Jump to content

Recommended Posts

Hi, I'm using the pagination script 'as easy as prev 1 2 3 next' and I was wondering how I would create some code after each 3 entries are shown?

 

i'm just concerned on this part:

    while($row = mysql_fetch_array($result)){

    echo "\t\t\t\t\t\t\t\t\t<td class=\"thumbnail\"><a target=\"_top\" href=\"$site_url/gallery/photo.php?id={$row['uphotoid']}\"><img src=\"$site_url/gallery/albums/{$row['photoname']}.jpg\"></a></td>\n";
    }

 

I want it to show </tr><tr> after every 3 records. can someone help me on this?

 

here's the full pagination code, if you notice any bugs with other stuff, I'll sort it out later, i'm rather tired right now so I'm not doing it till tomorrow lol but if someone could help me with this problem.

 

// Address error handing.
ini_set ('display_errors', 1);
error_reporting (E_ALL & ~E_NOTICE);

// get connection and database information
require_once('../admin/sql/mysql_connect.php');

    $limit          = 9;
    $query_count    = "SELECT count(*) FROM gallery_albums";
    $result_count   = mysql_query($query_count);    
    $totalrows      = mysql_result($result_count,0);
    $page = $_GET['page'];

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

    $limitvalue = $page * $limit - ($limit);
    $query  = "SELECT * FROM gallery_albums WHERE album_name='{$_GET['album_name']}' ORDER BY upicid ASC LIMIT $limitvalue, $limit";
    $result = mysql_query($query) or die("Error: " . mysql_error());

    echo "\t\t\t\t\t\t<div class=\"news-box\">\n\t\t\t\t\t\t\t<div class=\"news-title\">\n\t\t\t\t\t\t\t\t:: Member List\n\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t<div class=\"news-article\">\n";
    echo "\t\t\t\t\t\t\t<table cellspacing=\"0\" cellpadding=\"2\" border=\"0\" width=\"100%\">\n";

    while($row = mysql_fetch_array($result)){

/*

I want to add a </tr><tr> after every 3 records shown.

like this:
    echo "\t\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t\t<tr>\n";

*/

    echo "\t\t\t\t\t\t\t\t\t<td class=\"thumbnail\"><a target=\"_top\" href=\"$site_url/gallery/photo.php?id={$row['uphotoid']}\"><img src=\"$site_url/gallery/albums/{$row['photoname']}.jpg\"></a></td>\n";
    }
    echo "\t\t\t\t\t\t\t</table>\n";

    echo "\t\t\t\t\t\t</div>\n\t\t\t\t\t</div>\n";
    echo ("\t\t\t\t\t<div id=\"prevnext\">\n");

    if($page != 1){
        $pageprev = $page-1;

        echo("\t\t\t\t\t\t<a class=\"pn-nav\" href=\"$PHP_SELF?view=all&page=$pageprev\"> « Prev </a>");
    }else{
        echo("\t\t\t\t\t\t<span class=\"pn-nav2\"> « Prev </span>");
    }

    $numofpages = $totalrows / $limit;

    for($i = 1; $i <= $numofpages; $i++){
        if($i == $page){
            echo("<span class=\"pn-nav\"> ".$i." </span>");
        }else{
            echo("<a class=\"pn-nav\" href=\"$PHP_SELF?view=all&page=$i\"> $i </a>");
        }
    }

    if(($totalrows % $limit) != 0){
        if($i == $page){
            echo("<span class=\"pn-nav\">".$i."</span>");
        }else{
            echo("<a class=\"pn-nav\" href=\"$PHP_SELF?view=all&page=$i\"> $i </a>");
        }
    }

    if(($totalrows - ($limit * $page)) > 0){
        $pagenext = $page+1;
        echo("<a class=\"pn-nav\" href=\"$PHP_SELF?view=all&page=$pagenext\"> Next » </a>\n");
    }else{
        echo("<span class=\"pn-nav2\"> Next » </span>\n");  
    }
    echo ("\t\t\t\t\t</div>\n");


    mysql_free_result($result);

mysql_close(); // Close the database connection.

 

 

thanks in advance.

 

--

TJ

Link to comment
https://forums.phpfreaks.com/topic/3051-trying-to-create-thumbnail-view-gallery/
Share on other sites

$i = 0;
while($row = mysql_fetch_array($result))
{
    if($i%3==0 && $i>0) echo "\t\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t\t<tr>\n";

    echo "\t\t\t\t\t\t\t\t\t<td class=\"thumbnail\"><a target=\"_top\" href=\"$site_url/gallery/photo.php?id={$row['uphotoid']}\"><img src=\"$site_url/gallery/albums/{$row['photoname']}.jpg\"></a></td>\n";

    $i++; // remember this
}

[!--quoteo(post=327507:date=Dec 14 2005, 07:59 PM:name=ryanlwh)--][div class=\'quotetop\']QUOTE(ryanlwh @ Dec 14 2005, 07:59 PM) 327507[/snapback][/div][div class=\'quotemain\'][!--quotec--]

$i = 0;
while($row = mysql_fetch_array($result))
{
    if($i%3==0 && $i>0) echo "\t\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t\t<tr>\n";

    echo "\t\t\t\t\t\t\t\t\t<td class=\"thumbnail\"><a target=\"_top\" href=\"$site_url/gallery/photo.php?id={$row['uphotoid']}\"><img src=\"$site_url/gallery/albums/{$row['photoname']}.jpg\"></a></td>\n";

    $i++; // remember this
}

 

wow, fast reply, thanks alot :) will try it out when I get up in the morning. will let you know how I get on.

 

thanks.

 

TJ.

 

$cnt =0;

 

while(....){

if ($cnt % 4 == 0 || $cnt ==0)

echo "\t\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t\t<tr>\n";

.

.

.

$cnt++;

}

 

 
$cnt =1;

while(....){
   if ($cnt % 4 == 0 || $cnt ==0)
      echo "\t\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t\t<tr>\n";
.
.
.
   $cnt++;
}

 

$cnt =1;

while(....){
   if ($cnt % 4 == 0 || $cnt ==1)
      echo "\t\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t\t<tr>\n";
.
.
.
   $cnt++;
}

*** edit at bottom ***

 

at present the code you supplied only shows 1 thumbnail, which I know why, (but not sure how to make it work) cos it looks like it needs a loop (i noticed it seems to be a simular way as my old thumbnail script that a friend made for me, but it doesn't have pagination, it just displays all the results, seperating them into rows of three.)

 

Old thumbnail script

function padNumber($number)
    {
        if (strlen($number) == '1')
    {
        $number = "00$number";
    }
    else if (strlen($number) == '2')
    {
        $number = "0$number";
    }

    return $number;
}

    for($i = 1; $i < $pic_number; $i++)
    {
        echo "\n\t\t\t\t\t\t\t\t<td>\n\t\t\t\t\t\t\t\t\t<a target=\"_new\" href=\"$pic_url", padNumber($i), ".jpg\">\n\t\t\t\t\t\t\t\t\t\t<img src=\"$pic_url/thumbs/", padNumber($i), ".jpg\" ALT=\"", padNumber($i), ".jpg\" border=\"0\">\n\t\t\t\t\t\t\t\t\t</a>\n\t\t\t\t\t\t\t\t</td>\n";

        if ($i % 3 == 0)
        {
            echo "\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t<tr>";
        }
    }

 

so I believe I need to edit it so that I put this part of the code...

 

    for($i = 1; $i < $pic_number; $i++)
    {

    }

 

together with this code... ( I changed $i = 0 to $i = 1 as it was starting at 0 and not 1 (same thing with old script)

 

    $i = 1; 
    while($row = mysql_fetch_array($result))
    {
        if($i%3==0 && $i>0) echo "\t\t\t\t\t\t\t\t</tr>\t\t\t\t\t\t\t\t<tr>\n";

            echo "\t\t\t\t\t\t\t\t\t<td class=\"thumbnail\"><a target=\"_top\" href=\"$site_url/gallery/photo.php?id=", padNumber($i), "\"><img src=\"$site_url/gallery/albums/{$row['album_name']}/thumbs/", padNumber($i), ".jpg\"></a></td>\n";

        $i++; // remember this
    }

 

so how would I go about editing this so that it will work? it seems to be that this is the only thing I need to do before my script is complete :D (although pagination was only showing 1 page instead of 2, (i created a test record with 12 results, divided by 3, seperated into 9, 18, 27, 36 etc)

 

thanks in advance.

 

*** EDIT ***

 

Ok so I think I know what's causing my pagination problem, it's not able to count how many pics, (which I want it to select the gallery's table field of 'number' which has the number of photos there is in the album.

 

but i'm not sure how I would change the code to display it.

 

    $limit          = 9;
    $query_count    = "SELECT COUNT(number) FROM gallery WHERE album_name='{$_GET['a']}'";
    $result_count   = mysql_query($query_count);
    $totalrows      = mysql_result($result_count,0);

 

i figured out that it was wrong by changing $totalrows to

//    $totalrows      = 12;

which then showed up 2 pages at the bottom. basicly I want it to use the number in field 'number' WHERE album_name='{$_GET['a']}, i did try doing something like that but it didn't work.

 

but I also still need a loop in the code before the edit to make them display properly and also a solution to the code below the edit.

anyone able to help me fix this? :) I need a way of getting mysql to read the table 'gallery' and get the info from the column called 'number' where 'album_name' etc, but couldn't seem to get it to work, any ideas?

 

also I need to do a loop through the number of photos

 

--

TJ

ok, so I managed to solve the 'number' problem and the looping problem, but now i'm having a problem with the limiting, although codewise it is as it should be, it's not limiting how many it shows on the browser, so if anyone can help me it would be good.

 

here's a link to show you what it's doing... [a href=\"http://www.tjhilder.co.uk/2-1/gallery/small.php?a=test\" target=\"_blank\"]thumbnail view gallery php file[/a]

 

here's a link to the source code (was quite large so figured it would be better to create a txt file with it instead.)

[a href=\"http://www.tjhilder.co.uk/2-1/gallery/small.txt\" target=\"_blank\"]thumbnail view gallery text file[/a]

 

query: SELECT * FROM gallery WHERE album_name='test' LIMIT 0, 9

 

hope someone can help.

not sure what that is meant to do.

 

the problem is with this code:

    $pic = 1;
    while($row = mysql_fetch_array($result))
    {
        for($num = 1; $num < $totalrows; $num++)
        {
            echo "\t\t\t\t\t\t\t\t\t<td class=\"thumbnail\"><a target=\"_top\" href=\"$site_url/gallery/large.php?a={$row['album_name']}&id=", padNumber($pic), "\"><img src=\"$site_url/gallery/albums/{$row['album_name']}/thumbs/", padNumber($pic), ".jpg\"></a></td>\n";
            if ($num % 3 == 0 && $num > 0)
                {
                  echo "\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr>\n";
                }
            $pic++; // remember this
        }
    }

 

it's reading $totalrows, (which is for instance 12 results) but it isn't splitting it into pages. but i'm not sure how to correct this or whether it can be corrected.

 

[a href=\"http://www.tjhilder.co.uk/2-1/gallery/small2.txt\" target=\"_blank\"]updated txt file of source code.[/a]

Ok so I tried using $lmit instead of $totalrows, it brought up 8 results (cos I need it to be $limit+1 to make 9)

 

interesting result, it does show up how many you want on the first page, but still doesn't show anything up on the 2nd or 3rd page, so this idea lead me into an idea of doing this... (I did $num == $num because taking it out wouldn't work, but $num = $num worked, if you know a better way then let me know.)

 

    if ($_GET['p'] == "1" or $_GET['p'] == '') {
        $pic = 1;
        $num = 1;
        $numlimit = 9;
    } elseif ($_GET['p'] == "2") {
        $pic = 10;
        $num = 10;
        $numlimit = 18;
    } elseif ($_GET['p'] == "3") {
        $pic = 19;
        $num = 19;
        $numlimit = 27;
    }
    while($row = mysql_fetch_array($result))
    {
        for($num = $num; $num < $numlimit; $num++)
        {
            echo "\t\t\t\t\t\t\t\t\t<td class=\"thumbnail\"><a class=\"noborder\" target=\"_top\" href=\"$site_url/gallery/large.php?a={$row['album_name']}&id=", padNumber($pic), "\"><img src=\"$site_url/gallery/albums/{$row['album_name']}/thumbs/", padNumber($pic), ".jpg\"></a></td>\n";
            if ($num % 3 == 0 && $num > 0)
                {
                    echo "\t\t\t\t\t\t\t\t</tr>\n\t\t\t\t\t\t\t\t<tr>\n";
                }
            $pic++; // remember this
        }
    }

 

but it still doesn't bring up anything on page 2 or 3, just 1. so it made me think about doing it it's own query, like this: (because it has the $limit in the query, it was limiting it to show 9, so taking away 10 - 18, 19 - 27 etc)

 

    $query2 = "SELECT * FROM gallery WHERE album_name='{$_GET['a']}'";
    $result2 = mysql_query($query2) or die("Error: " . mysql_error());

and later on...

changing     while($row = mysql_fetch_array($result))

to $result2

which brought up showing them on page 2 and 3 and so on as you can see here.

[a href=\"http://www.tjhilder.co.uk/2-1/gallery/small.php?a=rabbit05&p=2\" target=\"_blank\"]page 2[/a] and [a href=\"http://www.tjhilder.co.uk/2-1/gallery/small.php?a=rabbit05&p=3\" target=\"_blank\"]page 3[/a]

 

But still have a problem, now I don't have a $limit.

 

suggestion? and if you have a suggestion on how this can be improved so that its less code then that would be great.

 

[a href=\"http://www.tjhilder.co.uk/2-1/gallery/small3.txt\" target=\"_blank\"]gallery source code text file UPDATED[/a]

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '-9, 9' at line 1

 

I also got this error with mysql_fetch_rows() being an undefined function.

 

had to change it to

    $query = "SELECT * FROM gallery WHERE album_name='{$_GET['a']}' LIMIT ".(($p-1)*9).", $limit";

 

then it worked with the first page, but that was it.

 

changed it back to the way it was in [a href=\"http://www.tjhilder.co.uk/2-1/gallery/small3.txt\" target=\"_blank\"]this text [/a]file

*** edit at bottom ***

 

i don't think that will work, seeing as it's not counting how many rows there are because it's based on one mysql row, which has all the details like, album_name, number etc

 

I need to create something that calculates itself by what the $_GET['p'] is. I kinda started the ball rolling with a script i've been working on for the last few hours.

 

that calculates itself by what the ?p= is, this is what it looks like in action --> (a test btw) [a href=\"http://www.tjhilder.co.uk/2-1/gallery/test.php\" target=\"_blank\"]click me[/a] and this is what it looks like in the source code. [a href=\"http://www.tjhilder.co.uk/2-1/gallery/test.txt\" target=\"_blank\"]click me[/a]. ?p=1 and ?p=2 are working fine, but for some strange reason 3 & 4 don't show up any information but $pic_total.

 

maybe you'll have some idea on what I need to do.

 

*** EDIT ***

 

ok I managed to solve some things, now p=1 and p=3 works the way they should be. (22 results = 3 pages, page 3 ends with the $f_num being 22 (i really can't see how i'm figuring all this out.) but I think there is just one thing I'm missing and thats in this line:

 

} elseif ($_GET['p'] <= $numofpages) {
if ($pic_total == ($limit+1 <= $pic_total)) {

 

but p=2 doesn't, should be showing info, but it's not. so if someone could help me with this.

 

here's the full code on a text file. [a href=\"http://www.tjhilder.co.uk/2-1/gallery/test2.txt\" target=\"_blank\"]click me[/a]

Maybe I don't understand what all the fuss in about -- that and I can't get to the pix page. You add a LIMIT M,N clause to your SQL query. The "M" is the start value of the current listing, and the N is page limit (i.e. 3 per page). You pass M to your script -- so for the first page, it would be "LIMIT 0, 3". In your PHP code, your script your page links as (x-1*N), so that the link for page 1 has M=0, page 2 has M=3, etc. Previous/next links are similar. Obviously, you have to include boundary checks, but otherwise, I'm not sure what the complication is.

this link will work:

[a href=\"http://www.tjhilder.co.uk/2-1/gallery/small.php?a=rabbit05&p=1\" target=\"_blank\"]link to small.php[/a]

and this next link is for the txt file of the code:

[a href=\"http://www.tjhilder.co.uk/2-1/gallery/small.txt\" target=\"_blank\"]link to small.txt[/a]

 

I think I know what you're saying, do you mean use the same M and N in the for() statement? I was trying something like that the other day but must not have had it right cos it brought up errors.

 

is it possible that you could edit the code relivant of my script to how you're saying it should be?

 

thanks in advance.

I don't have the time to edit the code, and I can't get to your link without registering. There appear to be two issues here: first, creating a new table row every N pictures, and second, generating the appropriate pagination links. I don't know which you're refering to -- I was taking about the latter.

[!--quoteo(post=330074:date=Dec 23 2005, 11:34 PM:name=fenway)--][div class=\'quotetop\']QUOTE(fenway @ Dec 23 2005, 11:34 PM) 330074[/snapback][/div][div class=\'quotemain\'][!--quotec--]

and I can't get to your link without registering.

 

sorry about that, forgot to comment out the code that makes you have to register.

 

should work for you now. --> [a href=\"http://www.tjhilder.co.uk/2-1/gallery/small.php\" target=\"_blank\"]click me[/a]

 

the pagination works fine, it's just it's not using the mysql limiting properly when actually showing the thumbnails themselves.

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.