| | |
What value is returned from an empty sql query?
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
Sorry been out of commision for a few months.
Got a newbe question.
What value is returned from an sql query that returns no rows?
Example:
Note:
Table Name - a
Table Field - b
Table Field Value - c
Question:
In the table there is no value of c and hence nothing is returned
What is the value of $b?
Thanks, Regards X
PS: I am assuming 0 or NULL but nothing seems to be working, thanks.
Got a newbe question.
What value is returned from an sql query that returns no rows?
Example:
php Syntax (Toggle Plain Text)
$a = "SELECT * FROM a WHERE b = c"; $b = my_sql_query($a);
Note:
Table Name - a
Table Field - b
Table Field Value - c
Question:
In the table there is no value of c and hence nothing is returned
What is the value of $b?
Thanks, Regards X
PS: I am assuming 0 or NULL but nothing seems to be working, thanks.
"You never stop learning." - OmniX
Then if you do
mysql_num_rows($b) it will return 0 and if you attempt to fetch an array from the query then mysql will throw an error. So the value of b is still the query execute command but it just won't execute and instead will throw an error. Try not to bump 10 year old threads as it can be really annoying.
http://syntax.cwarn23.net/
My favourite PC. - Oopy Doopy Do 2U2!
http://syntax.cwarn23.net/
Smilies: ^_* +_+ v_v -_- *~*` My favourite PC. - Oopy Doopy Do 2U2!
•
•
•
•
In the table there is no value of c and hence nothing is returned
What is the value of $b?
http://in.php.net/function.mysql-query
Last edited by nav33n; Feb 26th, 2009 at 4:52 am.
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
I dont think that is correct because when I make the variable that holds the result == 0 / NULL it dosent work.
How could you demonstrate that:
So anything something like this possible?
THanks, Regards X
How could you demonstrate that:
php Syntax (Toggle Plain Text)
$a = "SELECT * FROM a WHERE b = c"; $b = mysql_query($a); if($b == 0) { echo "No rows retrieved"; } else { echo "Rows retrieved"; }
So anything something like this possible?
THanks, Regards X
"You never stop learning." - OmniX
You have to get the number of rows.
Is that what you were asking?
php Syntax (Toggle Plain Text)
$a = "SELECT * FROM a WHERE b = c"; $b = mysql_query($a); $num_rows = mysql_num_rows($b); if($num_rows == 0) { echo "No rows retrieved"; } else { echo "Rows retrieved"; }
Lost time is never found again.
- Benjamin Franklin
- Benjamin Franklin
Your skipping a step 
Because you cant preform num_rows if $b returns no rows and throws an error.
Been trying to come up with a solution but it is annoying me - hopefully I figure it out soon

Because you cant preform num_rows if $b returns no rows and throws an error.
Been trying to come up with a solution but it is annoying me - hopefully I figure it out soon
Last edited by OmniX; Feb 26th, 2009 at 11:42 pm.
"You never stop learning." - OmniX
Actually, I modified your query to test the code in my db prior to posting and it outputted "No rows retrieved'". Also, when I run the code like so:
it returns 0 every time.
Have you got an error in your query?
php Syntax (Toggle Plain Text)
$sql = 'SELECT * FROM `absent faculty table` WHERE absentid = "blah"'; $result=mysql_query($sql,$conn); $num_rows = mysql_num_rows($result); echo $num_rows;
Have you got an error in your query?
Lost time is never found again.
- Benjamin Franklin
- Benjamin Franklin
You got it all wrong. $b doesn't return any rows. It just return result resource, which can be used in
* mysql_num_rows to know how many rows were returned.
* mysql_fetch_array/mysql_fetch_assoc/mysql_fetch_row/mysql_fetch_object to get the values of the rows .
* mysql_num_rows to know how many rows were returned.
* mysql_fetch_array/mysql_fetch_assoc/mysql_fetch_row/mysql_fetch_object to get the values of the rows .
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
nav33n is correct it is returning a result resouce (but I was meaning to say if that result resource returns no rows).
buddylee17 that returned 0 always? Intresting... My query works because when it does "retrieve a row" there is no error but when "dosent retrieve a row" there is an error
Anyways to check if the result_resource contains "no rows" so then dosent throw an error?
Hmmm... Actually I think I know what may be the problem I think because I am calling the mysql_num_rows from a function then directly?
Ill bbs, after I have tinkered. Thanks for the input.
Ya solved it in .5 seconds with your help, ha (the function was causing the errors).
Thanks Guys
using 'rows' instead 'mysql_num_rows' throws the error.
Anyone can help me fix my code? Thanks
buddylee17 that returned 0 always? Intresting... My query works because when it does "retrieve a row" there is no error but when "dosent retrieve a row" there is an error

Anyways to check if the result_resource contains "no rows" so then dosent throw an error?
Hmmm... Actually I think I know what may be the problem I think because I am calling the mysql_num_rows from a function then directly?
Ill bbs, after I have tinkered. Thanks for the input.

Ya solved it in .5 seconds with your help, ha (the function was causing the errors).
Thanks Guys
php Syntax (Toggle Plain Text)
function rows($a) { $b = mysql_num_rows($a) or die("Error: "); return $b; }
using 'rows' instead 'mysql_num_rows' throws the error.
Anyone can help me fix my code? Thanks
Last edited by OmniX; Feb 27th, 2009 at 12:00 am.
"You never stop learning." - OmniX
•
•
•
•
Hmmm... Actually I think I know what may be the problem I think because I am calling the mysql_num_rows from a function then directly?
Ignorance is definitely not bliss!
*PM asking for help will be ignored*
*PM asking for help will be ignored*
![]() |
Similar Threads
- sql query problem with MS Access and C# (C#)
- How to configure GD (PHP)
- php.ini confusion (PHP)
- mysql_num_rows(): supplied argument error (PHP)
- help in sql query (PHP)
- Not getting information from the database (PHP)
- Fatal error: require once (PHP)
- echo data (PHP)
- multiple search terms+fulltext search (MySQL)
Other Threads in the PHP Forum
- Previous Thread: split data?
- Next Thread: Populate text box from database according to the selection made in listbox
Views: 2224 | Replies: 26
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access address ajax apache api array autoincrement beginner binary broken cakephp checkbox class cms code cron curl database date dehasher directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link login loop mail menu method methods mlm mod_rewrite multiple mysql oop parse paypal pdf php problem query radio random recursion regex remote script search select server sessions sms soap source space speed sql structure support! syntax system table tutorial update updates upload url validation validator variable video web xml youtube






