+ Reply to Thread
Results 1 to 7 of 7

Thread: Someone please help me with sql

  1. #1
    krahny's Avatar
    krahny is offline x10Hosting Member krahny is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    25

    Question Someone please help me with sql

    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.

  2. #2
    diabolo's Avatar
    diabolo is offline Community Advocate diabolo is on a distinguished road
    Join Date
    Nov 2007
    Location
    Jersey Shore
    Posts
    1,683

    Re: Someone please help me with sql

    Quote Originally Posted by krahny View Post
    Or, maybe there's a way to check if a record exists with a certain value.
    Code:
    SELECT column_name(s) FROM table_name WHERE column_name operator value
    http://www.w3schools.com/sql/sql_where.asp
    Last edited by diabolo; 12-11-2009 at 03:59 PM.

  3. #3
    krahny's Avatar
    krahny is offline x10Hosting Member krahny is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    25

    Smile Re: Someone please help me with sql

    I know that code, but I need to know what it returns if it finds no match to the value.

    Thanks anyway.

  4. #4
    Gouri's Avatar
    Gouri is offline Community Paragon Gouri has a brilliant futureGouri has a brilliant futureGouri has a brilliant future
    Join Date
    Oct 2007
    Location
    India
    Posts
    4,502

    Re: Someone please help me with sql

    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 click to give Reputation (bottom left corner of this post)

    X10 Hosting | News and Announcements | Premium Hosting | VPS Hosting | Prime Membership

    Tech Community | Gouri

  5. #5
    descalzo's Avatar
    descalzo is offline Grim Squeaker descalzo has a brilliant futuredescalzo has a brilliant futuredescalzo has a brilliant future
    Join Date
    Jul 2009
    Location
    Ankh-Morpork
    Posts
    7,636

    Re: Someone please help me with sql

    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 ) == ) {
       
    # HANDLE  NO MATCH 
    } else {
       
    # HANDLE AT LEAST ONE MATCH

    Last edited by descalzo; 12-11-2009 at 05:57 PM.

  6. #6
    misson is offline x10 Spammer misson is a jewel in the rough
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,506

    Re: Someone please help me with sql

    Quote Originally Posted by krahny View Post
    I know that code, but I need to know what it returns if it finds no match to the value.
    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.

  7. #7
    krahny's Avatar
    krahny is offline x10Hosting Member krahny is an unknown quantity at this point
    Join Date
    Nov 2009
    Posts
    25

    Talking Thanks!

    Thanks for your help!

    That code descalzo gave me worked Great!!


+ Reply to Thread

Similar Threads

  1. PHP SQL Output
    By lemon-tree in forum Programming Help
    Replies: 1
    Last Post: 11-10-2009, 07:45 PM
  2. Microsoft SQL Server (a rant)
    By merrillmck in forum Programming Help
    Replies: 6
    Last Post: 07-08-2009, 10:43 AM
  3. sql database does not restore
    By softwork in forum Free Hosting
    Replies: 3
    Last Post: 05-20-2008, 06:47 AM
  4. Sql?
    By SLIForum in forum Scripts & 3rd Party Apps
    Replies: 4
    Last Post: 12-03-2007, 01:17 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers