•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 396,887 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,313 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 14406 | Replies: 22
![]() |
•
•
Join Date: Aug 2003
Location: Steamboat Springs, CO
Posts: 82
Reputation:
Rep Power: 6
Solved Threads: 0
This script will display a previous next script that will look like this:
<< prev 1 2 3 4 5 next >>
It is clean, and avoids large numbers of pages in the prev/next links
I'll definitely redo this one soon, and comment the code a little better
<< prev 1 2 3 4 5 next >>
It is clean, and avoids large numbers of pages in the prev/next links
php Syntax (Toggle Plain Text)
$server = "localhost"; $user = "username"; $pass = "password"; $databasename = "yourDBname"; $db = mysql_connect($server, $user, $pass); mysql_select_db($databasename,$db); $sql = "SELECT * FROM yourtable WHERE yourconditions ORDER BY your_order "; $query = mysql_query($sql,$db); $total_results = mysql_num_rows($query); $limit = "15"; //limit of archived results per page. $total_pages = ceil($total_results / $limit); //total number of pages if (empty($page)) { $page = "1"; //default page if none is selected } $offset = ($page - 1) * $limit; //starting number for displaying results out of DB $query = "SELECT * FROM yourtable WHERE yourconditions ORDER BY your_order LIMIT $offset, $limit"; $result = mysql_query($query); //This is the start of the normal results... while ($row = mysql_fetch_array($result)) { // display your results as you see fit here. } mysql_close(); // This is the Previous/Next Navigation echo "<font face=Verdana size=1>"; echo "Pages:($total_pages) "; // total pages if ($page != 1) { echo "<a href=$PHP_SELF?page=1><< First</a> "; // First Page Link $prevpage = $page - 1; echo " <a href=$PHP_SELF?page=$prevpage><<</a> "; // Previous Page Link } if ($page == $total_pages) { $to = $total_pages; } elseif ($page == $total_pages-1) { $to = $page+1; } elseif ($page == $total_pages-2) { $to = $page+2; } else { $to = $page+3; } if ($page == 1 || $page == 2 || $page == 3) { $from = 1; } else { $from = $page-3; } for ($i = $from; $i <= $to; $i++) { if ($i == $total_results) $to=$total_results; if ($i != $page) { echo "<a href=$PHP_SELF?showold=yes&page=$i>$i</a>"; } else { echo "<b><font face=Verdana size=2>[$i]</font></b>"; } if ($i != $total_pages) echo " "; } if ($page != $total_pages) { $nextpage = $page + 1; echo " <a href=$PHP_SELF?page=$nextpage>>></a> "; // Next Page Link echo " <a href=$PHP_SELF?page=$total_pages>Last >></a>"; // Last Page Link } echo "</font>"; // This is the end of the Previous/Next Navigation
I'll definitely redo this one soon, and comment the code a little better
Last edited by cscgal : Nov 1st, 2007 at 5:08 am. Reason: Fixed code tags
•
•
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,880
Reputation:
Rep Power: 32
Solved Threads: 108
I'm still waiting on your redo
The only reason I'm asking is because inscissor was over at my house the other day and we were talking about how he just set up something like this on a php site he was working on ... so it reminded me.
The only reason I'm asking is because inscissor was over at my house the other day and we were talking about how he just set up something like this on a php site he was working on ... so it reminded me. Dani the Computer Science Gal
Do you run a computer-related website? Feature it in our niche link directory!
Do you run a computer-related website? Feature it in our niche link directory!
•
•
Join Date: Feb 2002
Location: Long Island, NY
Posts: 1,134
Reputation:
Rep Power: 12
Solved Threads: 1
Yeah I remember this. It's a good thing that he pasted his code because I don't think one site exists that shows how to do this. Especially this clean. It's rare.
_.:: my websites ::._
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
blog @ www.samaru.net * engi No Jutsu @ www.narutorp.net * portfolio @ shinylight.com
deviantART: inscissor
•
•
Join Date: Feb 2004
Posts: 11
Reputation:
Rep Power: 5
Solved Threads: 0
hi all, first of all, thank you! this is a very nice script..
I am no coder, i basically do a little bit of php, i try
hehe
My question is, how to display the results correctly? Let me tell you the situation:
I have a table named "screenshots" with names/date of files in it and i want to "echo" the names of the files correctly. I know my english is terrible, im sorry.
heres what ive tried:
i simply want to display the 12 latest images and so on for the other pages, i only need to print the filenames correctly, can someone help me out
thanks alot for your time
fred
I am no coder, i basically do a little bit of php, i try
heheMy question is, how to display the results correctly? Let me tell you the situation:
I have a table named "screenshots" with names/date of files in it and i want to "echo" the names of the files correctly. I know my english is terrible, im sorry.
heres what ive tried:
<?php
include('config.php');
$db = mysql_connect($dbserver, $dbuser, $dbpass);
mysql_select_db($dbname,$db);
$sql = "SELECT id,big,thumb,postdate, DATE_FORMAT(postdate, '%d/%m/%Y @ %T ') AS pdate FROM screenshots ORDER BY id DESC";
$query = mysql_query($sql,$db);
$total_results = mysql_num_rows($query);
$limit = "12"; //limit of archived results per page.
$total_pages = ceil($total_results / $limit); //total number of pages
if (empty($page))
{
$page = "1"; //default page if none is selected
}
$offset = ($page - 1) * $limit; //starting number for displaying results out of DB
$query = "SELECT id,big,thumb,postdate, DATE_FORMAT(postdate, '%d/%m/%Y @ %T ') AS pdate FROM screenshots ORDER BY id DESC LIMIT $offset, $limit";
$result = mysql_query($query);
//This is the start of the normal results...
$screen_id = mysql_result($result,$row,"id");
$screen_b = mysql_result($result,$row,"big");
$screen_t = mysql_result($result,$row,"thumb");
$screen_date = mysql_result($result,$row,"pdate");
while ($row = mysql_fetch_array($result))
{
echo "$screen_t"; // display your results as you see fit here.
}
mysql_close();
***CUT***
i simply want to display the 12 latest images and so on for the other pages, i only need to print the filenames correctly, can someone help me out

thanks alot for your time
fred
•
•
Join Date: Feb 2004
Posts: 11
Reputation:
Rep Power: 5
Solved Threads: 0
***CUT***
while ($row = mysql_fetch_array($result))
{
echo "<a HREF=images/ingame/".$row['big']." TARGET=_blank><img src=images/ingame/thumbs/".$row['thumb']." border=0 alt=".$row['big']."></a> "; // display your results as you see fit here.
}
***CUT***
This code will display the pictures i want, but i have another problem
, How do i create a nice 3x4 table to display the images ? please..fred
•
•
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,880
Reputation:
Rep Power: 32
Solved Threads: 108
I don't know PHP for anything but the following is code for one row ...
So now, perhaps use code like the following? Keep in mind I'm NOT a php programmer.
<tr> <td> code for picture in row 1</td> </tr> <tr> <td> code for picture in row 2 </td> </tr>
So now, perhaps use code like the following? Keep in mind I'm NOT a php programmer.
echo "<table><tr>";
while ($row = mysql_fetch_array($result))
{
echo "<td><a HREF=images/ingame/".$row['big']." TARGET=_blank><img src=images/ingame/thumbs/".$row['thumb']." border=0 alt=".$row['big']."></a></td>"; // display your results as you see fit here.
if (($row % 3) == 0)
{ echo "</tr><tr>"; }
}
</tr></table> Dani the Computer Science Gal
Do you run a computer-related website? Feature it in our niche link directory!
Do you run a computer-related website? Feature it in our niche link directory!
•
•
Join Date: Feb 2002
Location: Lawn Guylen, NY
Posts: 10,880
Reputation:
Rep Power: 32
Solved Threads: 108
I doubt it was right. In fact, I just found an error ... I don't want to see if $row % 3 ... I want to see what we're on ... change that to $counter % 3, and directly above, add counter++; Then, above the while loop, add $counter=0; Sorry
Dani the Computer Science Gal
Do you run a computer-related website? Feature it in our niche link directory!
Do you run a computer-related website? Feature it in our niche link directory!
•
•
Join Date: Feb 2004
Posts: 11
Reputation:
Rep Power: 5
Solved Threads: 0
$counter=0;
echo "<table><tr>";
while ($row = mysql_fetch_array($result))
{
echo "<td><a HREF=images/ingame/".$row['big']." TARGET=_blank><img src=images/ingame/thumbs/".$row['thumb']." border=0 alt=".$row['big']."></a></td>"; // display your results as you see fit here.
$counter++;
if (($counter % 3) == 0){
echo "</tr><tr>";
}
}
echo "</tr></table>";
awesome!!!!!!
thanks !!!
fred
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
Similar Threads
Other Threads in the PHP Forum
- Previous Thread: Query syntax not working
- Next Thread: Want to pass a string through URL...



Linear Mode