sharke Posted December 15, 2009 Share Posted December 15, 2009 Hi guys i need help for correct get photo id from datebase, i have 4 photos to same category photo_id(7,8,22,28), now when i'm on photo 8 i have button only for Previous photo... <?php $result = mysql_query("SELECT * FROM photos WHERE photo_id='".$_GET['photo_id']."'"); while ($data = mysql_fetch_assoc($result)){ $pres = mysql_query("SELECT photo_id FROM photos WHERE photo_id = '".($data['photo_id']-1)."' AND photo_catid='13'"); $nres = dbquery("SELECT photo_id FROM photos WHERE photo_id = '".($data['photo_id']+1)."' AND photo_catid='13'"); $prev = mysql_fetch_assoc($pres); $next = mysql_fetch_assoc($nres); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/ Share on other sites More sharing options...
sharke Posted December 15, 2009 Author Share Posted December 15, 2009 anyone Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978074 Share on other sites More sharing options...
sharke Posted December 16, 2009 Author Share Posted December 16, 2009 nobody replay , if i have in category 10 photos with random id's like (1,2,5,9,14) and when i'm on photo id 2 i have button only for previous photo ... can somebody help me Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978446 Share on other sites More sharing options...
rajivgonsalves Posted December 16, 2009 Share Posted December 16, 2009 you should use limit ? and this will be mysql not php Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978450 Share on other sites More sharing options...
Adam Posted December 16, 2009 Share Posted December 16, 2009 Guessing you didn't get a reply because you never actually asked a question. Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978453 Share on other sites More sharing options...
sharke Posted December 16, 2009 Author Share Posted December 16, 2009 $result = mysql_query("SELECT * FROM photos WHERE photo_id='".$_GET['photo_id']."'"); where i must use limit here ? please example me you should use limit ? and this will be mysql not php Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978455 Share on other sites More sharing options...
rajivgonsalves Posted December 16, 2009 Share Posted December 16, 2009 well you'll have to keep the current position in mind so I guess its php+mysql, following will show you the third image $pos = 2; $result = mysql_query("SELECT * FROM photos WHERE photo_id='".$_GET['photo_id']."' limit $pos, 1"); Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978458 Share on other sites More sharing options...
sharke Posted December 16, 2009 Author Share Posted December 16, 2009 if i used you this code mysql_num_rows return 0 $pos = 2; $result = mysql_query("SELECT * FROM photos WHERE photo_id='".$_GET['photo_id']."' limit $pos, 1"); Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978470 Share on other sites More sharing options...
rajivgonsalves Posted December 16, 2009 Share Posted December 16, 2009 it should have been infact, will show you the third photo in the category you might want to order it so you get correct results $pos = 2; $result = mysql_query("SELECT * FROM photos WHERE photo_catid='13' limit $pos, 1"); Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978475 Share on other sites More sharing options...
sharke Posted December 16, 2009 Author Share Posted December 16, 2009 i dont see here result for now or my code is wrong... photos.php?photo_id=2 <?php $result = mysql_query("SELECT * FROM photos WHERE photo_id='".$_GET['photo_id']."'"); while ($data = mysql_fetch_assoc($result)){ $pos = $data['photo_id']; $result2 = mysql_query("SELECT * FROM photos WHERE photo_catid='13' limit $pos, 1"); $data2 = mysql_fetch_assoc($result2); $pres = mysql_query("SELECT photo_id FROM photos WHERE photo_id = '".($data2['photo_id']-1)."' AND photo_catid='13'"); $nres = dbquery("SELECT photo_id FROM photos WHERE photo_id = '".($data2['photo_id']+1)."' AND photo_catid='13'"); $prev = mysql_fetch_assoc($pres); $next = mysql_fetch_assoc($nres); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978537 Share on other sites More sharing options...
rajivgonsalves Posted December 16, 2009 Share Posted December 16, 2009 definitely some problem in the code, if you could post more code on where your using these variables it would be helpful Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978545 Share on other sites More sharing options...
sharke Posted December 16, 2009 Author Share Posted December 16, 2009 I hope you can now help me .. Here is code... <?php if (isset($_GET['photo_id']) && isnum($_GET['photo_id'])){ $update_counter = mysql_query("UPDATE photos SET photo_views=photo_views+1 WHERE photo_id='".$_GET['photo_id']."'"); $result = dbquery("SELECT * FROM photos WHERE photo_id='".$_GET['photo_id']."'"); if(mysql_num_rows($result)){ while ($data = mysql_fetch_assoc($result)){ $pres = dbquery("SELECT photo_id FROM photos WHERE photo_id = '".($data['photo_id']-1)."'"); $nres = dbquery("SELECT photo_id FROM photos WHERE photo_id = '".($pole['photo_id']+1)."'"); if (mysql_num_rows($pres)) $prev = mysql_fetach_assoc($pres); if (mysql_num_rows($nres)) $next = mysql_fetach_assoc($nres); if ((isset($prev['photo_id']) && isnum($prev['photo_id'])) || (isset($next['photo_id']) && isnum($next['photo_id']))) { if (isset($prev)) { <a href='".$PHP_SELF."?photo_id=".$prev['photo_id']."'>Prev Photo</a> } if (isset($next)) { <a href='".$PHP_SELF."?photo_id=".$next['photo_id']."'>Next Photo</a> } } } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978553 Share on other sites More sharing options...
rajivgonsalves Posted December 16, 2009 Share Posted December 16, 2009 might you explain exactly what are you trying to do in this script ? Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978560 Share on other sites More sharing options...
sharke Posted December 16, 2009 Author Share Posted December 16, 2009 Ok this is simple photo gallery script, in photos.php show thmubmanils, photos.php?photo_id=2 here get full size of image, i need set buttons for next and previous photos from same category. In category(13) i have 5 photos id's(1,2,5,9,14). If i use pasted code and i watch photo with ID 2 only i get button for previous not for next photo with id(5). i hope you can undastand me... Soryy for bad english .... Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978570 Share on other sites More sharing options...
rajivgonsalves Posted December 16, 2009 Share Posted December 16, 2009 try this out hopefully it works <?php if (isset($_GET['photo_id']) && isnum($_GET['photo_id'])){ $update_counter = mysql_query("UPDATE photos SET photo_views=photo_views+1 WHERE photo_id='".$_GET['photo_id']."'"); $result = dbquery("SELECT * FROM photos WHERE photo_id='".$_GET['photo_id']."'"); if(mysql_num_rows($result)){ $data = mysql_fetch_assoc($result); $cat_photos_res = dbquery("SELECT photo_id FROM photos WHERE photo_catid = '{$data['photo_catid']}'"); $cat_photos = array(); while ($row = mysql_fetch_assoc($cat_photos_res)) { $cat_photos[] = $row['photo_id']; } $photo_index = array_search($cat_photos, $_GET['photo_id']); if (isset($cat_photos[$photo_index-1])) { echo "<a href={$_SERVER['PHP_SELF']}?photo_id=".$cat_photos[$photo_index-1]."'>Prev Photo</a>"; } if (isset($cat_photos[$photo_index+1])) { echo "<a href='{$_SERVER['PHP_SELF']}?photo_id=".$cat_photos[$photo_index+1]."'>Next Photo</a>"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978580 Share on other sites More sharing options...
sharke Posted December 16, 2009 Author Share Posted December 16, 2009 now i get this error Warning: array_search() [function.array-search]: Wrong datatype for second argument in C:\xampp\htdocs\site\photos.php on line 16. Now i have button for next photo, no button for previous... Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978591 Share on other sites More sharing options...
rajivgonsalves Posted December 16, 2009 Share Posted December 16, 2009 this $photo_index = array_search($cat_photos, $_GET['photo_id']); should have been $photo_index = array_search($_GET['photo_id'], $cat_photos); Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978596 Share on other sites More sharing options...
sharke Posted December 16, 2009 Author Share Posted December 16, 2009 Strage, when i watch photo with id 1 Previous button show photo id(19) Next button show id(2).. Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978602 Share on other sites More sharing options...
rajivgonsalves Posted December 16, 2009 Share Posted December 16, 2009 try this <?php if (isset($_GET['photo_id']) && isnum($_GET['photo_id'])){ $update_counter = mysql_query("UPDATE photos SET photo_views=photo_views+1 WHERE photo_id='".$_GET['photo_id']."'"); $result = dbquery("SELECT * FROM photos WHERE photo_id='".$_GET['photo_id']."'"); if(mysql_num_rows($result)){ $data = mysql_fetch_assoc($result); $cat_photos_res = dbquery("SELECT photo_id FROM photos WHERE photo_catid = '{$data['photo_catid']}' order by photo_id"); $cat_photos = array(); while ($row = mysql_fetch_assoc($cat_photos_res)) { $cat_photos[] = $row['photo_id']; } $photo_index = array_search($_GET['photo_id'], $cat_photos,); if (isset($cat_photos[$photo_index-1])) { echo "<a href={$_SERVER['PHP_SELF']}?photo_id=".$cat_photos[$photo_index-1]."'>Prev Photo</a>"; } if (isset($cat_photos[$photo_index+1])) { echo "<a href='{$_SERVER['PHP_SELF']}?photo_id=".$cat_photos[$photo_index+1]."'>Next Photo</a>"; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978612 Share on other sites More sharing options...
sharke Posted December 16, 2009 Author Share Posted December 16, 2009 Working perfectly Thank you very much !! Quote Link to comment https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978618 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.