need help with table

Reply

Join Date: Sep 2009
Posts: 22
Reputation: MDanz is an unknown quantity at this point 
Solved Threads: 0
MDanz MDanz is offline Offline
Newbie Poster
 
0
  #11
Nov 4th, 2009
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


  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. ?>
Reply With Quote Quick reply to this message  
Join Date: Aug 2009
Posts: 49
Reputation: EvolutionFallen is an unknown quantity at this point 
Solved Threads: 8
EvolutionFallen EvolutionFallen is offline Offline
Light Poster
 
0
  #12
Nov 4th, 2009
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
  1. $construct= "SELECT * FROM Stacks Where username='Admin' LIMIT 0, {$maxCount}";
Then on line 23 you concatenate this as follows:
  1. $construct = $construct.' LIMIT '.$start.' , '.$limit;
So, you end up with a sql query that looks like this:
  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.
Reply With Quote Quick reply to this message  
Join Date: Apr 2009
Posts: 885
Reputation: Airshow will become famous soon enough Airshow will become famous soon enough 
Solved Threads: 127
Airshow's Avatar
Airshow Airshow is offline Offline
Practically a Posting Shark
 
0
  #13
Nov 4th, 2009
Originally Posted by EvolutionFallen View Post
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.
50% of the solution lies in accurately describing the problem!
Reply With Quote Quick reply to this message  
Reply

Message:




Views: 360 | Replies: 12
Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC