If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > Newbie question: 'if function'?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-17-03, 06:11
hammerslane hammerslane is offline
Registered User
 
Join Date: Nov 2003
Location: UK
Posts: 1
Question 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
Reply With Quote
  #2 (permalink)  
Old 11-17-03, 06:36
khibinite khibinite is offline
Registered User
 
Join Date: Oct 2003
Posts: 63
Re: Newbie question: 'if function'?

Quote:
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.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On