Results 1 to 2 of 2
  1. #1
    Join Date
    Nov 2003
    Location
    UK
    Posts
    1

    Question Unanswered: Newbie question: 'if function'?

    Hi, before I start, i'll just let you know that i'm not at all experienced in using SQL syntax, and I don't really know the nature of its functionality.
    I'm using PHP to display records for client contact details. The only thing is, that I don't have half of the customers details, so the 'address', 'phone' and 'email' fields are all blank for those record.
    Being a PHP person, I'd use a simple IF function, but i'm sure that doesn't work in sql..

    my code at the moment is
    $query=
    "SELECT *
    FROM contacttable
    WHERE client='$client' ";

    What I'd want to do then, is say, "if the name field, phone field, and email field are all blank, then display BLANK record" (BLANK record is a record which instead of having a client name, has 'NO RECORD FOUND'.
    What is the code for this?

    I apologise if I haven't explained too well, or my question is too stupid/easy etc...

    If there's an easier way to do what I'm attempting, could you let me know?
    All feedback is much appreciated.
    Regards

  2. #2
    Join Date
    Oct 2003
    Posts
    63

    Re: Newbie question: 'if function'?

    Originally posted by hammerslane
    Hi, before I start, i'll just let you know that i'm not at all experienced in using SQL syntax, and I don't really know the nature of its functionality.
    I'm using PHP to display records for client contact details. The only thing is, that I don't have half of the customers details, so the 'address', 'phone' and 'email' fields are all blank for those record.
    Being a PHP person, I'd use a simple IF function, but i'm sure that doesn't work in sql..

    my code at the moment is
    $query=
    "SELECT *
    FROM contacttable
    WHERE client='$client' ";

    What I'd want to do then, is say, "if the name field, phone field, and email field are all blank, then display BLANK record" (BLANK record is a record which instead of having a client name, has 'NO RECORD FOUND'.
    What is the code for this?

    I apologise if I haven't explained too well, or my question is too stupid/easy etc...

    If there's an easier way to do what I'm attempting, could you let me know?
    All feedback is much appreciated.
    Regards
    Hi!
    Could you show the full structure of your table in "CREATE TABLE format"?

    You could use such approach.
    Code:
    $query= 
    "SELECT *
    FROM contacttable
    WHERE client='$client' ";
    
    $qr_res = mysql_query($query);
    while $row = mysql_fetch_assoc($qr_res) {
       $data_len = strlen(trim($row["address"])) + strlen(trim($row["phone"])) + strlen(trim($row["email"]));
    };
    So, the variable $data_len will contain the common length of 3 fileds. If it will be equal 0, you can output 'NO RECORD FOUND'.

    I simply described an idea, I hope it helps.

Posting Permissions

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