Jump to content

Recommended Posts

Hi im having a big problem to set up next prev links proparly.

 

Im doing standard image gallery, once in selected category, browser is printing out all thumbs and links to their bigger version. (by id of record) -  i manage to display a big version.

but i dont know how to do links to next and prev id in selected category.

 

 

so i have following queries:

 

1 - is displaing big image.

 

$result=mysql_query("SELECT * FROM morgal WHERE categ='$categ' AND id='$id' LIMIT 1") or die(mysql_error());
	while($row=mysql_fetch_array($result))
	{
echo "<img src='http://www.nita-on-line.com/morgal/photos/";
	echo $row['image'];
	echo ".jpg' border='0'>";
}

 

2 - is the query selecting all records from selected category

 

$res1=mysql_query("SELECT * FROM morgal WHERE cat='$categ' ORDER BY id") or die(mysql_error());

and on the base of this query i would like to display nex prev links (to next prev id)

 

i was traying to count records, and then display links to prev next image but this method is not covering with the id of record so wrong images are being displayed. (standad paging result).

 

to check the script out go to:

www.nita-on-line.com/morgal

 

Im relly stuck on this and would like to move on with it, if some one can give me some idea how to get these links right.

 

 

Thanka a lot for your help!!

 

Nita

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/53535-next-prev-links-in-the-image-gallery/
Share on other sites

On your page where an image is displayed (http://nita-on-line.com/morgal/index.php?categ=01&id=57), use this:

 

<?php

$prev = $_GET["id"] - 1;
$next = $_GET["id"] + 1;
$cat = $_GET["categ"];

echo "<a href=\"index.php?categ=$cat&id=$prev\">Previous Image</a>";
echo "<a href=\"index.php?categ=$cat&id=$next\">Next Image</a>";

?>

thx chigley for a post

 

it's better but has not solved the problem yet.

 

1. what if i have gaps in database (so i cant use "+ 1" and "- 1" with &id).

2. i have to add some if statment to code (so link previous is showing in case where there is a previous id in the category) - same think for next. Couse at the moment i have this links showing up in any case.

 

updated code of when you look at selected id  (big photo + next prev links)

 


else if(isset($_GET['categ'])||isset($_GET['id'])) // when looking at selected id
{

$categ=$_GET['categ'];
$id=$_GET['id'];

$result=mysql_query("SELECT * FROM morgal WHERE cat='$categ' AND id='$id' ORDER BY image LIMIT 1") or die(mysql_error());
	while($row=mysql_fetch_array($result))
	{
echo "<img src='http://www.nita-on-line.com/morgal/photos/";
	echo $row['image'];
	echo ".jpg' border='0'>";
}

$prev = $_GET['id'] - 1;
$next = $_GET['id'] + 1;

echo "<a href=\"index.php?categ=$categ&id=$prev\">Previous Image</a>";
echo "<a href=\"index.php?categ=$categ&id=$next\">Next Image</a>";

}

 

i need some help on this one

 

tkanks a lot in advance ...

 

nita

here we go ....

 

echo "<TABLE width='100%'>";

define ("NUMCOLS",5);
$res = mysql_query("SELECT id, page, cat, thumb FROM morgal WHERE cat='$cat' ORDER BY image");
$count = 0;
while (list($id, $page, $cat, $thumb) = mysql_fetch_row($res))
{

    if ($count % NUMCOLS == 0) echo "<TR>\n";  # new row

    echo "<TD class='font1' width='160'>

<table width='100%' border='0' cellspacing='0' cellpadding='10' class='table1'>
   <tr>
    <td valign='top' align='center'>";
echo "<A href='index.php?categ=$cat&id=$id'><img src='http://www.nita-on-line.com/morgal/photos/";
echo "$thumb";
echo ".jpg' border='0'></a></td>
  </tr>
</table>
</TD>\n";
    $count++;

    if ($count % NUMCOLS == 0) echo "</TR>\n";  # end row
}

# end row if not already ended

if ($count % NUMCOLS != 0) {
   while ($count++ % NUMCOLS) echo "<td> </td>";
   echo "</TR>\n";
}
echo "</TABLE>

 

that should be enough .... if you have any qestions let me know....

 

my problem still left with no solution.. i manage to display big image, but i cant create next / prev links to next, prev big image (id)

 

$prev = $_GET['id'] - 1;
$next = $_GET['id'] + 1;

 

it work for now, but i rather to have these links done to next / prev available id (big pic)

(just in case when i decide to delete some id - creating gaps).

 

i could do it simply with paging result 1 by 1 , but then this will couse a conflict with id passed from thumbnail link. (i mean im sending id from thumbs, which is not going to be = pageid if pagaing used)

 

hel any one...

 

thanks

 

nita

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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