Jump to content


Photo

Creating a Image Gallery with Page Navigation


  • Please log in to reply
7 replies to this topic

#1 saikiran

saikiran
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 25 July 2006 - 05:04 AM

hi,

I want to create a Image Gallery. The images are stored in a folder and while be linked with database table.The file name will be stored in the table and retrived and resolved using <img src="<?php echo ./uploads/$row['img_name']">.

I want to add pagination facility in it. Some thing like Back and Next buttons, so that at a time 6 images will be displayed, by clicking next button, the next set of images should come...

while clicking the thumbnails, the image should be opened in a separate popup window. In the popup window also, we have to put next and back functionality.

can anyone show me some tutorial or link for doing this.


cheers
saikiran
saisen76@hotmail.com

#2 manichean

manichean
  • Members
  • PipPip
  • Member
  • 29 posts

Posted 25 July 2006 - 05:44 AM

Hey Saikiran,

Here is a link im sure you will find usefull
http://www.phpfreaks...orials/43/0.php
;D
Cheers

#3 saikiran

saikiran
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 25 July 2006 - 07:24 AM

i,

thank you for the links.

i will check it out as it as and get back to you.I hope my problem will be solved with this code.




cheers
sai

#4 saikiran

saikiran
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 25 July 2006 - 08:04 AM

hi,

I am using this script as it is to check the pagination script.


<?php

    @mysql_connect($localhost, $user, $password) or die("ERROR--CAN'T CONNECT TO SERVER");
    @mysql_select_db($database) or die("ERROR--CAN'T CONNECT TO DB");

    $limit          = 10;             
    $query_count    = "SELECT count(*) FROM table";   
    $result_count  = mysql_query($query_count);   
    $totalrows      = mysql_num_rows($result_count);

    if(empty($page)){
        $page = 1;
    }
       

    $limitvalue = $page * $limit - ($limit);
    $query  = "SELECT * FROM table LIMIT $limitvalue, $limit";       
    $result = mysql_query($query) or die("Error: " . mysql_error());

    if(mysql_num_rows($result) == 0){
        echo("Nothing to Display!");
    }

    $bgcolor = "#E0E0E0"; // light gray

    echo("<table>");
   
    while($row = mysql_fetch_array($result)){
        if ($bgcolor == "#E0E0E0"){
            $bgcolor = "#FFFFFF";
        }else{
            $bgcolor = "#E0E0E0";
        }

    echo("<tr bgcolor=".$bgcolor.">n<td>");
    echo($row["users"]);
    echo("</td>n<td>");
    echo($row["usersID"]);
    echo("</td>n</tr>");
    }

    echo("</table>");

    if($page != 1){
        $pageprev = $page--;
       
        echo("<a href="$PHP_SELF&page=$pageprev">PREV".$limit."</a> ");
    }else{
        echo("PREV".$limit." ");
    }

    $numofpages = $totalrows / $limit;
   
    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href="$PHP_SELF?page=$i">$i</a> ");
        }
    }


    if(($totalrows % $limit) != 0){
        if($i == $page){
            echo($i." ");
        }else{
            echo("<a href="$PHP_SELF?page=$i">$i</a> ");
        }
    }

    if(($totalrows - ($limit * $page)) > 0){
        $pagenext = $page++;
       
        echo("<a href="$PHP_SELF?page=$pagenext">NEXT".$limit."</a>");
    }else{
        echo("NEXT".$limit);
    }
   
    mysql_free_result($result);

?>


i have modified the same script 100%, just to check with my database table.

What i did is changed the limit as 2

<?php

    @mysql_connect("localhost", "admin", "maaindia") or die("ERROR--CAN'T CONNECT TO SERVER");
    @mysql_select_db("shobhacards") or die("ERROR--CAN'T CONNECT TO DB");

    $limit          = 2;             
    $query_count    = "SELECT count(*) FROM prod_catlog2";   
    $result_count  = mysql_query($query_count); 
   
    $totalrows      = mysql_num_rows($result_count);
    echo $totalrows."<br>";
global $page;
    if(empty($page)){
        $page = 1;
    }
       

    $limitvalue = $page * $limit - ($limit);
    $query  = "SELECT * FROM prod_catlog2 LIMIT $limitvalue, $limit";       
    $result = mysql_query($query) or die("Error: " . mysql_error());

    if(mysql_num_rows($result) == 0){
        echo("Nothing to Display!");
    }

    $bgcolor = "#E0E0E0"; // light gray

    echo("<table>");
   
    while($row = mysql_fetch_array($result)){
        if ($bgcolor == "#E0E0E0"){
            $bgcolor = "#FFFFFF";
        }else{
            $bgcolor = "#E0E0E0";
        }

    echo("<tr bgcolor=".$bgcolor.">n<td>");
    echo($row["Product"]);
    echo("</td>n<td>");
    echo($row["Sno"]);
    echo("</td>n</tr>");
    }

    echo("</table>");

    if($page != 1){
        $pageprev = $page--;
       
        "<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."</a> ";
        //echo('<a href="disp.php&page=$pageprev">PREV'.$limit.'</a>');
    }else{
        echo("PREV".$limit." ");
    }

    $numofpages = $totalrows / $limit;
   
    echo $numofpages."<br>";
   
    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo($i." ");
        }else{
       
            echo("<a href=\"$PHP_SELF&page=$i\">$i</a> "); 
        //echo "<a href='disp.php?page='$i''>$i</a>";
            //echo('<a href="disp.php?page=$i">'.'$i'.'</a>' );
        }
    }


    if(($totalrows % $limit) != 0){
        if($i == $page){
            echo($i." ");
        }else{
        echo("<a href=\"$PHP_SELF&page=$i\">$i</a> ");
        }
    }

    if(($totalrows - ($limit * $page)) > 0){
        $pagenext = $page++;
          echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."</a>");
    }else{
        echo("NEXT".$limit);
    }
   
    mysql_free_result($result);

?>


i am using the same $PHP_SELF only, can anyone find this and correct what wrong with this code.

Also, instead of page numbers, i want to show just back and next and navigate to single record (image photo gallery type)

suggestions and some links will be helpful.

cheers
sai





#5 saikiran

saikiran
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 26 July 2006 - 05:12 AM

hi to all,

I tried out the above script, but i am not getting the desirable output.

What i want is this, i have image thumbnails which are placed in a page.

When user clicks any single thumbnail, it has to open a gallery page which has many images (from database) with medium size.

From here, if user presses one image, it should open a popup a show that image in bigger size. I have to provide back and next button facility in both the pages.

kindly help me out in how to do it.


cheers
sai



#6 redarrow

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

Posted 26 July 2006 - 05:30 AM

we can help but not do it for you what problam you got so far error? what?

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

#7 saikiran

saikiran
  • Members
  • PipPip
  • Member
  • 24 posts

Posted 26 July 2006 - 07:38 AM

hi redarrow,

Thank you for your reply. while executing the code

<?php

    @mysql_connect("localhost", "admin", "maaindia") or die("ERROR--CAN'T CONNECT TO SERVER");
    @mysql_select_db("shobhacards") or die("ERROR--CAN'T CONNECT TO DB");

    $limit          = 2;             
    $query_count    = "SELECT count(*) FROM prod_catlog2"; 
    $result_count  = mysql_query($query_count);
 
    $totalrows      = mysql_num_rows($result_count);
    echo $totalrows."
";
  global $page;
    if(empty($page)){
        $page = 1;
    }
     

    $limitvalue = $page * $limit - ($limit);
    $query  = "SELECT * FROM prod_catlog2 LIMIT $limitvalue, $limit";     
    $result = mysql_query($query) or die("Error: " . mysql_error());

    if(mysql_num_rows($result) == 0){
        echo("Nothing to Display!");
    }

    $bgcolor = "#E0E0E0"; // light gray

    echo("<table>");
 
    while($row = mysql_fetch_array($result)){
        if ($bgcolor == "#E0E0E0"){
            $bgcolor = "#FFFFFF";
        }else{
            $bgcolor = "#E0E0E0";
        }

    echo("<tr bgcolor=".$bgcolor.">n<td>");
    echo($row["Product"]);
    echo("</td>n<td>");
    echo($row["Sno"]);
    echo("</td>n</tr>");
    }

    echo("</table>");

    if($page != 1){
        $pageprev = $page--;
     
        "<a href=\"$PHP_SELF&page=$pageprev\">PREV".$limit."[/url] ";
        //echo('<a href="disp.php&page=$pageprev">PREV'.$limit.'[/url]');
    }else{
        echo("PREV".$limit." ");
    }

    $numofpages = $totalrows / $limit;
 
    echo $numofpages."
";
 
    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo($i." ");
        }else{
         
            echo("<a href=\"$PHP_SELF&page=$i\">$i[/url] ");
          //echo "<a href='disp.php?page='$i''>$i[/url]";
            //echo('<a href="disp.php?page=$i">'.'$i'.'[/url]' );
        }
    }


    if(($totalrows % $limit) != 0){
        if($i == $page){
            echo($i." ");
        }else{
          echo("<a href=\"$PHP_SELF&page=$i\">$i[/url] ");
        }
    }

    if(($totalrows - ($limit * $page)) > 0){
        $pagenext = $page++;
          echo("<a href=\"$PHP_SELF?page=$pagenext\">NEXT".$limit."[/url]");
    }else{
        echo("NEXT".$limit);
    }
 
    mysql_free_result($result);

?>


i am not getting any error, instead i am not able to traverse through my records with the back and prev button , as they are not showing the link at all.

if i give something like this http://localhost/gal.php?page = 1 0r 2 0r 3...., then it is showing that particular page.

What i feel is the problem is with the navigation link part.

if you can put some time...i hope you can help me out.

cheers
saikiran

#8 redarrow

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

Posted 26 July 2006 - 08:10 AM

heres my code alter as needed ok

good luck

There you go done it like this live on here know lol..........................

I bet it works first go lol..............please tell me ok i am learning aswell?
<? 

$db=mysql_connect("localhost" , "xxx" , "xxx");
mysql_select_db("promotor",$db);

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

$max_results = 2; 

$from = (($page * $max_results) - $max_results); 

$query="select * from prod_catlog2 where  LIMIT $from, $max_results";


$result=mysql_query($query);
while($record=mysql_fetch_assoc($result)){


echo"<table align='center' width='300'border='4' bordercolor='black'>
<td align='left'><b>Product name<font color='red'><br>".$record["product"]."</font><br>Sno: 
<font color='red'><br>".$record["sno"]."</td><table>";

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM prod_catlog2"),0); 

$total_pages = ceil($total_results / $max_results); 

if($page > 1){ 
    $prev = ($page - 1); 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"></a>"; 
} 

for($i = 1; $i <= $total_pages; $i++){ 
    if(($page) == $i){ 
        echo "$i "; 
        } else { 
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; 
} 
 } 

if($page < $total_pages){ 
    $next = ($page + 1); 
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\"></a>";
} 
 }
?>


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




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users