Carthick Posted November 13, 2012 Share Posted November 13, 2012 help me sir... Am a newbie in these programming.... i gotto submit this project by today evening ma whole diwali is being messed up by these... Am attachin the file with it.... plz help me... i donnow how to let it work.... plz help me sir... i'll b so thankful... as itz d last date for submission n ma practical exam login.php Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 13, 2012 Share Posted November 13, 2012 You are storing the result of the query in the variable $result. However, the query is failing, so $result is set to the Boolean FALSE value. On line 181 you then try to "use" the result of the query by extracting a row from the result while($row = mysql_fetch_assoc($result)) As stated above, since the query failed $result does not contain a resource (pointer) to a query result. You should always check your queries to see if they fail. If they do you should output the MySQL error and the actual query to the page for debugging purposes. In this case I see a few problems. 1. I'm not certain, but I don't think != is valid in MySQL. You should use <> 2. This is not valid if($result > 0){ I'm pretty sure you want to check if the result contained more than 0 ROWS. As stated above $result will contain a resource to the result set - it is not the count of the records returned. Instead you would do this: if(mysql_num_rows($result) > 0){ Use the following $sql = "SELECT * FROM members WHERE confirmation = '1' AND type <> 'Admin' AND image <> 'uploads/propic.jpg' ORDER BY RAND() LIMIT 9"; $result = mysql_query($sql); if(!$result) { echo "The query failed. Query: {$sql}<br>Error: " . mysql_error(); } elseif(!mysql_num_rows($result)) { echo "There were no records returned."; } else { //Display the results $first = $row['image']; Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted November 13, 2012 Share Posted November 13, 2012 Two quick notes: 1. The != operator is valid in MySQL, although <> is preferred. 2. Depending on the size of your MySQL table, using ORDER BY RAND() can be very slow. If your table is not large (more than 500+ rows about), then you really do not have to worry. However, using ORDER BY RAND() is a bad habit to get into. 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.