Jump to content

Archived

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

saikiran

Creating a Image Gallery with Page Navigation

Recommended Posts

hi,

[color=red]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']">.[/color]

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

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

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


cheers
saikiran
saisen76@hotmail.com

Share this post


Link to post
Share on other sites
Hey Saikiran,

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

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
hi,

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


[quote]<?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");

    [color=red]$limit          = 10;              [/color]
    $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);

?> [/quote]

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

What i did is changed the limit as 2

[color=red]<?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);

?>[/color]

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



Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
we can help but not do it for you what problam you got so far error? what?

Share this post


Link to post
Share on other sites
hi redarrow,

Thank you for your reply. while executing the code

[quote]<?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);

?>[/quote]

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 [color=red]http://localhost/gal.php?page = 1 0r 2 0r 3[/color]...., 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

Share this post


Link to post
Share on other sites
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?
[code]
<?

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

[/code]

Share this post


Link to post
Share on other sites

×

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.