aerolite Posted April 27, 2012 Share Posted April 27, 2012 // Check for this userID if exsist in cp_credits $sql = "SELECT * FROM `cp_credits` WHERE account_id = $userid"; // Execute Query $r = mysqli_query($dbc, $sql); // If there are result in $r if($r){ // Print a message indicating success or not: while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)){ $user_balance = $row['balance']; $user_last_donation_date = $row['last_donation_date']; } } else{ $user_balance = "nothing"; $user_last_donation_date = "nothing"; } but either of my else statement does not work. Whats wrong with this? Link to comment https://forums.phpfreaks.com/topic/261696-php-with-mysql-queries-help/ Share on other sites More sharing options...
trq Posted April 27, 2012 Share Posted April 27, 2012 Pardon? Link to comment https://forums.phpfreaks.com/topic/261696-php-with-mysql-queries-help/#findComment-1341066 Share on other sites More sharing options...
Zephni Posted April 27, 2012 Share Posted April 27, 2012 A query returns true even if there are no results. It will only return false if the query fails. You will want to use <?php $num_rows = mysqli_num_rows($r); ?> and test whether there are any results like that Link to comment https://forums.phpfreaks.com/topic/261696-php-with-mysql-queries-help/#findComment-1341113 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.