I was wondering if anyone knows what the sql select command will return in a query if it finds no match. Or, maybe there's a way to check if a record exists with a certain value.
Somone please help.
I was wondering if anyone knows what the sql select command will return in a query if it finds no match. Or, maybe there's a way to check if a record exists with a certain value.
Somone please help.
http://www.w3schools.com/sql/sql_where.aspCode:SELECT column_name(s) FROM table_name WHERE column_name operator value
Last edited by diabolo; 12-11-2009 at 03:59 PM.
I know that code, but I need to know what it returns if it finds no match to the value.
Thanks anyway.
Handling in PHP
For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.
Only SQL
Empty set (0.00 sec)
Last edited by Gouri; 12-11-2009 at 05:44 PM.
If you feel my post is useful then clickto give Reputation (bottom left corner of this post)
X10 Hosting | News and Announcements | Premium Hosting | VPS Hosting | Prime Membership
Tech Community | Gouri
PHP:
PHP Code:
# $dbh is the connection to your database
$sql = "SELECT name, city FROM customer_table WHERE state='CA' " ;
$result = mysqli_query( $dbh , $sql ) ;
if( $result === false ){
# HANDLE ERROR ;
} elseif ( mysqli_num_rows( $result ) == 0 ) {
# HANDLE NO MATCH
} else {
# HANDLE AT LEAST ONE MATCH
}
Last edited by descalzo; 12-11-2009 at 05:57 PM.
Notionally, the empty set. Relational DBMSs, such as MySQL, are modeled after relationships, which are relations ([2]) where you don't care about domain order. In RDB parlance, "table" is synonymous with "relationship". An SQL statement creates a new relationship by joining, filtering and sorting other relationships. If a join or a filter results in no tuples (rows), the result is an empty set.
In PHP, the various MySQL drivers invariably return a result with no rows. If you want to test for an empty result, use (e.g.) mysqli_num_rows or PDOStatement::rowCount.
Be sure to read all pages linked in this post; they have further information that should prove useful. When asking for help, make sure you follow Eric Raymond's and Jon Skeet's guidelines for prompt, accurate responses. Please answer any questions I ask; they're not rhetorical (probably). Any posted code is intended as illustrative example, rather than a solution to your problem to be copied without alteration. Study it to learn how to write your own solution.Misson, not Mission.
Thanks for your help!
That code descalzo gave me worked Great!!
![]()