Jump to content

Photo (prev & next)


sharke

Recommended Posts

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);
}
?>

Link to comment
https://forums.phpfreaks.com/topic/185276-photo-prev-next/
Share on other sites

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);
}
?>

Link to comment
https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978537
Share on other sites

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> }
    }
   }
  }
}
?>

Link to comment
https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978553
Share on other sites

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 ....

Link to comment
https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978570
Share on other sites

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>"; }
    }  
}
?>

Link to comment
https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978580
Share on other sites

try this  :shrug:

 

<?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>"; }
    }  
}
?>

Link to comment
https://forums.phpfreaks.com/topic/185276-photo-prev-next/#findComment-978612
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.