bluetoother Posted December 1, 2006 Share Posted December 1, 2006 guyssee this code plz:$result = mysql_query("SELECT * FROM sometable WHERE st_id=".$_REQUEST['id']);//how to check that there is a result from that query//before i add this code$row=mysql_fetch_array($result);//coz if $result does not contain any result from the query//an error will occur when i want to fetch any empty result in $row//then i will see this msg:/*Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in c:\inetpub\wwwroot\php\login.php on line 62wrong password*/how to make sure that query gave me a result ?before i start with the 2nd line Link to comment Share on other sites More sharing options...
jlhaslip Posted December 1, 2006 Share Posted December 1, 2006 if ($result) {// do this} else {// do something else} Might work. Link to comment Share on other sites More sharing options...
justsomeguy Posted December 1, 2006 Share Posted December 1, 2006 Or if(mysql_num_rows($result) > 0) Link to comment Share on other sites More sharing options...
Guest sham85131 Posted December 11, 2006 Share Posted December 11, 2006 if(mysql_num_rows($result)){ $row=mysql_fetch_array($result); // & other action you want }else { echo "no Record Retrived"; } Link to comment Share on other sites More sharing options...
paramasivan Posted December 11, 2006 Share Posted December 11, 2006 if($row=mysql_fetch_array($result)) { //Do what ever you want with php}Its my style. Link to comment Share on other sites More sharing options...
vanyok Posted December 11, 2006 Share Posted December 11, 2006 I'd do what justsomeguy posted. I find it the best way. I usually assign it to the variable. Here:$num=mysql_num_rows($result);if ($num>0){echo "My query returned $num rows";}else{echo "Your query didnt return any results";} Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now