Programming Theory
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesProgramming Theory

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old April 8th, 2005, 07:42 PM
LLX LLX is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Glendale, CA, USA
Posts: 1,121 LLX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 43 m 44 sec
Reputation Power: 3
Send a message via AIM to LLX Send a message via Yahoo to LLX
This seems KLUNKY

http://domestic-staffingtimes.com/Ecard/cardindex.php

I got my display system to work but the menthod i used to get there seems klunky what with having to "force" the system to run invisible fetches to set the starting point, image the grin that would put on a topic 200 items big and you viewing the last page? 150 fetches is kinda insane and id love help to stream line it.

php Code:
Original - php Code
  1.  
  2. $result = mysql_query("SELECT * FROM cards");
  3.  
  4. $page = $_GET['page'];
  5.  
  6. // if a page isn't defined, we're on page one
  7. if($page <= 0)
  8. {
  9.     $page = 1;
  10. }
  11.  
  12. // where to start depending on what page we're viewing
  13. $start = ($page * $display) - $display;
  14.  
  15. // how many lines of data to display
  16. $display = 3;
  17. $keys = mysql_num_rows($result);
  18. //determine number of pages
  19. $newspages = ($keys / $display);
  20. $realstart = ($start + 1);
  21. $finish = ($start + $display);
  22. if ($finish > $keys) {
  23.     $finish = $keys; }
  24.  
  25. //$news=mysql_fetch_assoc($result);
  26. //$row = mysql_fetch_array($result);
  27. //echo "<PRE>";
  28. //print_r ($news);
  29. //print_r ($row);
  30. //echo "</PRE>";
  31. // the actual news we're going to print
  32.  
  33. //KLUNKY way to set start point, HAS TO BE A BETTER WAY
  34. $startpoint = $page-1;
  35.  $startpoint = $startpoint * $display;
  36.  
  37. if ($page > 1){
  38. for ($i = 1; $i <=  $startpoint; $i++){
  39. $news=mysql_fetch_assoc($result);
  40. }
  41. }
  42.  
  43. echo '<table width="100%" border=1 cellpadding=4><TR>';
  44. $Counter = 0;
  45. for ($i = 1; $i <=  $display; $i++){
  46. $news=mysql_fetch_assoc($result);
  47. if ($Counter % 3 == 0){
  48. echo '</TR><TR>';
  49. }
  50. if (trim($news)){
  51. echo '<TD width=150 valign="top" align="center"><H1>ID: '.$news[ID].'</H1><BR><IMG SRC="'.$news[path].' height=150 width=150"><BR><H2>'.$news[name_card].'</H2></TD>';
  52. } else {
  53. echo '<TD width=150>&nbsp;</TD>';
  54. }
  55. $Counter++;
  56. }
  57. echo '</TR></table>';
  58.  
  59. /* old system, stil lseems superior if not perfect
  60. echo '<table width="100%" border=1 cellpadding=4><TR>';
  61. $Counter = 0;
  62. while($news=mysql_fetch_assoc($result)) {
  63. if ($Counter % 3 == 0){
  64. echo '</TR><TR>';
  65. }
  66. echo '<TD width=150 valign="top" align="center"><H1>ID: '.$news[ID].'</H1><BR><IMG SRC="'.$news[path].' height=150 width=150"><BR><H2>'.$news[name_card].'</H2></TD>';
  67. $Counter++;
  68. }
  69. while ($Counter % 3 != 0){
  70. echo '<TD width=150>&nbsp;</TD>';
  71. $Counter++;
  72. }
  73. echo '</TR></table>';
  74. */
  75.  
  76. //page display links
  77.     echo '</table><table width="100%"><TR><TD align="left" width="50%">There are <B>' . $keys . '</B> ecards available.</TD>';
  78.     echo '<TD align="right">You are on page: <b>' . $page . '</b> of <b>' . ceil($newspages) . '</b> Pages</TD></TR>';
  79.     echo '<TR> <TD colspan="2" align="left">| ';
  80. //previous link
  81. if ($page > 1){
  82. echo '<a href="'.$PHP_SELF.'?page='.($page-1).'">PREV</a> | ';
  83. }
  84. //page list
  85. if ($newspages != (int) $newspages){
  86.  
  87.     for ($pageslist = 1; $pageslist <= $newspages+1; $pageslist++){
  88.     if ($pageslist != $page){
  89.     echo '<a href="'.$PHP_SELF.'?page='.$pageslist.'">';
  90.         echo $pageslist . '</a> | ';
  91.     } else {
  92.         echo '<B>'.$pageslist . '</B> | ';
  93.     }
  94.     }
  95. } else {
  96.     for ($pageslist = 1; $pageslist <= $newspages; $pageslist++){
  97.     if ($pageslist != $page){
  98.     echo '<a href="'.$PHP_SELF.'?page='.$pageslist.'">';
  99.         echo $pageslist . '</a> | ';
  100.     } else {
  101.         echo '<B>'.$pageslist . '</B> | ';
  102.     }
  103.     }
  104. }
  105. //next link
  106. if ($page != ceil($newspages)){
  107. echo '<a href="'.$PHP_SELF.'?page='.($page+1).'">NEXT</a> |';
  108. }

Reply With Quote
  #2  
Old April 9th, 2005, 05:29 AM
spud spud is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Melbourne, Australia
Posts: 163 spud User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: This seems KLUNKY

i've probably misunderstood your question, but it sounds like you want pagination...

http://codewalkers.com/tutorials/4/1.html

have a look at that.

sorry if that wasn't at all helpful

Reply With Quote
  #3  
Old April 9th, 2005, 04:20 PM
LLX LLX is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Glendale, CA, USA
Posts: 1,121 LLX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 43 m 44 sec
Reputation Power: 3
Send a message via AIM to LLX Send a message via Yahoo to LLX
RE: This seems KLUNKY

i have pagination working the problem i s that in order to set the start point i need to do a invisible fetch of my database array and ifi its a large one that a lot of fetching

Reply With Quote
  #4  
Old April 10th, 2005, 02:42 AM
spud spud is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Location: Melbourne, Australia
Posts: 163 spud User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
RE: This seems KLUNKY

have a look at LIMITS.
i can't remember the exact syntax, but it'd be something like
php Code:
Original - php Code
  1.  
  2. $page = $_GET['page'];
  3. if($page <= 0)
  4. {
  5.     $page = 1;
  6. }
  7.  
  8. $display = 3;
  9. $start = ($page * $display) - $display;
  10.  
  11. $result = mysql_query("SELECT * FROM cards LIMIT ".$start.",".$display);

Reply With Quote
  #5  
Old April 10th, 2005, 02:06 PM
System System is offline
Codewalkers Novice (500 - 999 posts)
 
Join Date: Apr 2007
Posts: 665 System User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 2
Message Moved

Thread moved from 'PHP Coding' to 'Programming Theory' by andrew.

Reason:

Reply With Quote
  #6  
Old April 11th, 2005, 04:33 PM
LLX LLX is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Glendale, CA, USA
Posts: 1,121 LLX User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 43 m 44 sec
Reputation Power: 3
Send a message via AIM to LLX Send a message via Yahoo to LLX
RE: This seems KLUNKY

i had to modify the code a bit to fit the rules of limit

FYI its

$result = mysql_query("SELECT * FROM cards LIMIT $start, $display");

not

$result = mysql_query("SELECT * FROM cards LIMIT ".$start.", ".$display.");

http://domestic-staffingtimes.com/Ecard/cardindex.php?page=2

however the limit works to well, when you click on another page it still uses the original limits, it does see mto update the limits for the next bock of data

the second part seems to work displaying only $display values its the first part that seems to not work it seems to only start at page 1

php Code:
Original - php Code
  1.  
  2.  
  3. $page = $_GET['page'];
  4.  
  5. // if a page isn't defined, we're on page one
  6. if($page <= 0)
  7. {
  8.     $page = 1;
  9. }
  10.  
  11. // where to start depending on what page we're viewing
  12. $start = ($page * $display) - $display;
  13. // how many lines of data to display
  14. $display = 6;
  15.  
  16. $resultfull = mysql_query("SELECT * FROM cards");
  17. $result = mysql_query("SELECT * FROM cards LIMIT $start, $display");
  18. $keys = mysql_num_rows($resultfull);
  19. $newspages = ($keys / $display);
  20.  
  21. //determine number of pages
  22. $realstart = ($start + 1);
  23. $finish = ($start + $display);
  24. if ($finish > $keys) {
  25.     $finish = $keys; }
  26.  
  27. //$news=mysql_fetch_assoc($result);
  28. //$row = mysql_fetch_array($result);
  29. //echo "<PRE>";
  30. //print_r ($news);
  31. //print_r ($row);
  32. //echo "</PRE>";
  33. // the actual news we're going to print
  34.  
  35. echo '<table width="100%" border=1 cellpadding=4><TR>';
  36. $Counter = 0;
  37. while ($news=mysql_fetch_assoc($result)){
  38. if ($Counter % 3 == 0){
  39. echo '</TR><TR>';
  40. }