MySQL Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesMySQL Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old October 10th, 2000, 01:01 PM
Mike Paxman Mike Paxman is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Posts: 5 Mike Paxman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Can anyone help a new PHP user?

I'm constructing a search on a MySQL database.

I have a field for thumbnail pictures, (picthumb)
but some of the entries don't have thumbnail pictures.

What I want is that when searching, if the thumbnail field is empty,
then the resulting html page pulls up an image called coming.gif
(which shows that the thumbnail is not yet available)

I'm sure this is a simple if - else line, but I can't get it right.

any help would be appreciated!

Reply With Quote
  #2  
Old October 10th, 2000, 01:06 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
Do it in your query:

select foo,bar,if(isnull(thumb),'coming.jpg',thumb) as thumb from table....;

Assuming the field name is 'thumb' and that you are storing the actual filename.

Reply With Quote
  #3  
Old October 10th, 2000, 01:54 PM
Mike Paxman Mike Paxman is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Posts: 5 Mike Paxman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks Rod, but I don't seem to be able to get it working, have I got it in the right place?
Here's the script.
BTW the field is named (picthumb)

$result = mysql_query ("SELECT * FROM propdata1 WHERE location LIKE '$location%' AND rental LIKE '$rental%' AND purchase LIKE '$purchase%' ");

if(isnull(picthumb),'coming.gif',picthumb);
if ($row = mysql_fetch_array($result)) {

do {
printf ("<body bgcolor=#FFFFFF>");
printf ("<center><P><table border=0 cellpadding=5 cellspacing=0 width=600>n");
printf ("<tr><td colspan=2>n");
printf ("<strong>n");
printf (" %sn",$row["name"]);
printf (" - ");
printf (" %sn",$row["location"]);
printf ("</td></tr><tr><td>");
printf ("</strong><br>");
printf ("<img src=http://www.blah.com/img/");
printf ($row["picthumb"]);
printf ("</td></tr>n");
printf ("</table></P></center>n");
} while($row = mysql_fetch_array($result));
} else {print "<br><br><center><b> Sorry, no records were found! </b></center>";}


[This message has been edited by Mike Paxman (edited October 10, 2000).]

Reply With Quote
  #4  
Old October 10th, 2000, 02:34 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
You can do it in your query or outside. The code I gave you was for inside the query. To do it the way you are trying:

<code>$result = mysql_query ("SELECT * FROM propdata1 WHERE location LIKE '$location%' AND rental LIKE '$rental%' AND purchase LIKE '$purchase%' ");


if ($row = mysql_fetch_array($result)) {
if $row[picthumb]=="" $row[picthumb]='coming.jpg';

do {
printf ("<body bgcolor=#FFFFFF>");
printf ("<center><P><table border=0 cellpadding=5 cellspacing=0 width=600>n");
printf ("<tr><td colspan=2>n");
printf ("<strong>n");
printf (" %sn",$row["name"]);
printf (" - ");
printf (" %sn",$row["location"]);
printf ("</td></tr><tr><td>");
printf ("</strong><br>");
printf ("<img src=http://www.blah.com/img/");
printf ($row["picthumb"]);
printf ("</td></tr>n");
printf ("</table></P></center>n");
} while($row = mysql_fetch_array($result));
} else {print "<br><br><center><b> Sorry, no records were found! </b></center>";}</code>


Reply With Quote
  #5  
Old October 10th, 2000, 03:04 PM
Mike Paxman Mike Paxman is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Posts: 5 Mike Paxman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
The middle line here is throwing a parse error:

if ($row = mysql_fetch_array($result));{
if $row[picthumb]=="" $row[picthumb]='coming.gif';
do {

Reply With Quote
  #6  
Old October 10th, 2000, 05:06 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
Remove the ; from between the first if and the opening {

Reply With Quote
  #7  
Old October 10th, 2000, 05:29 PM
Mike Paxman Mike Paxman is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Posts: 5 Mike Paxman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
I've already done that, but I still get a

Parse error: parse error, expecting `'(''


Reply With Quote
  #8  
Old October 10th, 2000, 09:14 PM
rod k rod k is offline
Apprentice Deity
Dev Shed Loyal (3000 - 3499 posts)
 
Join Date: Jul 1999
Location: Niagara Falls (On the wrong side of the gorge)
Posts: 3,237 rod k User rank is Private First Class (20 - 50 Reputation Level)rod k User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 4 m 8 sec
Reputation Power: 13
Send a message via AIM to rod k
Doh! Forgot the parenthesis.

if ($row[picthumb]=="") $row[picthumb]='coming.jpg';

Reply With Quote
  #9  
Old October 11th, 2000, 04:32 AM
Sepodati's Avatar
Sepodati Sepodati is offline
Banned
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Dec 1999
Location: Afghanistan
Posts: 14,385 Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)Sepodati User rank is General 12nd Grade (Above 100000 Reputation Level)  Folding Points: 72870 Folding Title: Intermediate FolderFolding Points: 72870 Folding Title: Intermediate FolderFolding Points: 72870 Folding Title: Intermediate FolderFolding Points: 72870 Folding Title: Intermediate Folder
Time spent in forums: 2 Months 4 Weeks 20 h 36 m 16 sec
Reputation Power: 1784
Send a message via ICQ to Sepodati Send a message via Yahoo to Sepodati
You could also set a default in your table, so instead of storing NULL it will store 'coming.jpg' Then there won't be any additional logic you have to do

You can use the alter command to change it.

ALTER TABLE your_table CHANGE COLUMN your_column_name new_column_name VARCHAR(50) DEFAULT 'coming.jpg';

I'm assuming it's a varchar column, adapt to your needs. Also, have the two column names be the same if you don't want to change the name.

It's another approach...

---John Holmes...

------------------
*************************************************************
* The manual can probably answer 90% of your questions...
*
* PHP Manual. www.php.net/manual
* MySQL Manual: www.mysql.com/documentation/mysql/bychapter
*************************************************************

Reply With Quote
  #10  
Old October 12th, 2000, 02:18 AM
Mike Paxman Mike Paxman is offline
Junior Member
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2000
Posts: 5 Mike Paxman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Thanks for the help! Problem solved.

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesMySQL Help > PHP/My SQL search on empty fields


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT