944,173 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Unsolved
  • Views: 820
  • PHP RSS
You are currently viewing page 2 of this multi-page discussion thread; Jump to the first page
Nov 4th, 2009
0
Re: need help with table
ok i've got it working.. can you help me get my pagination working along with it.. i get the Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/ustackc1/public_html/test2.php on line 30


PHP Syntax (Toggle Plain Text)
  1. <?php
  2.  
  3. $rows = 4;
  4. $cols = 14;
  5.  
  6. mysql_connect("localhost", "Master", "password");
  7. mysql_select_db("Ustack");
  8.  
  9. $maxCount = $rows * $cols;
  10. $construct= "SELECT * FROM Stacks Where username='Admin' LIMIT 0, {$maxCount}";
  11.  
  12. $limit = 52;
  13. $page = $_GET['page'];
  14.  
  15. if($page){
  16. $start = ($page - 1) * $limit;
  17. }else{
  18. $start = 0;
  19. }
  20.  
  21.  
  22. $foundnum = mysql_num_rows(mysql_query($construct));
  23. $construct = $construct.' LIMIT '.$start.' , '.$limit;
  24. $run = mysql_query($construct);
  25.  
  26. $idList = array();
  27.  
  28. while($row = mysql_fetch_assoc($result))
  29. {
  30. $idList[] = $row['id'];
  31.  
  32.  
  33.  
  34. $tableOutput = '';
  35.  
  36. for($row=0; $row<$rows; $row++)
  37. {
  38. $tableOutput .= " <tr>\n";
  39. for($col=0; $col<$cols; $col++)
  40. {
  41. $idIndex = ($row * $cols) + $col;
  42.  
  43. $tableOutput .= "<td>";
  44. $tableOutput .= (isset($idList[$idIndex]) ? $idList[$idIndex] : '&nbsp;');
  45. $tableOutput .= "</td>\n";
  46. }
  47. $tableOutput .= " </tr>\n";
  48. }}
  49. echo "<table border='0'>
  50. $tableOutput
  51. </table>";
  52. // How many adjacent pages should be shown on each side?
  53. $adjacents = 3;
  54.  
  55. // Your file name (the name of this file)
  56. $targetpage = "test2.php";
  57.  
  58. if ($page == 0){
  59. $page = 1;
  60. }
  61.  
  62. $prev = $page - 1;
  63.  
  64. $next = $page + 1;
  65.  
  66. $lastpage = ceil($foundnum/$limit);
  67.  
  68. $lpm1 = $lastpage - 1;
  69.  
  70. $pagination = "";
  71. if($lastpage > 1){
  72. $pagination .= "<div class=\"pagination\">";
  73. // Previous
  74. if ($page > 1){
  75. $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$prev\" style='text-decoration: none';> <strong>&laquo; previous</strong></a>";
  76. }else{
  77. $pagination .= "<span class=\"disabled\"> <strong>&laquo; previous</strong></span>";
  78. }
  79.  
  80. // Pages
  81.  
  82. if ($lastpage < (7 + ($adjacents * 2))){
  83. for ($counter = 1; $counter <= $lastpage; $counter++){
  84. if ($counter == $page){
  85. $pagination .= "<span class=\"current\"><strong> $counter</strong></span>";
  86. }else{
  87. $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$counter\" style='text-decoration: none';><strong> $counter</strong></a>";
  88. }
  89. }
  90. }elseif($lastpage > (5 + ($adjacents * 2))){
  91. if($page < 1 + ($adjacents * 2)){
  92. for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++){
  93. if ($counter == $page){
  94. $pagination .= "<span class=\"current\"><strong> $counter</strong></span>";
  95. }else{
  96. $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$counter\" style='text-decoration: none';><strong> $counter</strong></a>";
  97. }
  98. }
  99. }
  100.  
  101. $pagination .= "...";
  102. $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$lpm1\" style='text-decoration: none';><strong> $lpm1</strong></a>";
  103. $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$lastpage\" style='text-decoration: none';><strong> $lastpage</strong></a>";
  104. }elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)){
  105. $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=1\" style='text-decoration: none';><strong> 1</strong></a>";
  106. $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=2\" style='text-decoration: none';><strong> 2</strong></a>";
  107. $pagination .= "...";
  108.  
  109. for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++){
  110. if ($counter == $page){
  111. $pagination .= "<span class=\"current\"><strong> $counter</strong></span>";
  112. }else{
  113. $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$counter\" style='text-decoration: none';><strong> $counter</strong></a>";
  114. }
  115. }
  116. $pagination .= "...";
  117. $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$lpm1\" style='text-decoration: none';><strong> $lpm1</strong></a>";
  118. $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$lastpage\" style='text-decoration: none';><strong> $lastpage</strong></a>";
  119. }else{
  120. $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=1\" style='text-decoration: none';> 1</strong></a>";
  121. $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=2\" style='text-decoration: none';> 2</strong></a>";
  122. $pagination .= "...";
  123.  
  124. for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++){
  125. if ($counter == $page){
  126. $pagination .= "<span class=\"current\"><strong> $counter</strong></span>";
  127. }else{
  128. $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$counter\" style='text-decoration: none';><strong> $counter</strong></a>";
  129. }
  130. }
  131. }
  132.  
  133. // Next
  134. if ($page < $counter - 1){
  135. $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$next\" style='text-decoration: none';><strong> next &raquo;</strong></a>";
  136. }else{
  137. $pagination .= "<span class=\"disabled\"><strong> next &raquo;</strong></span>";
  138. $pagination .= "</div>\n";
  139. }
  140. }
  141. echo $pagination;
  142.  
  143.  
  144.  
  145.  
  146.  
  147.  
  148.  
  149.  
  150. ?>
Reputation Points: 10
Solved Threads: 0
Junior Poster
MDanz is offline Offline
146 posts
since Sep 2009
Nov 4th, 2009
0
Re: need help with table
You're passing $result to mysql_fetch_assoc() . You should be passing $run to it instead.

Also, you might want to note that on line 10, your code says
php Syntax (Toggle Plain Text)
  1. $construct= "SELECT * FROM Stacks Where username='Admin' LIMIT 0, {$maxCount}";
Then on line 23 you concatenate this as follows:
php Syntax (Toggle Plain Text)
  1. $construct = $construct.' LIMIT '.$start.' , '.$limit;
So, you end up with a sql query that looks like this:
sql Syntax (Toggle Plain Text)
  1. SELECT * FROM Stacks WHERE username='Admin' LIMIT 0, {$maxCount} LIMIT <start's value>, 52
  2.  

So you've got LIMIT twice in one query...
Last edited by EvolutionFallen; Nov 4th, 2009 at 7:59 pm.
Reputation Points: 40
Solved Threads: 31
Junior Poster
EvolutionFallen is offline Offline
198 posts
since Aug 2009
Nov 4th, 2009
0
Re: need help with table
I thought I'd mention it in case the OP didn't know it was an option, since PHP certainly cannot do what he/she is asking for =)
Evo, we are clearly of one mind here.

Airshow
Last edited by Airshow; Nov 4th, 2009 at 8:05 pm.
Sponsor
Reputation Points: 318
Solved Threads: 358
WiFi Lounge Lizard
Airshow is offline Offline
2,527 posts
since Apr 2009

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: how to set a session to destroy itself unset whatever in a certain amount of time
Next Thread in PHP Forum Timeline: Question about mass mail function





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC