Jump to content


Photo

Result Set Limit and Navigation problem


  • Please log in to reply
2 replies to this topic

#1 saikiran

saikiran
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 11 August 2006 - 08:49 AM

hi,

I am running a photo gallery in my site. in which , i am having a thumbnail page and a popup image page,

what i am doing is when user clicks the thumbnail, the bigger picture should open in a popup in a separate page.

I would like to add a navigation link in the popup page. i.e. with in the popup page, user can go and view the rest of the images in the gallery also.


i am providing this as 1,2 ,3,4,5.....[Next][Previous] .  format.

i am not able to run the navigation part properly....



This is what the code for the 2 pages:

Thumbnails page code

<?php include_once('config.php');
$psql = "select * from bhakt_photo";
$result = mysql_query($psql);

if($result)
{
    while($row = mysql_fetch_array($result,MYSQL_BOTH))
    {
        echo "<table>";
        echo "<tr>";
        echo "<td>";?>
        <a  href='bhakti_popnew.php?id=<?php echo $row['id'];?>'><img src="http://www.seher.in/gall_upload/ <?php echo $row['mid_img'];?>" border="0" ></a>       
        <?php
        echo "</td>";
        echo "</table>";
    }
}

?>


-----Popup page code-------------


<?php include('config.php');
//new code

$id=$_GET['id']; //this the Id i am getting for the images

// how many rows to show per page

$rowsPerPage = 1;

// by default we show first page

$pageNum = 1;

// if $_GET['page'] defined, use it as page number
if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}

// counting the offset
$offset = ($pageNum - 1) * $rowsPerPage;
//$offset =  $rowsPerPage;

$query = " SELECT * FROM bhakt_photo where id=$id " .
         " LIMIT $offset, $rowsPerPage";

echo $query."<br>"         ;

$result = mysql_query($query) or die('Error, query failed');

?>
<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">

        <?php
        while($row = mysql_fetch_array($result))
        {
            echo $row['big_img'];
         } ?>
      </table>
      <br>
<br>
<?php // how many rows we have in database

$query   = "SELECT COUNT(big_img) AS numrows FROM bhakt_photo ";

$result  = mysql_query($query) or die('Error, query failed');
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];

// how many pages we have when using paging?
$maxPage = ceil($numrows/$rowsPerPage);

// print the link to access each page
$self = $_SERVER['PHP_SELF'];
$nav  = '';

for($page = 1; $page <= $maxPage; $page++)
{
   if ($page == $pageNum)
   {
      $nav .= " $page "; // no need to create a link to current page
     
   }
   else
   {  
      $nav .= " <a href=\"$self?page=$page\">$page</a> ";     
     
   }
}
if ($pageNum > 1)
{
   $page  = $pageNum - 1;      
  $id  = $id-1;
  
   $prev  = " <a href=\"$self?page=$page&id=$id\">[Prev]</a> ";
   $first = " <a href=\"$self?page=1&id=$id\">[First Page]</a> ";
  
   //$prev  = " <a href=\"$self?page=$page\">[Prev]</a> ";
   //$first = " <a href=\"$self?page=1\">[First Page]</a> ";
}
else
{
   $prev  = '&nbsp;'; // we're on page one, don't print previous link
   $first = '&nbsp;'; // nor the first page link
}

if ($pageNum < $maxPage)
{
   $page = $pageNum + 1;  
   $id = $id +1;
  
  echo "<b>". $id."<br>";
 
       $next = " <a href=\"$self?page=$page&id=$id\">[Next]</a> ";
       $last = " <a href=\"$self?page=$maxPage&id=$id\">[Last Page]</a> ";
 
 
       //$next = " <a href=\"$self?page=$page\">[Next]</a> ";
       //$last = " <a href=\"$self?page=$maxPage\">[Last Page]</a> ";
}
else
{
   $next = '&nbsp;'; // we're on the last page, don't print next link
   $last = '&nbsp;'; // nor the last page link
}

// print the navigation link
echo $first . $prev . $nav . $next . $last;

// and close the database connection


// ... and we're done!
?>

the problem what i assume is - the 'id' value is not passing in the subsquent pages properly.

i have checked readymade photogallery packages...but i would like to have my own. I am not an expert in PHP too.

can anyone just tell me whats the problem in my code and help me out in completing this one.


cheers
saikiran
saisen76@hotmail.com

#2 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 11 August 2006 - 08:55 AM

weres the javascript


Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#3 saikiran

saikiran
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 11 August 2006 - 09:32 AM

hi,

this is how i am calling it into the popup.

sorry for not putting the popup one

<?php include_once('config.php');
$psql = "select * from bhakt_photo";
$result = mysql_query($psql);

if($result)
{
    while($row = mysql_fetch_array($result,MYSQL_BOTH))
    {
        echo "<table>";
        echo "<tr>";
        echo "<td>";?>
<a  href="javascript:;" onClick = "window.open('bhakti_popnew.php?id=<?php echo $row['id'];?>','Gallery','height=700,width=589,scrolling=yes')"><img src="http://www.seher.in/uploads/<?php echo $row['mid_img'];?>" border="0" ></a>
        <?php
        echo "</td>";
        echo "</table>";
    }
}

?>



cheers
saikiran




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users