php-db | 2002091

[PHP-DB] Re: joining tables From: David Robley (robleyd <email protected>)
Date: 09/15/02

In article <WorldClient-F200209141027.AA27090001 <email protected>>,
basza <email protected> says...
> I have the following code :
> <?
> $sql = "SELECT juke_artists.id, juke_artists.name, juke_tracks.id,
> juke_tracks.ar_id, juke_tracks.name FROM juke_tracks, juke_artists WHERE
> juke_tracks.ar_id = juke_artists.id and juke_tracks.name like '$lyrics%'
> ORDER BY juke_tracks.name";
>
> $lyricnames = mysql_query($sql) or die("Select Failed!");
> while ($lyricname = mysql_fetch_array($lyricnames)) {
> ?>
> <table width="100%" border="0">
> <tr>
> <td><? echo "<b><a href='lyricinfo.php?info=$lyricname
> [juke_tracks.id]'>$lyricname[juke_tracks.name]</a> </b> - By $lyricname
> [juke_artist.name]<br> "; ?></td>
> </tr>
> </table>
> <? } ?>
>
> Being new to php & mysql I have done some reading to get the above
> code, but for some reason it returns nothing. Could someone please
> point out where I might have gone wrong.
>
> Thanks in advance

'Returns nothing' is a little ambiguous - are there no matching records,
or there are matching records that are not being displayed?

To determine if you are finding matching records, you could add a call to
mysql_num_rows after your mysql_query. If the result is > 0 you have
matching records which are not being displayed; a possible reason is that
you are not quoting the fieldnames when trying to echo them:

$lyricname['juke_tracks.name']

You might also find the extract() function handy for assigning the field
values to variable names.

-- 
David Robley
Temporary Kiwi!

Quod subigo farinam

-- PHP Database Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php