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? Link to comment https://forums.phpfreaks.com/topic/95550-test-if-query-is-successful/ 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!!"; } Link to comment https://forums.phpfreaks.com/topic/95550-test-if-query-is-successful/#findComment-489142 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. Link to comment https://forums.phpfreaks.com/topic/95550-test-if-query-is-successful/#findComment-489150 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... Link to comment https://forums.phpfreaks.com/topic/95550-test-if-query-is-successful/#findComment-489166 Share on other sites More sharing options...
l0ve2hat3 Posted March 11, 2008 Share Posted March 11, 2008 please post your code Link to comment https://forums.phpfreaks.com/topic/95550-test-if-query-is-successful/#findComment-489190 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"; } Link to comment https://forums.phpfreaks.com/topic/95550-test-if-query-is-successful/#findComment-489193 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 Link to comment https://forums.phpfreaks.com/topic/95550-test-if-query-is-successful/#findComment-489194 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 { Link to comment https://forums.phpfreaks.com/topic/95550-test-if-query-is-successful/#findComment-489196 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); Link to comment https://forums.phpfreaks.com/topic/95550-test-if-query-is-successful/#findComment-489197 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 { Link to comment https://forums.phpfreaks.com/topic/95550-test-if-query-is-successful/#findComment-489198 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){ Link to comment https://forums.phpfreaks.com/topic/95550-test-if-query-is-successful/#findComment-489201 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. Link to comment https://forums.phpfreaks.com/topic/95550-test-if-query-is-successful/#findComment-489207 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? Link to comment https://forums.phpfreaks.com/topic/95550-test-if-query-is-successful/#findComment-489212 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" Link to comment https://forums.phpfreaks.com/topic/95550-test-if-query-is-successful/#findComment-489213 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); } } } Link to comment https://forums.phpfreaks.com/topic/95550-test-if-query-is-successful/#findComment-489219 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!!!!!! Link to comment https://forums.phpfreaks.com/topic/95550-test-if-query-is-successful/#findComment-489222 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.