squiblo Posted February 3, 2010 Share Posted February 3, 2010 How can I make the following two queries into just 1 query so I dont have to divide by 2 at the end. this is what the db table looks like.... || user_id || page_zebra_id || friend || foe || 2 53 1 0 53 2 1 0 $friend_check = mysql_query("SELECT * FROM page_zebra WHERE user_id='$user_id' AND friend=1"); $first_friends = mysql_numrows($friend_check); $friend_check = mysql_query("SELECT * FROM page_zebra WHERE page_zebra_id='$user_id' AND friend=1"); $second_friends = mysql_numrows($friend_check); $total_friends = ($first_friends + $second_friends) / 2; Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 3, 2010 Share Posted February 3, 2010 SELECT (COUNT(*) / 2) AS totalFriends FROM page_zebra WHERE (page_zebra_id='$user_id' OR user_id='$user_id') AND friend=1 Quote Link to comment Share on other sites More sharing options...
squiblo Posted February 3, 2010 Author Share Posted February 3, 2010 i have put $friend_check = mysql_query("SELECT (COUNT(*) / 2) AS totalFriends FROM page_zebra WHERE (page_zebra_id='$user_id' OR user_id='$user_id') AND friend=1"); $total_friends = mysql_numrows($friend_check); but get this error Parse error: syntax error, unexpected ')' Quote Link to comment Share on other sites More sharing options...
Mchl Posted February 3, 2010 Share Posted February 3, 2010 In which line? Syntax of these two is correct. And besides, this query will return only one row, but with value you need already calculated. $friend_check = mysql_query("SELECT (COUNT(*) / 2) AS totalFriends FROM page_zebra WHERE (page_zebra_id='$user_id' OR user_id='$user_id') AND friend=1"); $row = mysql_fetch_assoc($friend_check); $total_friends = $row['totalFriends']; Quote Link to comment Share on other sites More sharing options...
squiblo Posted February 3, 2010 Author Share Posted February 3, 2010 that query is working fine but is displaying like 1.0000 how can i display the value as an integer? Quote Link to comment Share on other sites More sharing options...
squiblo Posted February 3, 2010 Author Share Posted February 3, 2010 that query is working fine but is displaying like 1.0000 how can i display the value as an integer? $totalfriends = intval($totalfriends); 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.