PDA

View Full Version : PHP MySQL


sloojoe
04-09-2007, 10:18 PM
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
04-10-2007, 04:07 AM
i don't know the proper php syntax, but in asp it would look something like...

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
04-10-2007, 01:33 PM
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
06-08-2007, 04:41 AM
Use something like this.


$t = array('\pics\family\dadmom.jpg','\pics\family\gran dma.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.

sloojoe
06-08-2007, 01:08 PM
I will give it a try, thanks so much

Imagn
09-12-2007, 07:58 AM
The better way is run a file check...

$the_file = $FILEPATH . $FILENAME;

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