SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Guru augathra's Avatar
    Join Date
    Jul 2004
    Location
    united states
    Posts
    826
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    SELECT & check if result is there

    Hi, I'm guessing this is a very simple piece of code, but I'm not sure of it. I am wondering how I can do a query, and if it returns empty, create a variable saying YES or NO or EMPTY, etc..

    PHP Code:
    // connect //
    $sql 'select * FROM table1 WHERE....';
    $query msyql_query($sql);
    while(
    $row mysql_fetch_array($query)) {
    if(empty(
    $row)) {
    $var = EMPTY;
    }

    of course that didnt work for me.

  2. #2
    SitePoint Zealot ssttoo's Avatar
    Join Date
    Jan 2004
    Location
    LA, California
    Posts
    123
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There's this function mysql_num_rows() that will give you an idea if there are results:
    PHP Code:
    // connect //
    $sql 'SELECT * FROM table1 WHERE....';
    $query msyql_query($sql);
    $number_of_rows mysql_num_rows($query);
    if (
    $number_of_rows == 0) {
        
    $var "Damn! No results :( ";


  3. #3
    SitePoint Guru augathra's Avatar
    Join Date
    Jul 2004
    Location
    united states
    Posts
    826
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    /sigh, Thanks...heh


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •