query problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
cgildenhuys
Forum Newbie
Posts: 8
Joined: Fri Feb 21, 2003 3:10 am

query problem

Post by cgildenhuys »

I can't figure out why this does not work.
Very simple, if an id gets passed in the url, the individual artist's info is shown otherwise a list of all artisits. The list works fine. Once I click on the artist, I can see(and I tested) that the id is passed but on reload I get an "Warning: Supplied argument is not a valid MySQL result resource in /Users/adam/Sites/globalparty3/lib/labelvirtuel/artists/index.php on line 6
" error.
The code:

<p>
<?php
// show individuel artist info if id is available, otherwise a list of all artists
if ($id) {
$result = mysql_query("SELECT * FROM artistLV WHERE artist_id = '$id'");
$myrow = mysql_fetch_array($result);
echo $myrow['name'];
echo $myrow['descripEng'];
} else {
?>
<table width="600" border="0" cellspacing="0" cellpadding="0">
<?php
$result2 = mysql_query("SELECT * FROM artistLV LEFT JOIN images ON artistLV.imageId = images.id_images ORDER BY artistLV.artist_id ASC");
while($myrow = mysql_fetch_array($result2)) {
?>
<tr>
<!-- image -->
<?php
if ($myrow['imageId']=='0') {
echo "<td>&nbsp;</td>";
} else {
?>
<td valign="top" width="85"><img src="../images/<?php echo $myrow['thumbUrl']; ?>" width="<?php echo $myrow['thumbWidth']; ?>" height="<?php echo $myrow['thumbHeight']; ?>" alt="<?php echo $myrow['alt']; ?>" /></td>
<?php
}
?>
<td width="10">&nbsp;</td>
<td width="500" valign="top"><a href="artists/index.php?id=<?php echo $myrow['artist_id']; ?>"><?php echo $myrow['name']; ?></a> <?php echo $myrow['country']; ?></td>
</tr>
<tr><td colspan="3">&nbsp;</td></tr>
<?php
}
?>
</table>
<?php
}
?>
</p>

It must be something obvious but I can't find it.

thanks.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

To debug, instead of this:

Code: Select all

$result = mysql_query("SELECT * FROM artistLV WHERE artist_id = '$id'");
try:

Code: Select all

$sql = "SELECT * FROM artistLV WHERE artist_id = '$id'";
$result = mysql_query($sql) or die(mysql_error().'<p>'.$sql.'</p>');
Mac
cgildenhuys
Forum Newbie
Posts: 8
Joined: Fri Feb 21, 2003 3:10 am

Post by cgildenhuys »

thanks, that made things more clear. I'm using a intricate frames setup and somehow when the page gets reloaded it looses the includes in its parent page, which was the connect script.
Post Reply