Results 1 to 9 of 9
Related
-
Question about SEO and Dynamic Pages Forum: Search Engine Optimization - SEO - Forum
Replies: 3 -
Split categories in half. Forum: CGI Perl Forum
Replies: 4 -
[split] PHP upload script. Forum: PHP Forum
Replies: 3
-
04-23-2003, 07:16 PM #1
How to split up dynamic results in multiple pages?
Hi,
Before posting this message I have read about 200 pages with information but I am stuck, so I thought to ask the pro guys around if they had any solution to my problem.
Current situation:
I have a website with 10000+ pictures divided in 5 categories.
Each category has 1 page which uses echo to show all images in a specific directory.
Ofcourse, all images are being displayed on 1 pagenow I have over 400 images on 1 page and that eats my bandwith... O, I am not using a database!
What do I want then:
I want the current situation kept, but with maximum 20 images per page and a <previous 1/2/3...next> navigation bar.
Here is the code I use:
function stats() {
global $titulo,$titulo2,$titulo3,$cstats2,$imagen,$bytes,$fotos,$filas,$cnombres1,$dir,$dir2,$dir3,$dir4;
$kb = number_format($bytes/1024);
echo "<table cellspacing=0 cellpadding=4 width=100%>";
echo "<tr><td align=center width=100% bgcolor=$cstats2 class=titulo>$titulo</td></tr>";
echo "<table width=100% cellpadding=2 cellspacing=2><tr>";
$trow = 1;
array_multisort($fotos["modi"],SORT_DESC,$fotos["nombre"]);
reset($fotos);
while (list($key) = each($fotos["nombre"])) {
echo "<td class=nombre align=center bgcolor=$cnombres1 onmouseover=\"mOver(this);return true\" onmouseout=\"mOut(this);return true\" onclick=\"mClick(this);\"><a href=\"javascript:showFotoset('".$dir2.substr($fotos["nombre"][$key],0,-4).$dir4."')\"><img height=200 src=".$dir.$fotos["nombre"][$key]." border=1></a></td>";
if ($trow >= $filas) { echo "</tr><tr>"; $trow=1; } else { $trow++; }
}
echo "</tr>";
echo "</table></table>";
echo "<table><tr ><td align=center width=100% bgcolor=$cstats2 class=titulo><font face=Verdana, Arial, Helvetica, sans-serif size=2>$titulo2</font></td></tr></table>";
}
where $dir is the variable i've used to point to the image directory.
Anyone who could help me with a working version?
-
04-23-2003, 07:34 PM #2
Here is a tutorial on pagination http://www.phpfreaks.com/tutorials/43/0.php on the last page of the tutorials you will see a small forum area at the bottom which pertainsto the pagination tutorial, if you have problems be sure to read the posts they may be of help. If you are still stuck I can try to help you here, having just recently done this to our hosting directory and the PHP Scripts directory last month.
Dave
-
04-23-2003, 08:06 PM #3
Here is a tutorial on pagination http://www.phpfreaks.com/tutorials/43/0.php on the last page of the tutorials you will see a small forum area at the bottom which pertainsto the pagination tutorial, if you have problems be sure to read the posts they may be of help. If you are still stuck I can try to help you here, having just recently done this to our hosting directory and the PHP Scripts directory last month.
Dave
-
04-24-2003, 07:37 AM #4
Thanks dave for the link, I have checked it out and this is where I am so far:
the problem is I am not using a database and I do not want to with the load of images I already have.
I am however expereminting with what i have, I've found a way to count the total number of images and put a navigation bar with page numbering.
BUT
all images are still displayed on 1 page, they are not divided up into 20 pics per page
Here's what i do for the navigation:
function total() {
$files_directory = "thumbs";
$new_array = array();
$files = array();
$fdirectory = opendir( "$files_directory" );
while ($file = readdir( $fdirectory ) ) {
if ( ( $file == "." ) || ( $file == ".." ) ) {
} else {
array_push( $files, $file );
}
}
$count = count( $files );
echo "$count"; // displays total number of images
$limit = 20;
if(empty($page)) // Checks if the $page variable is empty (not set)
$page = 1; // If it is empty, we're on page 1
$limitvalue = $page * $limit - ($limit);
if($page != 1){
$pageprev = $page--;
// Fancy way of subtracting 1 from $page
echo("<a href=\"index.php&page=$pageprev\">PREV</a> ");
}else
echo("PREV ");
// If we're on page 1, PREV is not a link
$numofpages = $count / $limit;
for($i = 1; $i <= $numofpages; $i++){
if($i == $page)
echo($i." ");
else
echo("<a href=\"index.php&page=$i\">$i</a> ");
} // This ends the for loop
if(($count % $limit) != 0){
if($i == $page)
echo($i." ");
else
echo("<a href=\"index.php&page=$i\">$i</a> ");
}
if(($count - ($limit * $page)) > 0){
$pagenext = $page++;
echo("<a href=\"index.php&page=$pageprev\">NEXT</a>");
}else
echo(" NEXT ".$limit);
clearstatcache();
}
Now i have to integrate it with the code in my first post so also the images will be per 20, and that index.php?page=2 will not give me a 404
Wow, PHP is heavy for a newbie 8-)
-
04-24-2003, 12:05 PM #5
Hiya.
because you are not using a database, it means we have to move the 'limiting' of results away from the sql query and into the php.
best way I can think of is to let the script loop thru every script, but only to display it if the count is between a certain range.
this would probably be best achieved with a counting variable and a for loop. eg
PHP Code:$i = 1;
// Looping code you already have, but with an $i++ increment WITHIN the loop
if ($i > $start && $i < $end) {
// Echoing code
}
Clear? If not , post away.If one of our members helps you, please click theicon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?
-
04-24-2003, 07:25 PM #6
Aha, eu ,
nope, cannot work with it (yet)...
I have been thinking, if you look at the code in my 1st post, you see that I limit the number of table colums with:
if ($trow >= $filas) { echo "</tr><tr>"; $trow=1; } else { $trow++; }
where $filas has a value of 4, so the page will show all pictures in a table with 4 colums and as many rows as it needs.
Well, if I know that the total amount of pictures i want to show on 1 page is 20, can't I also say when 5 rows are reached, cut page, put a navigation below?
Just trying...
Another thing that could work is using array_slice according to PHP.net but there are to few examples for me to fully understand this function... will be reading more, meanwhile, all comments are welcome
-
04-25-2003, 01:53 PM #7
i dont know anything about php, so please ignore this post if it's irrelavent. how bout using querystrings?
pass on the value of the page, then use the page number to find out what images need to be displayed.
for instance, if u want 20 images per page, then if u pass on the value of the page to be viewed, i.e. page 3, then u can calculate that images 41-60 need to be displayed.
firstImage = ((pageno-1) * 20) + 1
lastImage = firstImage + 19
then just loop through the images
this is assuming you've named all images = image1.jpg, image2.gif...
if not u can put all the file names into an array, and loop through it and take out array item number 41-60, only displaying the needed images
total pages to be displayed = (number of files in array / 20) + 1
if u want your page to display 10 pages at a time, then that takes more work
hope that helps
(i'm an asp programmer, so this might not apply to php)
-
07-11-2003, 08:19 AM #8
Well, I finally decided to switch to a database, much more effecient and flexible
Thanks for all responses!
-
07-11-2003, 11:54 AM #9
Excellent. DB's are the way to go
If one of our members helps you, please click theicon to add to their reputation!
No support via email or private message - use the forums!
Before you ask, have you Searched?
Cloudjiffy- PaaS for Developers
10-05-2020, 12:30 AM in Web Hosting Forum