Dysan Posted November 23, 2007 Share Posted November 23, 2007 Why do I get the following error message, when output items from the database? Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\Documents and Settings\User\Desktop\Xampp\htdocs\1.php on line 17 foreach($array as $item) { $result = mysql_query("SELECT * FROM names WHERE id = '$id'"); while($row = mysql_fetch_array($result)) //This is line 17 { $row['Firstname']." - ". $row['Surname'] ." ".$row['Sex']; } } Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted November 23, 2007 Share Posted November 23, 2007 This means there is either something wrong with your query, or there are no results. Try this: <?php foreach($array as $item){ $result = mysql_query("SELECT * FROM names WHERE id = '$id'") or die(mysql_error()); $num = mysql_num_rows($result); if($num > 0){ while($row = mysql_fetch_array($result)){ $row['Firstname']." - ". $row['Surname'] ." ".$row['Sex']; } } } ?> Quote Link to comment Share on other sites More sharing options...
helraizer Posted November 23, 2007 Share Posted November 23, 2007 Ginger's code might work but normally for the mysql_query you should probably do it like: <?php $sql = "SELECT * FROM `names` WHERE `id`='$id'" $result = mysql_query($sql) or die(mysql_error()); ?> I think you'll find that that should work (haven't tried it but it should) Quote Link to comment Share on other sites More sharing options...
revraz Posted November 23, 2007 Share Posted November 23, 2007 Tick marks shouldn't make any difference in this case. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.