General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 4th, 2003, 06:34 PM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
paginating help

alright, well I don't think this is what most people do but it seems like a valid solution to me. I have decided to simply pass three variables (so far), two fro looking bewteen two userids, and one for how many to add and subtract from the userids for the next and last links. My question is this: is it possible (I'm guessing using count works for this, although I am fairly unfamiliar with that still)... well is it possible to see how many users I have, and then only pass a varialbe to that point in the userids... ie, if I have 15 users, I want to be able to go through 1-10 first, and then just 11-15, and not have the next link show up... I am able to get the last link to go easily by seeing if the number is less than or equal to 1. And can I use this to make links to pages where the numbers are set, ie jump to page 1, it has nums 1-10, page 2 nums 11-20, etc. Here is the code I'm useing.

PHP Code:
<?php
if(isset($userid))
{ if(
$userid == 'all')
$pname = @mysql_query("SELECT * FROM users WHERE
userId >= '" 
$num1 "' AND userId <= '" $num2 "'");
} else {
$pname = @mysql_query("SELECT * FROM users WHERE
userId= " 
$userid "")
or die(
mysql_error());
} }

if(
$userid == 'all')
 { 
?>
<tr><td width="100%"><font size="1"><center>
<?php
if($num1 >= '1')
$lastNum1 $num1 $numa;
$lastNum2 $num2 $numa?>
<a href="index.php?page=viewprofile&userid=
<?php echo $userid?>&num1=
<?php echo $lastNum1?>&num2=
<?php echo $lastNum2?>&numa=
<?php echo $numa?>">Last</a>
<?php }
 
$nextNum1 $num1 $numa;
$nextNum2 $num2 $numa?>
<a href="index.php?page=viewprofile&userid=
<?php echo $userid?>&num1=
<?php echo $nextNum1?>&num2=
<?php echo $nextNum2?>&numa=
<?php echo $numa?>">Next</a>
</center></font></td></tr>

<?php ?>


That's all the stuff used for this problem of it. So any ideas? You guys help so mcuh thank you.
__________________
hey it's the CHARKING

Last edited by thecharking : July 4th, 2003 at 07:04 PM.

Reply With Quote
  #2  
Old July 5th, 2003, 03:26 PM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
little help? ... heh

Does anyone have any ideas? This is something I could use on numourous pages. So far it seems like a good idea. So how can I get the next link to work right, and display the number of pages along with it? BTW I did read the tutorial on pagination, but, I jsut want something simpler... it was hard to understand, so i wasn't able to change it everytime I wanted to change a few things

Reply With Quote
  #3  
Old July 9th, 2003, 12:24 AM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to avit
It's not complete, but I hope this gives you some ideas.

PHP Code:
<?php
if ( $userid == 'all' ) {

// Define your basic query
$query_in "SELECT * FROM users"

// Define how many records per page.
$perpage 10;

// Get the current page (passed in from GET in this example)
$page $_GET[page];

// Page number is checked and a range limit is applied to the query
// (See LIMIT in MySQL Docs)
if ($page 1) {
  
$limitquery $query_in " LIMIT " . ($perpage * ($page-1)) . "," $perpage;
} else {
  
$page 1;
  
$limitquery $query_in " LIMIT 0," $perpage;
}

// Define the total number of records from your basic query
// I'll leave this to you...
$num_rows count_your_records();

// Define last page, i.e. number of pages
$last ceil($num_rows/$perpage);

// Define previous page, if current page is not first
if ($page 1) {
  
$prev $page 1;
}

// Define next page, if current page is not last
if (!( ($page*$perpage) >= $num_rows )) {
  
$next $page 1;
}

// Do the query (to your limit range)
$results mysql_query($limitquery);

// end if ( $userid == 'all' )

?>


What you do with this is display the $results, then make previous & next links according to whether $next or $prev are set.

HTH.

Reply With Quote
  #4  
Old July 10th, 2003, 04:18 AM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
thank you

thanks for the help. I am still having problems though. It is working alright, except that it only displays five of my users. I have six in my db. It should show up to ten per page right? And when I click on the next link, it gives me this:

Warning: Unable to jump to row 0 on MySQL result index 38 in c:\phpdev\www\prp\jumpto.php on line 58
-- Prev -- Next

here is 55-59:

PHP Code:
 55. // Do the query (to your limit range)

56. $pname mysql_query($limitquery);

57.

58. $results2 
mysql_result($pname00);

59. 

I dont know what that means...

thank you for all your help though

oh and when you set num_rows, you let me set it up... but I set it up wrong I think, I was unsure of what to do, I used

PHP Code:
 $num_rows mysql_query("SELECT count(*) FROM users"); 


but that seems to easy.

I would post code, if you need it, but it's basically all the same as before. Any help would be greatly appreciated, and I hope I'm not missing something simple.

Last edited by thecharking : July 10th, 2003 at 04:22 AM.

Reply With Quote
  #5  
Old July 10th, 2003, 04:51 AM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to avit
Too hard to guess what's going on. The code please...

One thing that I do see is that your $num_rows is a result resource, and not an integer. You will want to get the count from the result:

PHP Code:
 $num_rows mysql_resultmysql_query('SELECT count(*) FROM users'), ); 

Last edited by avit : July 10th, 2003 at 04:58 AM.

Reply With Quote
  #6  
Old July 10th, 2003, 02:32 PM
thecharking thecharking is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Posts: 187 thecharking User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 6
Send a message via AIM to thecharking
thanks a lot

yah that was the main problem and i fixed a few other things and it works great now. you are awesome. I will be back probably when I decide to try to modify it or something, but I'm gonna screw around with this for a bit. Thanks so much!

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > paginating help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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 On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 6 hosted by Hostway
Stay green...Green IT