| | |
need help with table
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Sep 2009
Posts: 22
Reputation:
Solved Threads: 0
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
PHP Syntax (Toggle Plain Text)
<?php $rows = 4; $cols = 14; mysql_connect("localhost", "Master", "password"); mysql_select_db("Ustack"); $maxCount = $rows * $cols; $construct= "SELECT * FROM Stacks Where username='Admin' LIMIT 0, {$maxCount}"; $limit = 52; $page = $_GET['page']; if($page){ $start = ($page - 1) * $limit; }else{ $start = 0; } $foundnum = mysql_num_rows(mysql_query($construct)); $construct = $construct.' LIMIT '.$start.' , '.$limit; $run = mysql_query($construct); $idList = array(); while($row = mysql_fetch_assoc($result)) { $idList[] = $row['id']; $tableOutput = ''; for($row=0; $row<$rows; $row++) { $tableOutput .= " <tr>\n"; for($col=0; $col<$cols; $col++) { $idIndex = ($row * $cols) + $col; $tableOutput .= "<td>"; $tableOutput .= (isset($idList[$idIndex]) ? $idList[$idIndex] : ' '); $tableOutput .= "</td>\n"; } $tableOutput .= " </tr>\n"; }} echo "<table border='0'> $tableOutput </table>"; // How many adjacent pages should be shown on each side? $adjacents = 3; // Your file name (the name of this file) $targetpage = "test2.php"; if ($page == 0){ $page = 1; } $prev = $page - 1; $next = $page + 1; $lastpage = ceil($foundnum/$limit); $lpm1 = $lastpage - 1; $pagination = ""; if($lastpage > 1){ $pagination .= "<div class=\"pagination\">"; // Previous if ($page > 1){ $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$prev\" style='text-decoration: none';> <strong>« previous</strong></a>"; }else{ $pagination .= "<span class=\"disabled\"> <strong>« previous</strong></span>"; } // Pages if ($lastpage < (7 + ($adjacents * 2))){ for ($counter = 1; $counter <= $lastpage; $counter++){ if ($counter == $page){ $pagination .= "<span class=\"current\"><strong> $counter</strong></span>"; }else{ $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$counter\" style='text-decoration: none';><strong> $counter</strong></a>"; } } }elseif($lastpage > (5 + ($adjacents * 2))){ if($page < 1 + ($adjacents * 2)){ for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++){ if ($counter == $page){ $pagination .= "<span class=\"current\"><strong> $counter</strong></span>"; }else{ $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$counter\" style='text-decoration: none';><strong> $counter</strong></a>"; } } } $pagination .= "..."; $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$lpm1\" style='text-decoration: none';><strong> $lpm1</strong></a>"; $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$lastpage\" style='text-decoration: none';><strong> $lastpage</strong></a>"; }elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)){ $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=1\" style='text-decoration: none';><strong> 1</strong></a>"; $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=2\" style='text-decoration: none';><strong> 2</strong></a>"; $pagination .= "..."; for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++){ if ($counter == $page){ $pagination .= "<span class=\"current\"><strong> $counter</strong></span>"; }else{ $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$counter\" style='text-decoration: none';><strong> $counter</strong></a>"; } } $pagination .= "..."; $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$lpm1\" style='text-decoration: none';><strong> $lpm1</strong></a>"; $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$lastpage\" style='text-decoration: none';><strong> $lastpage</strong></a>"; }else{ $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=1\" style='text-decoration: none';> 1</strong></a>"; $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=2\" style='text-decoration: none';> 2</strong></a>"; $pagination .= "..."; for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++){ if ($counter == $page){ $pagination .= "<span class=\"current\"><strong> $counter</strong></span>"; }else{ $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$counter\" style='text-decoration: none';><strong> $counter</strong></a>"; } } } // Next if ($page < $counter - 1){ $pagination .= "<a href=\"$targetpage?search=".$_GET['search']."&page=$next\" style='text-decoration: none';><strong> next »</strong></a>"; }else{ $pagination .= "<span class=\"disabled\"><strong> next »</strong></span>"; $pagination .= "</div>\n"; } } echo $pagination; ?>
•
•
Join Date: Aug 2009
Posts: 49
Reputation:
Solved Threads: 8
0
#12 Nov 4th, 2009
You're passing
Also, you might want to note that on line 10, your code says
Then on line 23 you concatenate this as follows:
So, you end up with a sql query that looks like this:
So you've got LIMIT twice in one query...
$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)
$construct= "SELECT * FROM Stacks Where username='Admin' LIMIT 0, {$maxCount}";
php Syntax (Toggle Plain Text)
$construct = $construct.' LIMIT '.$start.' , '.$limit;
sql Syntax (Toggle Plain Text)
SELECT * FROM Stacks WHERE username='Admin' LIMIT 0, {$maxCount} LIMIT <start's value>, 52
So you've got LIMIT twice in one query...
Last edited by EvolutionFallen; Nov 4th, 2009 at 7:59 pm.
0
#13 Nov 4th, 2009
Last edited by Airshow; Nov 4th, 2009 at 8:05 pm.
50% of the solution lies in accurately describing the problem!
![]() |
Similar Threads
- ASP PERL script table (Perl)
- I have a problem in my table (PHP)
- Display Table From MySQL DB (C#)
- Dreamweaver MX - unwanted white table space at top (Graphics and Multimedia)
Other Threads in the PHP Forum
- Previous Thread: how to set a session to destroy itself unset whatever in a certain amount of time
- Next Thread: Question about mass mail function
Views: 360 | Replies: 12
| Thread Tools | Search this Thread |
Tag cloud for PHP
.htaccess access ajax apache api array beginner binary broken cakephp checkbox class cms code cron curl database date datepart directory display download dynamic echo email error file files folder form forms function functions google href htaccess html image include insert integration ip java javascript joomla jquery limit link list login loop mail menu methods mlm mod_rewrite multiple mysql oop parse password paypal pdf php problem query radio random recursion regex remote script search select seo server sessions sms soap source space speed sql structure syntax system table tutorial update updates upload url validation validator variable video web webdesign xml youtube






