vmicchia Posted June 9, 2010 Share Posted June 9, 2010 Hi I am working on a pretty simple script at the moment. I keep getting this error: Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/stay/public_html/index.php on line 26. Here is my code !DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title> </head> <body> <div id="outerContainer" style="width:1024px; border:thin; border-color:#000000"> <div id="imageContainer" style="width:500px;"> </div> <div id="formContainer"> <form name="selectCushion" id="selectCushion" enctype="multipart/form-data" action="fabricSelect.php"> <?php include("includes/openDbConn.php"); $sql="SELECT cushionName, cushionDescription, cushionPrice, cushionImagePath FROM cushions"; //echo $sql; $result = mysql_query($sql); //echo $result; //echo "This works"; if($result = 0){ $num_results = 0; //echo "Past If"; }else{ //echo "Past else"; //echo $num_results; $num_results = mysql_num_rows($result); } for($i = 0; $i < $num_results; $i++){ $row = mysql_fetch_array($result); echo "<input type='image' src='".trim($row["cushionImagePath"])."' height='' width='' alt='".trim($row["cushionDescription"])."'/>"; //echo "<label>" trim($row["cushionName"]) "</label>"; } ?> </form> </div> </div> </body> </html> I have run the query in mySQL and it returns the correct data so that doesn't seem to be the problem. Thanks for any help. Quote Link to comment Share on other sites More sharing options...
micah1701 Posted June 9, 2010 Share Posted June 9, 2010 on line 17 (if I counted backwards correctly)... if($result = 0){ needs to be: if($result == 0){ //with 2 equal signs Instead of checking if $result is equal to zero, you're re-assigning the value of $result to 0. Quote Link to comment Share on other sites More sharing options...
syed Posted June 9, 2010 Share Posted June 9, 2010 use this instead while ( $row = mysql_fetch_array($result) { print $row['field']; } Quote Link to comment Share on other sites More sharing options...
vmicchia Posted June 9, 2010 Author Share Posted June 9, 2010 on line 17 (if I counted backwards correctly)... if($result = 0){ needs to be: if($result == 0){ //with 2 equal signs Instead of checking if $result is equal to zero, you're re-assigning the value of $result to 0. Thanks so much for catching that. I copied some of the code from an old project so I guess I just expected it to be working and right. Much appreciated. use this instead while ( $row = mysql_fetch_array($result) { print $row['field']; } I will try that I appreciate the advice very much. It works great now. Much appreciated. 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.