 |
Results from the most recent live auction are here.
19 members in the live chat room. Join Chat!
| |
04-04-2006, 06:35 AM
|
· #1 | | Steven Name: Steven Gibbons Location: United Kindom Join Date: Aug 2005
Posts: 1,506
NP$: 40.00 ( Donate)
| Pagination Hi,
I have this page: Code:
<?php
$connect = mysql_connect("localhost", "username", "password");
mysql_select_db("db", $connect);
$select = mysql_query("SELECT * FROM `tutorials` WHERE category = 'photoshop'", $connect);
while($row = mysql_fetch_array($select, MYSQL_ASSOC)) {
$id = $row['id'];
$name = $row['name'];
$email = $row['email'];
$category = $row['category'];
$url = $row['url'];
$url2 = $row['url2'];
$websitename = $row['websitename'];
$tutorialname = $row['tutorialname'];
$description = $row['description'];
echo "
<p>
<strong>Tutorial Name:</strong> <a href=\"$url2\">$tutorialname</a><br />\n
<strong>Submitted By:</strong> <a href=\"$url\">$websitename</a><br />\n
<strong>Description:</strong> $description</p>";
}
?>
I hope you all understand, and what i am trying to do is intergrate pagination, but i dont know where the script will go and how to use the Code:
$select = mysql_query("SELECT * FROM `tutorials` WHERE category = 'photoshop'", $connect);
while($row = mysql_fetch_array($select, MYSQL_ASSOC)) {
$id = $row['id'];
$name = $row['name'];
$email = $row['email'];
$category = $row['category'];
$url = $row['url'];
$url2 = $row['url2'];
$websitename = $row['websitename'];
$tutorialname = $row['tutorialname'];
$description = $row['description'];
echo "
<p>
<strong>Tutorial Name:</strong> <a href=\"$url2\">$tutorialname</a><br />\n
<strong>Submitted By:</strong> <a href=\"$url\">$websitename</a><br />\n
<strong>Description:</strong> $description</p>";
}
?>
bit which i need. Thanks
Steven |
| |
04-04-2006, 07:50 AM
|
· #2 | | DNOA Member Name: Shoei Location: Montreal, Quebec, Canada Join Date: Feb 2006
Posts: 324
NP$: 65.00 ( Donate)
| I use PEAR :: Pager now because i'm just totally in love with PEAR ... but this is how I used to do it (i got this off a tutorial a long time ago and modified it) PHP Code: $max_results = 30; //maximum entries to show per page
if(!isset($_GET['page'])){
$page = 1;
}else {
$page = $_GET['page'];
}
$sql = "SELECT * FROM `tutorials` WHERE category = 'photoshop'";
$select = mysql_query($sql, $connect);
$totalrows = mysql_num_rows($select );
$minval = (($page * $max_results) - $max_results);
$sql .= " LIMIT $minval, $max_results";
$select = mysql_query($sql, $connect);
while($row = mysql_fetch_array($select, MYSQL_ASSOC)) {
$id = $row['id'];
$name = $row['name'];
$email = $row['email'];
$category = $row['category'];
$url = $row['url'];
$url2 = $row['url2'];
$websitename = $row['websitename'];
$tutorialname = $row['tutorialname'];
$description = $row['description'];
echo "
<p>
<strong>Tutorial Name:</strong> <a href=\"$url2\">$tutorialname</a><br />\n
<strong>Submitted By:</strong> <a href=\"$url\">$websitename</a><br />\n
<strong>Description:</strong> $description</p>";
}
# pagination
$total_pages = ceil($totalrows / $max_results);
if($page > 1){
$prev = ($page - 1);
echo "<a href=\"?id=$id&page=$prev\"><</a> ";
}
for($i = 1; $i <= $total_pages; $i++){
if($i % 30 == 0) {echo "<br>\n";} // How many page numbers you want per line
if(($page) == $i){
echo "$i ";
} else {
echo "<a href=\"?id=$id&page=$i\">$i</a> ";
}
}
if($page < $total_pages){
$next = ($page + 1);
echo "<a href=\?id=$id&page=$next\">></a>";
}
?>
Last edited by Noobie : 04-04-2006 at 08:10 AM.
|
| |
04-04-2006, 08:06 AM
|
· #3 | | Steven Name: Steven Gibbons Location: United Kindom Join Date: Aug 2005
Posts: 1,506
NP$: 40.00 ( Donate)
| This displays what i want but the only problem i am having is that my site works using ?id= and when i go to page 2 it goes back to the default page and shows the url as http://www.x6core.com/?page=2
I am using the code in the post above, how can i change this? |
| |
04-04-2006, 08:11 AM
|
· #4 | | DNOA Member Name: Shoei Location: Montreal, Quebec, Canada Join Date: Feb 2006
Posts: 324
NP$: 65.00 ( Donate)
| I just edited it ... its a simpler way (just adding your variables like the id manually) of doing it but not the ideal way |
| |
04-04-2006, 08:22 AM
|
· #5 | | Steven Name: Steven Gibbons Location: United Kindom Join Date: Aug 2005
Posts: 1,506
NP$: 40.00 ( Donate)
| its still not working, if i click on next it says ?id=5&page=2, and also if i click on it and edit the code to ?id=photoshop&page=2 it still doesnt work.
I worked it out that my code already says
but if i take it out where does yours tell it what $id is?
Last edited by webmonkey : 04-04-2006 at 08:26 AM.
|
| |
04-04-2006, 09:40 AM
|
· #6 | | DNOA Member Name: Shoei Location: Montreal, Quebec, Canada Join Date: Feb 2006
Posts: 324
NP$: 65.00 ( Donate)
| i'm confused, are you using category=photoshop or id=someid.
Either way, you can enter whatever every varaibles you want there
edit: spelling
Last edited by Noobie : 04-04-2006 at 10:12 AM.
|
| |
04-04-2006, 09:42 AM
|
· #7 | | Steven Name: Steven Gibbons Location: United Kindom Join Date: Aug 2005
Posts: 1,506
NP$: 40.00 ( Donate)
| ok, i have fixed it any for anyone else who wants to know. Code:
$id = "photoshoptutorials"; |
| |
04-04-2006, 11:38 AM
|
· #8 | | while ($awake){ code(); } Name: Eric Location: Kentucky Join Date: Mar 2005
Posts: 4,134
NP$: 1123.00 ( Donate)
| Just a note PHP Code: if(!isset($_GET['page'])){
$page = 1;
}else {
$page = $_GET['page'];
}
Wouldn't recommend using that.
Try this instead PHP Code: $page = (!isset($_GET['page'])) ? 1 : intval($_GET['page']);
Last edited by SecondVersion : 04-04-2006 at 11:43 AM.
|
| |
04-04-2006, 12:00 PM
|
· #9 | | DNOA Member Name: Shoei Location: Montreal, Quebec, Canada Join Date: Feb 2006
Posts: 324
NP$: 65.00 ( Donate)
| yup very true, forgot the intval... |
| |
04-04-2006, 12:24 PM
|
· #10 | | Steven Name: Steven Gibbons Location: United Kindom Join Date: Aug 2005
Posts: 1,506
NP$: 40.00 ( Donate)
| What does that piece of code do? |
| |
04-04-2006, 01:49 PM
|
· #11 | | DNOA Member Name: Shoei Location: Montreal, Quebec, Canada Join Date: Feb 2006
Posts: 324
NP$: 65.00 ( Donate)
| Same thing as saying PHP Code: if(!isset($_GET['page'])){
$page = 1;
}else {
$page = intval($_GET['page']);
}
but alot cleaner
page = condition ? true : false; |
| |
Posting Rules
| You may not post new threads You may not post replies You may not post attachments You may not edit your posts HTML code is Off | | | |