suess0r Posted December 13, 2006 Share Posted December 13, 2006 hey guys, i'm setting up a site and some of my records have pictures and some don't, but i want the ones that don't to have some sort of mmpf to them as well, other than the generic [x] image not found space. is there any way i can default to a certain image if the ($i.jpg) doesn't exist??? thanks :D Quote Link to comment https://forums.phpfreaks.com/topic/30527-displaying-a-default-image-x/ Share on other sites More sharing options...
timmah1 Posted December 13, 2006 Share Posted December 13, 2006 I think this will work[code]$check = "select file from $table"; $qry = mysql_query($check)or die ("Could not match data because ".mysql_error());$num_rows = mysql_num_rows($qry); if ($num_rows != 0) { exit; }else {echo "$i.jpg";}[/code] Quote Link to comment https://forums.phpfreaks.com/topic/30527-displaying-a-default-image-x/#findComment-140521 Share on other sites More sharing options...
zq29 Posted December 13, 2006 Share Posted December 13, 2006 Alternative:[code]<?php$file = "path/to/your/images/image.jpg";echo (file_exists($file)) ? "<img src='$file' alt='My Image' />" : "<img src='noimg.gif' alt='No Image' />";?>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/30527-displaying-a-default-image-x/#findComment-140528 Share on other sites More sharing options...
suess0r Posted December 13, 2006 Author Share Posted December 13, 2006 thanks semi, i'm getting this error though...Parse error: parse error, expecting `','' or `';'' in /Users/jif/Clb411/pg3.php on line 9[quote] $file = "/images/clubs/logos/'.$name.'.jpg"; echo (file_exists($file)) ? "<img src='$file' alt='My Image' />" : "<img src='/images/noimg.jpg' alt='No Image' />";[/quote]any thoughts? Quote Link to comment https://forums.phpfreaks.com/topic/30527-displaying-a-default-image-x/#findComment-140541 Share on other sites More sharing options...
TEENFRONT Posted December 13, 2006 Share Posted December 13, 2006 paste us all your code, or at least line 9. Quote Link to comment https://forums.phpfreaks.com/topic/30527-displaying-a-default-image-x/#findComment-140545 Share on other sites More sharing options...
suess0r Posted December 13, 2006 Author Share Posted December 13, 2006 that is the code... and it is line 9 ;x<?php$file = "/images/clubs/logos/'.$name.'.jpg";echo (file_exists($file)) ? "<img src='$file' alt='My Image' />" : "<img src='/images/noimg.gif' alt='No Image' />";?>i think there's an error in the syntax with the ' or the "'s somewhere. Quote Link to comment https://forums.phpfreaks.com/topic/30527-displaying-a-default-image-x/#findComment-140549 Share on other sites More sharing options...
zq29 Posted December 13, 2006 Share Posted December 13, 2006 You're using a mixture of double and single quotes when building the contents of $file. Quote Link to comment https://forums.phpfreaks.com/topic/30527-displaying-a-default-image-x/#findComment-140588 Share on other sites More sharing options...
mlin Posted December 13, 2006 Share Posted December 13, 2006 $file = "/images/clubs/logos/$name.jpg"; Quote Link to comment https://forums.phpfreaks.com/topic/30527-displaying-a-default-image-x/#findComment-140591 Share on other sites More sharing options...
suess0r Posted December 13, 2006 Author Share Posted December 13, 2006 OK, so i don't think that syntax was the problem....there was a previous echo before it, and now how it is I don't know how to close this echo... echo ' <tr>'; $file = "/images/clubs/logos/$name.jpg"; echo (file_exists($file)) ? "<img src='$file' alt='My Image' />" : "<img src='/images/noimg.jpg' alt='No Image' Quote Link to comment https://forums.phpfreaks.com/topic/30527-displaying-a-default-image-x/#findComment-140636 Share on other sites More sharing options...
suess0r Posted December 14, 2006 Author Share Posted December 14, 2006 ok, so it's only displaying the default noimg.jpg no matter what (even that I know a lot of the pictures do exist) here's what the code is, am i setting the $file wrong??[quote]echo ' <tr>'; $file = "/images/clubs/logos/$name.jpg"; echo (file_exists($file)) ? "<p align='center'><img src='$file' alt='My Image' />" : "<img src='/images/noimg.jpg' alt='No Image'/></p>";[/quote]appreciate the assitance... Quote Link to comment https://forums.phpfreaks.com/topic/30527-displaying-a-default-image-x/#findComment-140792 Share on other sites More sharing options...
zq29 Posted December 14, 2006 Share Posted December 14, 2006 Try dropping the slash at the front of $file so that it reads "images/clubs/logos/$name.jpg" Quote Link to comment https://forums.phpfreaks.com/topic/30527-displaying-a-default-image-x/#findComment-140978 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.