Guber-X Posted July 11, 2009 Share Posted July 11, 2009 my idea was to have a photo album with categories. Categories will be listed at the top at all times, when a category is selected list photos that are in that category. then when a photo is selected, display the photo in full. ive been trying to get this to work for a few days now, and its just not working out for me. I can make it work to the point that is shows the thumbnail, then when clicked displayin the full size, but the thumbnail is still displayed above it. ive done similar stuff like this, but just with content, the basic category select and display whats in it. but some reason i cant get this one to work ??? heres the link: http://70.66.236.26/timeless/photos.php heres my code(sorry for the mess, if theres a cleaner way to do please help me out) <? $result = mysql_query("SELECT * FROM photo_cat ORDER by id"); if (!$result) { die("query failed: " . msql_error()); } while ($row = mysql_fetch_array($result)) { list($id, $cat_name, $cat_id, $location) = $row; print(': <a href=photos.php?cat_id='.$cat_id.' target="_top">'.$cat_name.'</a> :'); } ?> </center> <hr width="350" align="center" /> <? $category = (isset($_GET['cat_id'])) ? intval($_GET['cat_id']) : 0; if($_GET['cat_id']==$category){ $result = mysql_query("SELECT * FROM photo_cat WHERE cat_id=$category ORDER by id"); if (!$result) { die("query failed: " . msql_error()); } while ($row = mysql_fetch_array($result)) { list($id, $cat_name, $cat_id, $location) = $row; $result2 = mysql_query("SELECT * FROM photo_img WHERE cat_id=$category ORDER by id"); if (!$result2) { die("query failed: " . msql_error()); } while ($row = mysql_fetch_array($result2)) { list($id, $pic_id, $file_name, $cat_id, $comment) = $row; print('<a href="photos.php?cat_id='.$cat_id.'&pic_id='.$pic_id.'"><img src="images/'.$location.$file_name.'" width="100" border="0"></a>'); }} } echo('<br />'); $pic_id = (isset($_GET['pic_id'])) ? intval($_GET['pic_id']) : 0; if($_GET['cat_id']==$category && $_GET['pic_id']==$pic_id){ $result3 = mysql_query("SELECT * FROM photo_img WHERE pic_id=$pic_id LIMIT 1"); if (!$result3) { die("query failed: " . msql_error()); } while ($row = mysql_fetch_array($result3)) { print('<img src="images/'.$location.$file_name.'" border="0">'); }} ?> Quote Link to comment Share on other sites More sharing options...
Aeglos Posted July 12, 2009 Share Posted July 12, 2009 Short PHP tags is a bad practice, use full <?php ?> always. It all comes down to this line: print('<a href="photos.php?cat_id='.$cat_id.'&pic_id='.$pic_id.'"><img src="images/'.$location.$file_name.'" width="100" border="0"></a>'); Check for $pic_id > 0 before that line, if the condition is false, execute above said line, else skip it. If you want cleaner code (or at least more organized) try a mini front controller aproach... Before doing anything check all the GET vars. If $pic_id is PROPERLY set you know you only have to display a single image. If it is not set then check for a properly set $cat_id and display the thumbnails, or else just display the categories. The usual simple way is with an $action variable, like $action=thumbnails&cat_id=3 or $action=display&pic_id=76. Then you only check for the proper action (with an if-ifelse-else or a switch() conditional) and act accordingly using the rest of the GET variables supplied. Keeps things more organized. After that a whole world opens up which leads to full front controllers, page controllers, mvc and whatnot. Cheers. Quote Link to comment Share on other sites More sharing options...
Guber-X Posted July 14, 2009 Author Share Posted July 14, 2009 as far as i see it, everything works cept the if and elseif actions... Quote Link to comment Share on other sites More sharing options...
Guber-X Posted July 14, 2009 Author Share Posted July 14, 2009 bump if anyone can help me out it would be greatly appreciated Quote Link to comment 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.