|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
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! |
|
#2
|
|||
|
|||
|
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. |
|
#3
|
|||
|
|||
|
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).] |
|
#4
|
|||
|
|||
|
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> |
|
#5
|
|||
|
|||
|
The middle line here is throwing a parse error:
if ($row = mysql_fetch_array($result));{ if $row[picthumb]=="" $row[picthumb]='coming.gif'; do { |
|
#6
|
|||
|
|||
|
Remove the ; from between the first if and the opening {
|
|
#7
|
|||
|
|||
|
I've already done that, but I still get a
Parse error: parse error, expecting `'('' |
|
#8
|
|||
|
|||
|
Doh! Forgot the parenthesis.
if ($row[picthumb]=="") $row[picthumb]='coming.jpg'; |
|
#9
|
||||
|
||||
|
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 ************************************************************* |
|
#10
|
|||
|
|||
|
Thanks for the help! Problem solved.
|
![]() |
| Viewing: Dev Shed Forums > Databases > MySQL Help > PHP/My SQL search on empty fields |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|