Paging in php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
exutable
Forum Newbie
Posts: 5
Joined: Wed Feb 16, 2005 7:35 pm

Paging in php

Post by exutable »

Warning: extract(): First argument should be an array in /customers/daneshea.com/daneshea.com/httpd.www/functions.php on line 31


This is what I get from the paging script why doesn't it work?

Code: Select all

if(!$show_from || $show_from < 0) &#123;
$show_from = 0;
&#125;

$pr_page = 20;

$sql = "select ip, id, name, email, message, date_format(time, '%a, %H:%i, %c/%e/%Y') as thetime from tagwall order by time desc limit $show_from, $pr_page";

$result = mysql_query($sql);

$count_amount = "select count(*) as amount from tagwall";

$tag_amount&#1111;] = mysql_query($count_amount);

extract($tag_amount&#1111;0]);

if($amount > ($show_from + $pr_page)) &#123;

	$next_show_from = $show_from + $pr_page;
	$next_nav = "<a href="/tagwall.php?show_from=$next_show_from">Next</a>";

&#125;
else &#123;

$next_nav = "<span class="dead-link">Next</span>";

&#125;

if($show_from > 0 && ($show_from - $pr_page) < $amount) &#123;

	$prev_show_from = $show_from - $pr_page;
	$prev_nav = "<a href="/tagwall.php?show_from=$prev_show_from">Previous</a>";
&#125;
else &#123;

	$prev_nav = "<span class="dead-link">Previous</span>";

&#125;

$nav = "<p align="center"><table cellpadding="4">
<tr><td align="center">$prev_nav</td><td align="center">$prev_nav</td></tr>
</p>";
while ($row = mysql_fetch_array($result)) &#123;
extract($row);
        ?>
	<html>
        <table cellpadding=2>
        <tr><td width=50%>Written By: <? echo "$name"; ?></td></tr>
	<tr><td width=50%>Day/Time/Date: <? echo "$thetime"; ?></td></tr>
	<tr><td width=50%>Ip: <? echo "$ip"; ?></td></tr>
	<tr><td width=50%>Email: <? echo "$email"; ?></td></tr>
	<tr><td width=50% height=100 cellpadding=10>Message: <? echo "$message"; ?><br><br><p align=left><span class="class2"><a href="http://www.daneshea.com/<? echo "tagloginconfirm.php?id=$id&action=deleteid"; ?>">Delete</a></span> :: <span class="class2"><a href="http://www.daneshea.com/<? echo "ban.php?deleteid=$id&banip=$ip&name=$name&email=$email"; ?>">Ban</a></span></td></tr></table><br>
	</html>
	<?	
	&#125;
echo "$nav";
Last edited by exutable on Wed Feb 16, 2005 7:54 pm, edited 1 time in total.
Dale
Forum Contributor
Posts: 466
Joined: Fri Jun 21, 2002 5:57 pm
Location: Atherstone, Warks

Post by Dale »

Welcome to DevNetwork,

Please would you be able to use tags in your posts from now on please,as it helps us define whats the text and whats the code.

Thank You.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

try echo'ing out $tag_amount[0] before you extract it. Firstly, it is not an array and you have not fetched the result from that query, you have simply executed it.

Code: Select all

$tag_amount&#1111;] = mysql_query($count_amount); 

extract($tag_amount&#1111;0]);
should be changed to

Code: Select all

$tag_amount = mysql_query($count_amount); 

$tag_amount = mysql_fetch_assoc($tag_amount);  

echo $tag_amount&#1111;'amount'];
Which wil return your count query.
exutable
Forum Newbie
Posts: 5
Joined: Wed Feb 16, 2005 7:35 pm

Post by exutable »

Thank you very much it now seems to work.....
exutable
Forum Newbie
Posts: 5
Joined: Wed Feb 16, 2005 7:35 pm

Post by exutable »

Here is what it looks like now, but the thing is I have gone over the pr_page of 20 and the next link does not seem to appear as an active link.
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

change instances of $amount.. ie.

Code: Select all

if($amount > ($show_from + $pr_page)) &#123;
to $tag_amount['amount'] ie.

Code: Select all

if($tag_amount&#1111;'amount'] > ($show_from + $pr_page)) &#123;
exutable
Forum Newbie
Posts: 5
Joined: Wed Feb 16, 2005 7:35 pm

Unfortunately

Post by exutable »

Unfortunately the next link comes back to the same exact page instead of go to the next this is EVERYTHING I am using to read the tagwall!

Code: Select all

if(!$show_from || $show_from < 0) &#123;
$show_from = 0;
&#125;

$pr_page = 20;

$result = "select name, email, message, date_format(time, '%a, %H:%i, %c/%e/%Y') as thetime from tagwall order by time desc limit $show_from, $pr_page";

$sql = mysql_query($result);

$count_amount = "select count(*) as amount from tagwall";

$tag_amount = mysql_query($count_amount); 

$tag_amount = mysql_fetch_assoc($tag_amount);

if($tag_amount&#1111;'amount'] > ($show_from + $pr_page)) &#123;

	$next_show_from = $show_from + $pr_page;
	$next_nav = "<span class="class2"><a href="/tagwall.php?show_from=$next_show_from">Next</a></span>";

&#125;
else &#123;

$next_nav = "<span class="dead-link">Next</span>";

&#125;

if($show_from > 0 && ($show_from - $pr_page) < $tag_amount&#1111;'amount']) &#123;

	$prev_show_from = $show_from - $pr_page;
	$prev_nav = "<span class="class2"><a href="/tagwall.php?show_from=$prev_show_from">Previous</a></span>";
&#125;
else &#123;

	$prev_nav = "<span class="dead-link">Previous</span>";

&#125;

$nav = "<p align="center"><table cellpadding="4">
<tr><td align="center">$prev_nav</td><td align="center">$next_nav</td></tr>
</p>";

while ($row = mysql_fetch_array($sql)) &#123;
extract($row);
echo "<table cellpadding=2>";
echo "<tr><td width=50%>Written By: $name</td></tr>";
	echo "<tr><td width=50%>Day/Time/Date: $thetime</td></tr>";
	echo "<tr><td width=50%>Email: $email</td></tr>";
	echo "<tr><td width=50% height=100 cellpadding=10>Message: $message</td></tr></table><br>";
&#125;
echo "$nav";
&#125;
Post Reply