[advanced search]
Results from the most recent live auction are here.
17 members in the live chat room. Join Chat!
Register Rules & FAQ NP$ Store Active Threads Mark Forums Read
Go Back   NamePros.Com > Design and Development > Programming > CODE
User Name
Password

Old 04-04-2006, 06:35 AM   · #1
Xyzer
Steven
 
Xyzer's Avatar
 
Name: Steven Gibbons
Location: United Kindom
Trader Rating: (45)
Join Date: Aug 2005
Posts: 1,506
NP$: 40.00 (Donate)
Xyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to all
Tsunami Relief AIDS/HIV
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


Please register or log-in into NamePros to hide ads
Xyzer is offline   Reply With Quote
Old 04-04-2006, 07:50 AM   · #2
Noobie
DNOA Member
 
Noobie's Avatar
 
Name: Shoei
Location: Montreal, Quebec, Canada
Trader Rating: (0)
Join Date: Feb 2006
Posts: 324
NP$: 65.00 (Donate)
Noobie is on a distinguished road
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\">&lt;</a>&nbsp;";
}
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&nbsp;";
        } else {
     echo
"<a href=\"?id=$id&page=$i\">$i</a>&nbsp;";
        }
    }
    if(
$page < $total_pages){
    
$next = ($page + 1);
    echo
"<a href=\?id=$id&page=$next\">&gt;</a>";
}

?>
__________________
Goldkey.com is a scam
What's your BMI? | Timestamp Generator

Last edited by Noobie : 04-04-2006 at 08:10 AM.
Noobie is offline   Reply With Quote
Old 04-04-2006, 08:06 AM   · #3
Xyzer
Steven
 
Xyzer's Avatar
 
Name: Steven Gibbons
Location: United Kindom
Trader Rating: (45)
Join Date: Aug 2005
Posts: 1,506
NP$: 40.00 (Donate)
Xyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to all
Tsunami Relief AIDS/HIV
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?
Xyzer is offline   Reply With Quote
Old 04-04-2006, 08:11 AM   · #4
Noobie
DNOA Member
 
Noobie's Avatar
 
Name: Shoei
Location: Montreal, Quebec, Canada
Trader Rating: (0)
Join Date: Feb 2006
Posts: 324
NP$: 65.00 (Donate)
Noobie is on a distinguished road
I just edited it ... its a simpler way (just adding your variables like the id manually) of doing it but not the ideal way
__________________
Goldkey.com is a scam
What's your BMI? | Timestamp Generator
Noobie is offline   Reply With Quote
Old 04-04-2006, 08:22 AM   · #5
Xyzer
Steven
 
Xyzer's Avatar
 
Name: Steven Gibbons
Location: United Kindom
Trader Rating: (45)
Join Date: Aug 2005
Posts: 1,506
NP$: 40.00 (Donate)
Xyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to all
Tsunami Relief AIDS/HIV
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
Code:
$id = $row['id'];

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.
Xyzer is offline   Reply With Quote
Old 04-04-2006, 09:40 AM   · #6
Noobie
DNOA Member
 
Noobie's Avatar
 
Name: Shoei
Location: Montreal, Quebec, Canada
Trader Rating: (0)
Join Date: Feb 2006
Posts: 324
NP$: 65.00 (Donate)
Noobie is on a distinguished road
i'm confused, are you using category=photoshop or id=someid.

Either way, you can enter whatever every varaibles you want there

edit: spelling
__________________
Goldkey.com is a scam
What's your BMI? | Timestamp Generator

Last edited by Noobie : 04-04-2006 at 10:12 AM.
Noobie is offline   Reply With Quote
Old 04-04-2006, 09:42 AM   · #7
Xyzer
Steven
 
Xyzer's Avatar
 
Name: Steven Gibbons
Location: United Kindom
Trader Rating: (45)
Join Date: Aug 2005
Posts: 1,506
NP$: 40.00 (Donate)
Xyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to all
Tsunami Relief AIDS/HIV
ok, i have fixed it any for anyone else who wants to know.
Code:
$id = "photoshoptutorials";
Xyzer is offline   Reply With Quote
Old 04-04-2006, 11:38 AM   · #8
SecondVersion
while ($awake){ code(); }
 
SecondVersion's Avatar
 


Name: Eric
Location: Kentucky
Trader Rating: (137)
Join Date: Mar 2005
Posts: 4,134
NP$: 1123.00 (Donate)
SecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond reputeSecondVersion has a reputation beyond repute
Member of the Month
MOTM September 2005 Save a Life Child Abuse 9/11/01 :: Never Forget Baby Health Marrow Donor Program AIDS/HIV Breast Cancer Cystic Fibrosis Ethan Allen Fund Animal Cruelty Ethan Allen Fund Ethan Allen Fund Cancer Alzheimer's Protect Our Planet
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']);
__________________
6k.org @ Sedo auction
SecondVersion.com - The Personal Blog of SecondVersion
Domain Name Portfolio - Get your free copy. - Version 1.0.1 now available!!
MetaCreator.com - Free Meta Tag Creator

Last edited by SecondVersion : 04-04-2006 at 11:43 AM.
SecondVersion is offline   Reply With Quote
Old 04-04-2006, 12:00 PM   · #9
Noobie
DNOA Member
 
Noobie's Avatar
 
Name: Shoei
Location: Montreal, Quebec, Canada
Trader Rating: (0)
Join Date: Feb 2006
Posts: 324
NP$: 65.00 (Donate)
Noobie is on a distinguished road
yup very true, forgot the intval...
__________________
Goldkey.com is a scam
What's your BMI? | Timestamp Generator
Noobie is offline   Reply With Quote
Old 04-04-2006, 12:24 PM   · #10
Xyzer
Steven
 
Xyzer's Avatar
 
Name: Steven Gibbons
Location: United Kindom
Trader Rating: (45)
Join Date: Aug 2005
Posts: 1,506
NP$: 40.00 (Donate)
Xyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to allXyzer is a name known to all
Tsunami Relief AIDS/HIV
What does that piece of code do?
Xyzer is offline   Reply With Quote
Old 04-04-2006, 01:49 PM   · #11
Noobie
DNOA Member
 
Noobie's Avatar
 
Name: Shoei
Location: Montreal, Quebec, Canada
Trader Rating: (0)
Join Date: Feb 2006
Posts: 324
NP$: 65.00 (Donate)
Noobie is on a distinguished road
Same thing as saying
PHP Code:
if(!isset($_GET['page'])){
    
$page = 1;
}else {
    
$page  = intval($_GET['page']);
}

but alot cleaner

page = condition ? true : false;
__________________
Goldkey.com is a scam
What's your BMI? | Timestamp Generator
Noobie is offline   Reply With Quote
Closed Thread

NamePros is a revenue sharing forum.

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump


Site Sponsors
Proof is in the Parking Hunting Moon Get Your Site Linked at LinkedKeywords.com
Advertise your business at NamePros
All times are GMT -7. The time now is 01:19 AM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.4.0