I'm trying to get to grips with this create view thingy, but can't see it.

This creats my view

mysql_query("CREATE VIEW list AS 
   SELECT AlbumId,Title FROM album,
   LEFT JOIN artist ON album.artistId = artist.ArtistId ORDER BY album.Title")or die ("no dice pal   ".mysql_error());

that works, and creats it fine. But when I run the query

  <table class='tables' align='center' border='1'>
  <tr>
  <th>ID</th><th>Album</th><th>Artist</th>
  </tr>
  <?php
  mysql_set_charset('utf8');
  $list=mysql_query("SELECT * FROM list");
   while($row=mysql_fetch_array($list)){
   $alb=$row['AlbumId'];
   $title=$row['Title'];
   $art=$row['Name'];

  echo"<tr>
      <td>".$alb."</td><td>".$title."</td><td>".$art."</td>
      </tr>";
   }

?>
  </table>

the last column in the table 'Artist' is blank, what am I missing here guys, aside from a few million brain cells?

Recommended Answers

All 3 Replies

There is no error except that you are not getting Name.So $row['Name'] is empty.

Change the above to this(i am assuming the field "artist name" as "Name" in Database).

mysql_query("CREATE VIEW list AS 
SELECT AlbumId,Title,Name FROM album, 
LEFT JOIN artist ON album.artistId = artist.ArtistId ORDER BY album.Title")or die ("no dice pal ".mysql_error());

ah, you beat me to it...

Thanks guys, I know this is something I should have learnt long since, but I've been lazy.....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.