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 > ifnull issue

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-08-11, 22:36
belask belask is offline
Registered User
 
Join Date: Sep 2010
Posts: 27
ifnull issue

I am using the following line in a PHP file:
SELECT * FROM `poems` WHERE `poemID`=1

now i want the following in addition with the above line:
if PoetName is NULL then PoetName is "Unknown"

but i am unable to solve this issue with ifnull() function. please somebody solve this problem.

I am using mysql
Reply With Quote
  #2 (permalink)  
Old 02-08-11, 23:40
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
Code:
SELECT something
     , anything
     , just_not_the_dreaded_evil_select_star 
     , COALESCE(PoetName,'Unknown') AS PoetName
  FROM poems 
 WHERE poemID = 1
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 02-09-11, 17:57
belask belask is offline
Registered User
 
Join Date: Sep 2010
Posts: 27
Ok i tried but it didn't work, although it didn't result in an error either. Poet field remained empty in output page.
Quote:
mysql_query(
"SELECT ghazalID, NameUrdu, TextUrdu, PoetUrdu, NameRoman, TextRoman, PoetRoman, COALESCE(PoetRoman,'Unknown') FROM ghazal_list WHERE ghazalID='" . $_GET[ghazalID] ."'");
Reply With Quote
  #4 (permalink)  
Old 02-09-11, 18:09
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
Quote:
Originally Posted by belask View Post
Ok Poet field remained empty in output page.
you forgot something

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 02-09-11, 18:45
belask belask is offline
Registered User
 
Join Date: Sep 2010
Posts: 27
That's for sure, but what? Do you have any idea?
As far as i know, i edited the correct php file.
There is no syntax error, because the page is showing correctly. (although there were some errors during the editing, but i fixed them)
I am sure that particular field is Null in the database table.
http://img211.imageshack.us/img211/7194/nullfields.png

Last edited by belask; 02-09-11 at 18:59.
Reply With Quote
  #6 (permalink)  
Old 02-09-11, 19:18
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
run your query outside of php, i.e. directly in mysql

you will see that it actually does work

then inspect your php code for the source of the error
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #7 (permalink)  
Old 02-09-11, 21:04
belask belask is offline
Registered User
 
Join Date: Sep 2010
Posts: 27
Quote:
Originally Posted by r937 View Post
run your query outside of php, i.e. directly in mysql

you will see that it actually does work

then inspect your php code for the source of the error
Thanks
Only after runing the query in mysql i could figure out the problem.
The problem was that I didn't blindly follow your syntax in the first place and didn't include AS PoetName.
Working perfectly now
And thanks for not telling me my mistake too early. Your strategy made me understand the meaning of AS PoetName.

Last edited by belask; 02-09-11 at 21:08.
Reply With Quote
  #8 (permalink)  
Old 02-09-11, 21:15
r937 r937 is online now
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,535
Quote:
Originally Posted by belask View Post
And thanks for not telling me my mistake too early. Your strategy made me understand the meaning of AS PoetName.
you're welcome

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
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