PHP MySQL

sloojoe

New Member
Hello all,

What would be the best way to set up a PHP function that can check a field and if no data exists, it will not display. but if it does, it will show the data.

Example:

Fields are Thumb1, Thumb2, Thumb3.
Thumb1 = \pics\family\dadmom.jpg
Thumb2 = \pics\family\grandma.jpg
Thumb3 = (nothing)

PHP, on my site I have a table and want to display the Thumbs when user does mouseover. Problem is since some Thumb# fields are blank, it show the missing picture icon in IE. Sooo, I want to make something in PHP that will check the Thumb# record and if link to pic exists, it will show in the table. And if no link in field, PHP knows to skip over it.

Thanks,
Joe
 

zkiller

Super Moderator
Staff member
i don't know the proper php syntax, but in asp it would look something like...

Code:
If Not Thumb1 = "" or 0 then
   Response.Write(Thumb1)
End If
i realize the code won't be the same in php, but the line of thinking remains the same. for what it's worth, i hope that helps. :)
 

jmad

New Member
ur variable in php must start with the "$"
the "!" means if the variable is undefined. if it will be defined but jus have a null value then u need to make the if statment show that. then u write the code to check ur field not sure if u need help with that to or not if so respond (cause i may need more info) n i will take a stab at.

if (!$Thumb1)
{
this is were u write ur code to check ur field ;
}
else
{
code to display messge.
}
 

Cramesta

New Member
Use something like this.

PHP:
$t = array('\pics\family\dadmom.jpg','\pics\family\grandma.jpg','');
for ($i=1;$i<=3;$i++) {
     $thumb = $t[$i];
     if ($thumb != "") {
          echo '<img src="' . $thumb . '" />';
     }
}

You might need to modify some of it, but that's basically it. I shortcutted it using a for loop.
 
Last edited:

Imagn

New Member
The better way is run a file check...

$the_file = $FILEPATH . $FILENAME;

if (is_file($the_file)) {
echo "<img....";
}
 
Top