dsaba Posted March 11, 2007 Share Posted March 11, 2007 If i have a table that is completely empty in a mysql database meaning NO ROWS and I run a query that selects * on that empty table will it return false, NULL, empty, or 0 because i have a particular situation where this is happening and I ran if statements on all of those and nothing checks out! Link to comment https://forums.phpfreaks.com/topic/42188-solved-if-table-is-empty-in-a-mysql-db/ Share on other sites More sharing options...
dsaba Posted March 11, 2007 Author Share Posted March 11, 2007 i know this sounds like a stupid question right? I know it is I wouldn't ask it because I THOUGHT i knew the answer, but apparantly my script is behaving differently here is the code: $pageip = $_SERVER['REMOTE_ADDR']; $pagedate = date("Y-m-d"); $pagedatetime = date("Y-m-d g:i:s"); include 'connectmysql.php'; $pageviewquery = mysql_query("SELECT * FROM pageviews WHERE pageip='$pageip' AND pageid='25' ORDER BY pagedatetime DESC LIMIT 0, 1"); $pageviewqueryrow = mysql_fetch_array($pageviewquery); if ($pageviewquery == FALSE) { echo "query is false"; } else { echo "query is not false"; } if ($pageviewquery == NULL) { echo "query is null"; } else { echo "query is not NULL"; } if ($pageviewquery == 0) { echo "query is 0"; } else { echo "query is not 0"; } it returns query is not false, query is not 0, and query is not null when i echo the query it returns Resource id #3 when I echo mysql_error(); it returns nothing when I echo mysql_errno(); it returns 0 so how can I not have an error? and then also have an error number? I KNOW THIS TABLE IS EMPTY, so whats going on???? thanks for your help Link to comment https://forums.phpfreaks.com/topic/42188-solved-if-table-is-empty-in-a-mysql-db/#findComment-204640 Share on other sites More sharing options...
dsaba Posted March 11, 2007 Author Share Posted March 11, 2007 if u dont want to read that other crap, let me ask the simplest way! queston: if you query a table that is empty in your mysql db what should it return? a simple question deserves a simple answer! thanks! Link to comment https://forums.phpfreaks.com/topic/42188-solved-if-table-is-empty-in-a-mysql-db/#findComment-204645 Share on other sites More sharing options...
jeremywesselman Posted March 11, 2007 Share Posted March 11, 2007 After running some tests of my own, I have determined that it returns false if there are no rows in the database. Link to comment https://forums.phpfreaks.com/topic/42188-solved-if-table-is-empty-in-a-mysql-db/#findComment-204648 Share on other sites More sharing options...
dsaba Posted March 11, 2007 Author Share Posted March 11, 2007 well I did this and i checked connectmysql.php and it does exist, and I can query succesfully from other tables but IT DOES NOT RETURN FALSE WHEN I QUERY AN EMPTY TABLE!!!! WHY!!!!!!???????????? what the hell is going on? i'm going nuts Link to comment https://forums.phpfreaks.com/topic/42188-solved-if-table-is-empty-in-a-mysql-db/#findComment-204650 Share on other sites More sharing options...
dsaba Posted March 11, 2007 Author Share Posted March 11, 2007 here is a pic from my phpmyadmin here is the exact code i'm using: $pageip = $_SERVER['REMOTE_ADDR']; $pagedate = date("Y-m-d"); $pagedatetime = date("Y-m-d g:i:s"); include 'connectmysql.php'; $pageviewquery = mysql_query("SELECT * FROM pageviews WHERE pageuserid='45'"); if ($pageviewquery == FALSE) { echo "query is false"; } else { echo "query is not false"; } mysql_close(); this returns QUERY IS NOT FALSE as you can see in my image there is not row with pageuserid= 45 what is going on? Link to comment https://forums.phpfreaks.com/topic/42188-solved-if-table-is-empty-in-a-mysql-db/#findComment-204656 Share on other sites More sharing options...
jeremywesselman Posted March 11, 2007 Share Posted March 11, 2007 $pageviewquery = mysql_query("SELECT * FROM pageviews WHERE pageuserid='45'"); $result = mysql_fetch_array($pageviewquery); echo $result; if ($result == FALSE) { echo "query is false"; } else { echo "query is not false"; } You need to use mysql_fetch_array() to get the results. Otherwise, it is returning a Resource Id. Jeremy Link to comment https://forums.phpfreaks.com/topic/42188-solved-if-table-is-empty-in-a-mysql-db/#findComment-204661 Share on other sites More sharing options...
dsaba Posted March 11, 2007 Author Share Posted March 11, 2007 THANK U!!!!! :) GOOD WORK THE REPLY I WAS LOOKING FOR!!! Link to comment https://forums.phpfreaks.com/topic/42188-solved-if-table-is-empty-in-a-mysql-db/#findComment-204662 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.