advancedfuture Posted January 9, 2008 Share Posted January 9, 2008 I am trying to print a list of output from mySQL using a nested while/for loop. But it keeps generating an error. Suggestions? Thanks! "mysql_fetch_array(): supplied argument is not a valid MySQL result resource" <?php include 'session.php'; include 'dbconnect.php'; $query = "SELECT * FROM mail WHERE rcpt = '$username'"; $results = mysql_query($query); $num = mysql_num_rows($results); while($row=mysql_fetch_array($num)) { for($i = 0; $i < $num; $i++) { echo $row[$i]; echo "<br />"; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/85250-mysql_fetch_array-supplied-argument-is-not-a-valid/ Share on other sites More sharing options...
rhodesa Posted January 9, 2008 Share Posted January 9, 2008 replace while loop with: while($row=mysql_fetch_array($results)) Quote Link to comment https://forums.phpfreaks.com/topic/85250-mysql_fetch_array-supplied-argument-is-not-a-valid/#findComment-434899 Share on other sites More sharing options...
GingerRobot Posted January 9, 2008 Share Posted January 9, 2008 This still isn't going to do what you're after. Your code doesn't make sense. mysql_num_rows() returns the number of records that you've selected from the database. It doesn't make sense to use this as a constraint within a loop that's looping through a record at a time. If you tell us what you're trying to achieve, we might be able to tell you the best way to go about it. Quote Link to comment https://forums.phpfreaks.com/topic/85250-mysql_fetch_array-supplied-argument-is-not-a-valid/#findComment-434905 Share on other sites More sharing options...
revraz Posted January 9, 2008 Share Posted January 9, 2008 while($row=mysql_fetch_array($results)) { echo $row[0]; echo "<br />"; } assuming you just want one field Quote Link to comment https://forums.phpfreaks.com/topic/85250-mysql_fetch_array-supplied-argument-is-not-a-valid/#findComment-434923 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.