Page 1 of 1

Paginate pictures, each of them with a link

Posted: Thu Jun 11, 2009 5:51 am
by selom86
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Hello, I'm not very good in php and i need your help for this: i managed to paginate but my problem is that i would like that each of the generated pictures is a link and

send a particular information so that when clicked, the same picture displays somewhere else. This works only for first ten pictures.
This is my last page i'm submitting tomorrow. Please I need help!

Code: Select all

<?php
//connect to the database
include_once ("DBConfig.php");
 
//paginator
require_once 'paginator.class.php';
 
 
//select albums
$query_albums = "select distinct img_folder from images";
$result = mysql_query($query_albums) or die("cant process the query $query_albums");
$nbRow = mysql_num_rows($result);
 
//define variables
$rev1 ="Revival Day 1";
 
                    
//query to download revival day 1 pictures
$query_rev1 = "select * from images where img_folder ='revival day 1'";
                        
//process query
$result_rev1 = mysql_query($query_rev1) or die ("could not process $query_rev1");
                        
//calculate number of picture in the folder rev1
$nbp = mysql_num_rows($result_rev1);
                        
//go through the table and get the number of row of rev1
$querNbRowRev1 = "SELECT COUNT(*) FROM images where img_folder='revival day 1'";
 
$resltNbRowRev1 = mysql_query($querNbRowRev1 ) or die ("could not process $querNbRowRev1 ");
 
$num_of_rowRev1 = mysql_fetch_row($resltNbRowRev1);
//var_dump($num_of_rowRev1);
 
 //create objects
$pages = new Paginator;
$pages->items_total = $num_of_rowRev1[0];
$pages->mid_range = 9; 
$pages->paginate();
 
                        
//select all pictures
$quSelectAllRev1 = "select img_name, img_path from images where img_folder='revival day 1' $pages->limit";
$reAllRev1 = mysql_query($quSelectAllRev1) or die("could not process query $quSelectAllRev1");
 
?>
 
<html>                      
<head>
<title>Image Gallery - Help Factory International Ministries</title>
</head>
 
<body>
<?php
               echo"<table style='width: 100%; height: 204px;' >"; //this table produces 10 cells each of them with a picture
                        $i=0;
                        $open_line="<tr>";
                        $close_line="</tr>";
 
 
                        for ($i=0; $i<=11; $i++)
                          {
                              if ($i==0 || $i==6)
                                {
                                    echo"$open_line";
                                }
 
                                elseif ($i==5 || $i==11)
                                {
                                    echo"$close_line";
                                }
                                else
                                {
                                    $row = mysql_fetch_array($reAllRev1);
                                   
                                    
                                        $img_name[$i] = $row['img_name'];
                                        $img_path[$i] = $row['img_path'];
                                        echo"<td style='width:121px; height:101px'>";
                                        if ($row !== false)
                                         {
                                            echo"<img alt='$img_name[$i]' src='$img_path[$i]/$img_name[$i]' style='width:121px; height:101px;border:1px #C9E673 solid'>";
                                         }
                                        echo"</td>";
                                   
                                    
 
                                }
                          }
                          echo"</table>";
                         echo "<p style='text-align:center; margin-bottom:10px'>"; echo $pages->display_pages() ; echo" Page $pages->current_page of 
 
$pages->num_pages</p>";
    ?>
    
                <div style="margin-top:20px; height: 630px;margin-top:50px; width:504px">
                
                <?
                    echo"<img alt='$img_name[1]' src='$img_path[1]/$img_name[1]' style='width:504px;border:3px black 
 
solid'>"; // any generated picture in the table above you click shoud appear here
                ?>
 
                
                </div>
 
</body>
</html>


this is the paginator i used

Code: Select all

<?php
 
class Paginator{
    var $items_per_page;
    var $items_total;
    var $current_page;
    var $num_pages;
    var $mid_range;
    var $low;
    var $high;
    var $limit;
    var $return;
    var $default_ipp = 8;
    var $querystring;
 
    function Paginator()
    {
        $this->current_page = 1;
        $this->mid_range = 7;
        $this->items_per_page = (!empty($_GET['ipp'])) ? $_GET['ipp']:$this->default_ipp;
    }
 
    function paginate()
    {
        if($_GET['ipp'] == 'All')
        {
            $this->num_pages = ceil($this->items_total/$this->default_ipp);
            $this->items_per_page = $this->default_ipp;
        }
        else
        {
            if(!is_numeric($this->items_per_page) OR $this->items_per_page <= 0) $this->items_per_page = $this->default_ipp;
            $this->num_pages = ceil($this->items_total/$this->items_per_page);
        }
        $this->current_page = (int) $_GET['page']; // must be numeric > 0
        if($this->current_page < 1 Or !is_numeric($this->current_page)) $this->current_page = 1;
        if($this->current_page > $this->num_pages) $this->current_page = $this->num_pages;
        $prev_page = $this->current_page-1;
        $next_page = $this->current_page+1;
 
        if($_GET)
        {
            $args = explode("&",$_SERVER['QUERY_STRING']);
            foreach($args as $arg)
            {
                $keyval = explode("=",$arg);
                if($keyval[0] != "page" And $keyval[0] != "ipp") $this->querystring .= "&" . $arg;
            }
        }
 
        if($_POST)
        {
            foreach($_POST as $key=>$val)
            {
                if($key != "page" And $key != "ipp") $this->querystring .= "&$key=$val";
            }
        }
 
        if($this->num_pages > 10)
        {
            $this->return = ($this->current_page != 1 And $this->items_total >= 10) ? "<a class=\"paginate\" 
 
href=\"$_SERVER[PHP_SELF]?page=$prev_page&ipp=$this->items_per_page$this->querystring\">&laquo; Previous</a> ":"<span class=\"inactive\" 
 
href=\"#\">&laquo; Previous</span> ";
 
            $this->start_range = $this->current_page - floor($this->mid_range/2);
            $this->end_range = $this->current_page + floor($this->mid_range/2);
 
            if($this->start_range <= 0)
            {
                $this->end_range += abs($this->start_range)+1;
                $this->start_range = 1;
            }
            if($this->end_range > $this->num_pages)
            {
                $this->start_range -= $this->end_range-$this->num_pages;
                $this->end_range = $this->num_pages;
            }
            $this->range = range($this->start_range,$this->end_range);
 
            for($i=1;$i<=$this->num_pages;$i++)
            {
                if($this->range[0] > 2 And $i == $this->range[0]) $this->return .= " ... ";
                // loop through all pages. if first, last, or in range, display
                if($i==1 Or $i==$this->num_pages Or in_array($i,$this->range))
                {
                    $this->return .= ($i == $this->current_page And $_GET['page'] != 'All') ? "<a title=\"Go to page $i of 
 
$this->num_pages\" class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" title=\"Go to page $i of $this->num_pages\" 
 
href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> ";
                }
                if($this->range[$this->mid_range-1] < $this->num_pages-1 And $i == $this->range[$this->mid_range-1]) 
 
$this->return .= " ... ";
            }
            $this->return .= (($this->current_page != $this->num_pages And $this->items_total >= 10) And ($_GET['page'] != 'All')) ? "<a 
 
class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=$next_page&ipp=$this->items_per_page$this->querystring\">Next &raquo;</a>\n":"<span 
 
class=\"inactive\" href=\"#\">&raquo; Next</span>\n";
            $this->return .= ($_GET['page'] == 'All') ? "<a class=\"current\" style=\"margin-left:10px\" href=\"#\"></a> \n":"<a 
 
class=\"paginate\" style=\"margin-left:10px\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All$this->querystring\"></a> \n";
        }
        else
        {
            for($i=1;$i<=$this->num_pages;$i++)
            {
                $this->return .= ($i == $this->current_page) ? "<a class=\"current\" href=\"#\">$i</a> ":"<a class=\"paginate\" 
 
href=\"$_SERVER[PHP_SELF]?page=$i&ipp=$this->items_per_page$this->querystring\">$i</a> ";
            }
            $this->return .= "<a class=\"paginate\" href=\"$_SERVER[PHP_SELF]?page=1&ipp=All$this->querystring\"></a> \n";
        }
        $this->low = ($this->current_page-1) * $this->items_per_page;
        $this->high = ($_GET['ipp'] == 'All') ? $this->items_total:($this->current_page * $this->items_per_page)-1;
        $this->limit = ($_GET['ipp'] == 'All') ? "":" LIMIT $this->low,$this->items_per_page";
    }
 
    function display_items_per_page()
    {
        $items = '';
        $ipp_array = array(10,25,50,100,'All');
        foreach($ipp_array as $ipp_opt) $items .= ($ipp_opt == $this->items_per_page) ? "<option selected 
 
value=\"$ipp_opt\">$ipp_opt</option>\n":"<option value=\"$ipp_opt\">$ipp_opt</option>\n";
        return "<span class=\"paginate\">Items per page:</span><select class=\"paginate\" 
 
onchange=\"window.location='$_SERVER[PHP_SELF]?page=1&ipp='+this[this.selectedIndex].value+'$this->querystring';return false\">$items</select>\n";
    }
 
    function display_jump_menu()
    {
        for($i=1;$i<=$this->num_pages;$i++)
        {
            $option .= ($i==$this->current_page) ? "<option value=\"$i\" selected>$i</option>\n":"<option value=\"$i\">$i</option>\n";
        }
        return "<span class=\"paginate\">Page:</span><select class=\"paginate\" 
 
onchange=\"window.location='$_SERVER[PHP_SELF]?page='+this[this.selectedIndex].value+'&ipp=$this->items_per_page$this->querystring';return 
 
false\">$option</select>\n";
    }
 
    function display_pages()
    {
        return $this->return;
    }
}
This is my last page i'm submitting tomorrow. Please I need help!



pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: Paginate pictures, each of them with a link

Posted: Fri Jun 12, 2009 9:44 am
by icesolid
Hard to understand what you are looking for, but maybe something like this?

Code: Select all

echo "<a href='link_page_here.php'><img alt='$img_name[$i]' src='$img_path[$i]/$img_name[$i]' style='width:121px; height:101px;border:1px #C9E673 solid'></a>";

Re: Paginate pictures, each of them with a link

Posted: Mon Jun 15, 2009 8:46 am
by selom86
thanks, it works