Jump to content

Recommended Posts

Hi. I cant get to solve my problem with the links in this image gallery.

 

Problem is that when i look at selected image (selected id) links are not printing out according to mysql query. Sure there is a problem with $_GET, variables and i guess construction of the links,

I mess it up, and looking forward to some solution. I feel really stuck on this one, and new and new ideas not helping much.

 

Below is part of the code when browser is looking at selected id in choosen category.

 

 

 

else if(isset($_GET['id'])||isset($_GET['categ'])) // when looking at selected id
{
include "htmlhead.php";
include "header.php";

//menu - category selection

$result = mysql_query("SELECT * FROM morgalcat ORDER BY name") or die(mysql_error());
while($row = mysql_fetch_array( $result )) 
{
echo "<span class='style2'><A href='index.php?cat=$row[cat]'>$row[name]</a></span><br>";
}


if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}
$max_results = 1;
$from = (($page * $max_results) - $max_results); 

$id = $page;

	$result=mysql_query("SELECT * FROM morgal WHERE id='$id'") 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'>";
}

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

// Figure out the total number of pages. 
$total_pages = ceil($total_results / $max_results);

if($page > 1){
    $prev = ($page - 1);
    echo "
<td class='nav'><a href=\"".$_SERVER['PHP_SELF']."?categ=$categ&id=$prev\">Previous</a></td>
  	<td width='2'></td>
";
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<td class='nav'><a href=\"".$_SERVER['PHP_SELF']."?categ=$categ&id=$next\">Next</a><td>";
}

}

 

 

to see this project go to:

www.nita-on-line.com/morgal

 

Thanks for your help in advance, and let me know if you need more code to solve this problem.

 

Nita

Link to comment
https://forums.phpfreaks.com/topic/53403-php-mysql-next-previous-links-problem/
Share on other sites

Ok i re edited some code and situation is a bit better.

 

 

My code is built out of 3 parts:

 

1 - when looking at the root of application

2 - when looking at selected category / sesion and is printing out thumbs with links to..

3 - when looking at selected image in big size and also with navigation next / previous

(in my code it one query selcting all form category and displaying them on by one.)

 

What i want to be done that when you press on on of the thumbnail - browser will go to part 3 aplication with already selected variablre $page.

How do i structure the link and to set the variable $page.

 

 

This is code of part 2.

 

echo "<A href='index.php?categ=$cat&page=$page'><img src='http://www.nita-on-line.com/morgal/photos/";
    echo "$thumb";
    echo ".jpg' border='0'></a>

 

and part 3 of the code

 

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

  if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}
$max_results = 1;
$from = (($page * $max_results) - $max_results); 
$categ=$_GET['categ'];

$result=mysql_query("SELECT * FROM morgal WHERE cat='$categ' ORDER BY image LIMIT $from, $max_results") 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'>";
}

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

// Figure out the total number of pages. Always round up using ceil()
$total_pages = ceil($total_results / $max_results);

if($page > 1){
    $prev = ($page - 1);
    echo "
<td class='nav'><a href=\"".$_SERVER['PHP_SELF']."?categ=$categ&page=$prev\">Previous</a></td>
  	<td width='2'></td>
";
}

// Build Next Link
if($page < $total_pages){
    $next = ($page + 1);
    echo "<td class='nav'><a href=\"".$_SERVER['PHP_SELF']."?categ=$categ&page=$next\">Next</a><td>";
}

}

 

 

so im happy with this part, question is how to get thumbnails links conected to right pages??

 

www.nita-on-line.com/morgal

 

if any on can help, please

 

 

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.