villain222 Posted May 24, 2011 Share Posted May 24, 2011 Ok here's my problem, I have a second query happening inside another While loop and I want it to grab info for the corresponding entry. I can get it to work fine if there is and entry available. So what do i do when the matching entry is not available. I don't care that value is missing. That's expected. What I'm looking for is how handle the lack of the entry to specify the variables I want. $final = mysql_query("SELECT tickets.item, tickets.amount, tickets.paypal FROM tickets WHERE tickets.item = $id"); //SECOND QUERY ON INCLUDE FILE while ($row2=mysql_fetch_array($final)) { //IF $id VALUE IS NOT MATCHED I WANT $amount AND $paypalID TO = 0 $amount = $row2['amount']; $paypalID = $row2['paypal'];} if ($amount>0 && $paypalID>0){ echo $amount; $over= '<font size=4 color="red"><br>sold!</font>'; echo $over; $stop= "86";} elseif ($hrdif>$hours) { $payprice=$row['loprice']; echo $payprice; $over= '<font size=4 color="red"><br>sale over</font>'; echo $over; $stop= "86"; //$userCut=$payprice*0.98; -also on paypalIPN.php. HERE FOR TESTING. //echo $userCut; } else { //echo "current price: "; $payprice=round($row['price']-$hourly*$hrdif, 2); echo $payprice; $over= ""; $stop= "0"; } Link to comment https://forums.phpfreaks.com/topic/237289-if-query-gets-no-result-do-what/ Share on other sites More sharing options...
biggieuk Posted May 24, 2011 Share Posted May 24, 2011 Hmm maybe this is what your looking for: IFNULL( tickets.amount, 0) Link to comment https://forums.phpfreaks.com/topic/237289-if-query-gets-no-result-do-what/#findComment-1219488 Share on other sites More sharing options...
mikosiko Posted May 24, 2011 Share Posted May 24, 2011 after this line: $final = mysql_query("SELECT tickets.item, tickets.amount, tickets.paypal FROM tickets WHERE tickets.item = $id"); and assuming that your SQL is correct, check for the number of affected rows with mysql_num_rows() and proceed accordingly Link to comment https://forums.phpfreaks.com/topic/237289-if-query-gets-no-result-do-what/#findComment-1219551 Share on other sites More sharing options...
villain222 Posted May 28, 2011 Author Share Posted May 28, 2011 ifnull?? thats a new one. where about does it go? I'll check it out on php.net, but if you can give me and example that would be great. Thanks. Link to comment https://forums.phpfreaks.com/topic/237289-if-query-gets-no-result-do-what/#findComment-1221480 Share on other sites More sharing options...
villain222 Posted May 29, 2011 Author Share Posted May 29, 2011 ok, well i gave up on the hell of dealing with nested if elses and while statements and went back to learn how to join 3 tables and that made things alot easier. sort of solved. by re engineering. Link to comment https://forums.phpfreaks.com/topic/237289-if-query-gets-no-result-do-what/#findComment-1221780 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.