dzedward Posted March 11, 2008 Share Posted March 11, 2008 How can I test if a query is successful? Lets say $id = '5'; $sql2 = "SELECT advURL FROM adv WHERE ID = '$id'"; $qry2 = mysql_query($sql2) or die("Query failed: " . mysql_error() . " Actual query: " . $sql); Lets say there is no value for advURL for that id. How can I know? Quote Link to comment Share on other sites More sharing options...
l0ve2hat3 Posted March 11, 2008 Share Posted March 11, 2008 do u want this? $id = '5'; $sql2 = "SELECT advURL FROM adv WHERE ID = '$id'"; $qry2 = mysql_query($sql2) or die("Query failed: " . mysql_error() . " Actual query: " . $sql); $row = mysql_fetch_array($qry2); if($row['advURL'] == ''){ echo "advURL is empty!!"; } Quote Link to comment Share on other sites More sharing options...
dzedward Posted March 11, 2008 Author Share Posted March 11, 2008 Sweet, thank you very much. I had all sorts of if statements, guess not testing on the right stuff. Thanks again. Quote Link to comment Share on other sites More sharing options...
dzedward Posted March 11, 2008 Author Share Posted March 11, 2008 its returning false every time for me... Quote Link to comment Share on other sites More sharing options...
l0ve2hat3 Posted March 11, 2008 Share Posted March 11, 2008 please post your code Quote Link to comment Share on other sites More sharing options...
dzedward Posted March 11, 2008 Author Share Posted March 11, 2008 $sql = "SELECT ID FROM adv WHERE req = '$incoming'"; $qry = mysql_query($sql) or die("Query failed: " . mysql_error() . " Actual query: " . $sql); while($rand = mysql_fetch_object($qry)) { $request = $rand->ID; $id = $request+1; $sql2 = "SELECT advURL FROM adv WHERE ID = '$id'"; $qry2 = mysql_query($sql2) or die("Query failed: " . mysql_error() . " Actual query: " . $sql2); if($qry2['advURL'] == ''){ finish(); } else { while($theId = mysql_fetch_object($qry2)) { $url = $theId->advURL; $newURL = $url; giveNew($newURL); } } } function giveNew($next){ echo $next; } function finish(){ echo "Finish Line"; } Quote Link to comment Share on other sites More sharing options...
dzedward Posted March 11, 2008 Author Share Posted March 11, 2008 without the if statement, it always returns the next URL, but when it gets to a point where there is no more after, its just blank, i need to know when that happens to I can call the function finish Quote Link to comment Share on other sites More sharing options...
l0ve2hat3 Posted March 11, 2008 Share Posted March 11, 2008 isnt $qry2['advURL'] undifined? i think you u need a fetch array on $qry2 $qry2 = mysql_query($sql2) or die("Query failed: " . mysql_error() . " Actual query: " . $sql2); if($qry2['advURL'] == ''){ finish(); } else { replace with this $qry2 = mysql_query($sql2) $row2 = mysql_fetch_array($qry2); or die("Query failed: " . mysql_error() . " Actual query: " . $sql2); if($row2['advURL'] == ''){ finish(); } else { Quote Link to comment Share on other sites More sharing options...
dzedward Posted March 11, 2008 Author Share Posted March 11, 2008 its not returning undefined, its just returning blank.. Changed that and now receive this Parse error: syntax error, unexpected T_VARIABLE in C:\wamp\www\domain\check.php on line 26 line 26 is $row2 = mysql_fetch_array($qry2); Quote Link to comment Share on other sites More sharing options...
l0ve2hat3 Posted March 11, 2008 Share Posted March 11, 2008 ooops forgot about the or die. use this $qry2 = mysql_query($sql2) or die("Query failed: " . mysql_error() . " Actual query: " . $sql2); $row2 = mysql_fetch_array($qry2); if($row2['advURL'] == ''){ finish(); } else { Quote Link to comment Share on other sites More sharing options...
Stooney Posted March 11, 2008 Share Posted March 11, 2008 I would suggest strlen. Small difference but it would be reliable technically. if(strlen($row2['advURL']) > 0){ Quote Link to comment Share on other sites More sharing options...
dzedward Posted March 11, 2008 Author Share Posted March 11, 2008 ooops forgot about the or die. use this $qry2 = mysql_query($sql2) or die("Query failed: " . mysql_error() . " Actual query: " . $sql2); $row2 = mysql_fetch_array($qry2); if($row2['advURL'] == ''){ finish(); } else { Using this I get no error, and I works if it is the last one in line. But all others fail to move on to next url, just get blank. Quote Link to comment Share on other sites More sharing options...
l0ve2hat3 Posted March 11, 2008 Share Posted March 11, 2008 hrmm not really following you. can u provide a link or no? Quote Link to comment Share on other sites More sharing options...
dzedward Posted March 11, 2008 Author Share Posted March 11, 2008 http://flashgods.org/check.php?inc=2068659131 is the second to last one in db.. should return http://www.beechstudios.com http://flashgods.org/check.php?inc=1090339229 is the last one in db... should return "Finish Line" Quote Link to comment Share on other sites More sharing options...
l0ve2hat3 Posted March 11, 2008 Share Posted March 11, 2008 this is the best i can do with out knowing exaclty what all these fields are $qry2 = mysql_query($sql2) or die("Query failed: " . mysql_error() . " Actual query: " . $sql2); $row2 = mysql_fetch_array($qry2); if($row2['advURL'] == ''){ finish(); } else { $url = $row2['advURL']; $newURL = $url; giveNew($newURL); } } } Quote Link to comment Share on other sites More sharing options...
dzedward Posted March 11, 2008 Author Share Posted March 11, 2008 Thats your best?? jp, cause it works now! I can't thank you enough!!!!!! 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.