JTapp Posted May 24, 2008 Author Share Posted May 24, 2008 runnerjp - no deal.. when there IS an image, the message takes over and the image isn't displayed. Thanks for your time! Quote Link to comment https://forums.phpfreaks.com/topic/106818-solved-when-image-is-missing-how-to-display-my-own-icon-instead-of-red-x/page/2/#findComment-549185 Share on other sites More sharing options...
runnerjp Posted May 24, 2008 Share Posted May 24, 2008 ty this <?PHP $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); $selected = mysql_select_db("lodges",$dbhandle) or die("Could not select lodges"); $id = $_GET['id']; $query = mysql_query("SELECT a.strLodgeName, a.intLodgeNumber, a.intDistrictID, a.strLodgeWEB, a.strLodgeCounty, a.dtChartered, a.strLodgeMeetingPlace, a.strLodgeLocationCity, a.strLodgeLocationState, a.strLodgeLocationZip, a.strLodgeEmail, a.strLodgePhone, a.strLodgeFax, a.strDrivingDirectons, a.dtMeetingTime, a.strMeetingCodes, a.dtMealTime, a.strFloorSchool, a.strLodgeNews, a.strLodgePhotoPathAndName, b.strOfficerTitle, b.strFirstName, b.strLastName, b.BusinessPhone, b.PersEmail FROM tblLodges a LEFT JOIN tblOfficers b ON a.lngLodgeID = b.lngLodgeID WHERE a.intLodgeNumber=$id GROUP BY a.strLodgeName LIMIT 50")or die(mysql_error()); while ($row = @mysql_fetch_array($query)) { $variable1=$row["strLodgeName"]; $variable2=$row["intLodgeNumber"]; $variable3=$row["intDistrictID"]; $variable4=$row["strLodgeWEB"]; $variable5=$row["strLodgeCounty"]; $variable6=$row["dtChartered"]; $variable7=$row["strLodgeMeetingPlace"]; $variable8=$row["strLodgeLocationCity"]; $variable9=$row["strLodgeLocationState"]; $variable10=$row["strLodgeLocationZip"]; $variable12=$row["strLodgeEmail"]; $variable13=$row["strLodgePhone"]; $variable14=$row["strLodgeFax"]; $variable15=$row["strDrivingDirectons"]; $variable16=$row["dtMeetingTime"]; $variable17=$row["dtMealTime"]; $variable18=$row["strFloorSchool"]; $variable19=$row["strLodgeNews"]; $variable20=$row["strLodgePhotoPathAndName"]; $variable21=$row["strMeetingCodes"]; $imagesFolder = '/lodgeimages/'; //table layout for results echo "<center>\n"; echo "<p><H3>LODGE: $variable1</H4></p>"; //image to be displayed $q = mysql_query($query) or die("Error running query:".mysql_error()); if($q && mysql_num_rows($q) > 0) { $row = mysql_fetch_array($q); if(!empty($row)) { echo "<img src='" . $imagesFolder . $row['companyid'] . ".jpg' /></p>"; } else { echo 'no image'; } } echo "<p><b>Lodge Number:</b> $variable2</p>"; echo "<p><b>District Name:</b> $variable3</p>"; echo "<a href=\"$variable4\">Click Here To Go To The Lodge Website</a>"; echo "<p><b>Lodge County:</b> $variable5</p>"; echo "<p><b>Lodge Chartered On:</b> $variable6</p>"; echo "<p><b>Lodge Address: </b> $variable7</p>"; echo "<p>$variable8, $variable9 $variable10</p>"; echo "<a href=\"mailto:$variable12\">Click Here To Email The Lodge</a>"; echo "<p><b>Lodge Phone Number: </b> $variable13</p>"; echo "<p><b>Lodge FAX Number: </b> $variable14</p>"; echo "<p><b>Lodge Driving Directions:</b><a href='http://maps.google.com/maps?saddr=&daddr=".$variable7.", ".$variable8.", ".$variable9."' target='_blank'>Link</a></p>"; echo "<p<b>Lodge Meetings:</b> $variable21</p>"; echo "<p><b>Lodge Meeting Time:</b> $variable16</p>"; echo "<p><b>Lodge Meal Time:</b> $variable17</p>"; echo "<p><b>Lodge Floor School:</b> $variable18</p>"; echo "<p><b>Lodge News:</b> $variable19</p>"; echo "</center>\n"; } ?> <hr> <p> <?php //query details table begins $query = mysql_query("SELECT tblLodges.strLodgeName, tblLodges.intLodgeNumber, tblLodges.intDistrictID, tblLodges.strLodgeLocationCity, tblLodges.strLodgeLocationZip, tblLodges.strLodgeCounty, tblOfficers.lngLodgeID, tblOfficers.strOfficerTitle, tblOfficers.strFirstName, tblOfficers.strLastName, tblOfficers.BusinessPhone, tblOfficers.PersEmail FROM tblLodges LEFT JOIN tblOfficers ON tblLodges.lngLodgeID = tblOfficers.lngLodgeID WHERE tblLodges.intLodgeNumber=$id GROUP BY tblOfficers.lngOfficerTitleID LIMIT 0, 50")or die(mysql_error()); echo "<center>\n"; echo "<H2>Roster of Lodge Officers</H2>\n"; echo "<table border='1'> <tr> <th>Lodge Number</th> <th>Officer Title</th> <th>Officer First</th> <th>Officer Last</th> <th>Officer Email</th> <th>Officer Phone</th> </tr>"; if (mysql_num_rows($query)) { while ($row = mysql_fetch_array($query)) { $variable1=$row["intLodgeNumber"]; $variable2=$row["strOfficerTitle"]; $variable3=$row["strFirstName"]; $variable4=$row["strLastName"]; $variable5=$row["PersEmail"]; $variable6=$row["BusinessPhone"]; //table layout for results print("<tr>"); echo "<tr align=\"center\" bgcolor=\"#EFEFEF\">\n"; echo "<td class=\"td_id\">$variable1</td>\n"; echo "<td class=\"td_id\">$variable2</td>\n"; echo "<td class=\"td_id\">$variable3</td>\n"; echo "<td class=\"td_id\">$variable4</td>\n"; echo "<td class=\"td_id\">$variable5</td>\n"; echo "<td class=\"td_id\">$variable6</td>\n"; print("</tr>"); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/106818-solved-when-image-is-missing-how-to-display-my-own-icon-instead-of-red-x/page/2/#findComment-549191 Share on other sites More sharing options...
JTapp Posted May 24, 2008 Author Share Posted May 24, 2008 I got a blank page on that one... Quote Link to comment https://forums.phpfreaks.com/topic/106818-solved-when-image-is-missing-how-to-display-my-own-icon-instead-of-red-x/page/2/#findComment-549197 Share on other sites More sharing options...
runnerjp Posted May 24, 2008 Share Posted May 24, 2008 ok i will tell you what i do for this... its my little work around... on signup i assign the user with 0.jpg in there image field... that way if they have no image then 0.jpg will be shown Quote Link to comment https://forums.phpfreaks.com/topic/106818-solved-when-image-is-missing-how-to-display-my-own-icon-instead-of-red-x/page/2/#findComment-549206 Share on other sites More sharing options...
JTapp Posted May 25, 2008 Author Share Posted May 25, 2008 Photos are stored in an 'Images' folder on my server. Let's just say each photo is named 'companyID.jpg' (really called 'intLodgeNumber') in that folder. In my database there is a 'companyID' field - this is a primary field and can't be changed. So my code looks for the ID in the database and matches it to the image in the folder. Here is my code: echo "<img src='" . $imagesFolder . $row['companyID'] . ".jpg' /></p>"; So I can't change the 'companyID' field.. there will always be a value. if I create a 0.jpg - I've got to figure out a way to tell it to search for the 'companyID.jpg' in the Images folder and if there isn't one, to use 0.jpg. Its starting to seem impossible... Quote Link to comment https://forums.phpfreaks.com/topic/106818-solved-when-image-is-missing-how-to-display-my-own-icon-instead-of-red-x/page/2/#findComment-549337 Share on other sites More sharing options...
DarkerAngel Posted May 25, 2008 Share Posted May 25, 2008 If all your images are in a central folder (and assuming your using Apache) you can add a .htaccess file Just have ErrorDocument 404 yourimage.php You can have the PHP file detect if the user was trying to get a page or an image, say if they where after a page redirect somewhere and if it is a image display the error image using GD if you need help with that just let me know Quote Link to comment https://forums.phpfreaks.com/topic/106818-solved-when-image-is-missing-how-to-display-my-own-icon-instead-of-red-x/page/2/#findComment-549343 Share on other sites More sharing options...
AndyB Posted May 25, 2008 Share Posted May 25, 2008 This ought to be a trivial exercise. I suspect the problem lies in the confusion of exactly where the images are, relevant to the script looking for them. You tell us that /lodgeimages/147.jpg is an example of one image. So is the value of the variable $imagesFolder actually /lodgeimages/ ? If it is then pocobueno's code for file_exists is going to work. Quote Link to comment https://forums.phpfreaks.com/topic/106818-solved-when-image-is-missing-how-to-display-my-own-icon-instead-of-red-x/page/2/#findComment-549441 Share on other sites More sharing options...
JTapp Posted May 25, 2008 Author Share Posted May 25, 2008 Yes, you are correct - this is the line that refers to it: $imagesFolder = '/lodgeimages/'; Still, P's code isn't working..? Here is a suggestion from another forum - but it doesn't make sense to me.. and it isn't working.. any thoughts on it? if (file_exists($imagesFolder.$row['intLodgeNumber'].".jpg")) { echo "<img src='" . $imagesFolder . $row['intLodgeNumber'] . ".jpg' /></p>"; } else { //just because it was on the end of your line... echo the </p> if no image echo "</p>"; } Quote Link to comment https://forums.phpfreaks.com/topic/106818-solved-when-image-is-missing-how-to-display-my-own-icon-instead-of-red-x/page/2/#findComment-549541 Share on other sites More sharing options...
sasa Posted May 25, 2008 Share Posted May 25, 2008 change line if (file_exists($imagesFolder.$row['intLodgeNumber'].".jpg")) { to if (file_exists($_SERVER['DOCUMENT_ROOT'].$imagesFolder.$row['intLodgeNumber'].".jpg")) { Quote Link to comment https://forums.phpfreaks.com/topic/106818-solved-when-image-is-missing-how-to-display-my-own-icon-instead-of-red-x/page/2/#findComment-549631 Share on other sites More sharing options...
JTapp Posted May 25, 2008 Author Share Posted May 25, 2008 sasa - YOU ROCK! Thank you very much...hours and hours of frustration to an end! Have an awesome weekend! change line if (file_exists($imagesFolder.$row['intLodgeNumber'].".jpg")) { to if (file_exists($_SERVER['DOCUMENT_ROOT'].$imagesFolder.$row['intLodgeNumber'].".jpg")) { Quote Link to comment https://forums.phpfreaks.com/topic/106818-solved-when-image-is-missing-how-to-display-my-own-icon-instead-of-red-x/page/2/#findComment-549653 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.