我不断收到此警告:
警告:这里为 foreach() 提供的参数无效是我的完整代码,它执行 mysql 的函数列表输出并将其分页每页 10 个输出,错误出现在最后一页
<?php
require_once('dbconnect.php');
$yesterday = date("Y-m-d", strtotime("yesterday"));
$page=intval($_POST['p']);
if($page=='')
{
$page=1;
}
$dbadd=($page-1)*10;
$query = "SELECT * FROM ranking";
$totalposts=mysql_num_rows(mysql_query($query));
$totalpages=ceil($totalposts/10);
$query = "SELECT r.ranking,r.screenname,r.name,r.followers,r.tweets,r.location,r.`join date`,r.avatar, h.date, r.followers-h.followers followers_diff, r.tweets-h.tweets tweets_diff FROM ranking r, ranking_hist h WHERE r.screenname=h.screenname and h.date='$yesterday' AND r.ranking>$dbadd AND r.ranking<($dbadd+11) ORDER BY ranking ASC LIMIT 10 ";
$result = mysql_query($query);
if( !$result ) {
die("Error: " . mysql_error() );
}
while($row = mysql_fetch_assoc($result) ) {
$tweep = $row['screenname'];
$tweeps[$tweep] = $row;
}
$query = "SELECT r.ranking,r.screenname,r.name,r.followers,r.tweets,r.location,r.`join date`,r.avatar FROM ranking r WHERE r.screenname NOT IN ( SELECT DISTINCT screenname from ranking_hist ) AND r.ranking>$dbadd AND r.ranking<($dbadd+11) ORDER BY ranking ASC LIMIT 10";
$result = mysql_query($query);
if( !$result ) {
die("Error: " . mysql_error() );
}
while($row = mysql_fetch_assoc($result) ) {
echo "";
$tweep = $row['screenname'];
$tweeps[$tweep] = $row;
}
mysql_free_result($result);
$i = 0;
$total_amount = count($tweeps);
foreach ($tweeps as $tweep) {
$i++;
if ($total_amount == $i) {
$class = 'divrow divrowlast';
} else {
$class = 'divrow';
}
$col5 = "";
if( $tweep['followers_diff'] > 0 ) {
$col5 = "<span style='color:green; display:inline;'> +" . $tweep['followers_diff'] . "▲ </span>";
}
else if( $tweep['followers_diff'] < 0 ) {
$col5 = "<span style='color:red; display:inline;'> -" . $tweep['followers_diff'] . "▼ </span>";
}
$html_table .= '<div class="'.$class.'"><ul>' .
"<li class='row100rank'> " . $tweep['ranking'] . "</li>" .
"<li class='row100user'>
<div class='avatar'><img width='32' height='32' src='" . $tweep['avatar'] . "' alt='" . $tweep['screenname'] ."' /></div>
<div class='feature-author'><a class='text_bigger' href='http://www.twitter.com/" . $tweep['screenname'] . "/'>@".$tweep['screenname']."</a></div>
<div class='row100description'>".$tweep['name']."<br />".$tweep['location']."</div></li>" .
"<li class='pad'><div class='stat'> <span>" . $tweep['followers'] . " $col5</span> followers</div></li>" .
"<li class='pad rowTwitte'><div class='stat'> <span>" . $tweep['tweets'] . " $col6</span> tweets</div></li>" .
"<li class='pad rowJoionDate'><div class='stat'> <span>" . date ( 'd M y', strtotime($tweep['join date'])) . "</span> joindate</div></li>" .
"</ul></div>";
}
echo $html_table;
?>
<div class="dataTables_paginate paging_full_numbers" ><span class="first paginate_button" ><a class="pagelinks" href="javascript:void(0);" pageid="1" onClick="changepage(1);">First</a></span>
<span class="previous paginate_button" ><a class="pagelinks" href="javascript:void(0);" pageid="<?php echo $page>1?($page-1):1;?>" onClick="changepage(<?php echo $page>1?($page-1):1;?>);" >Previous</a></span>
<span>
<?php
switch($page){
case 1:
$it=1;
$itl=6;
break;
case 2:
$it=1;
$itl=6;
break;
case $totalpages:
$it=$totalpages-4;
$itl=$totalpages+1;
break;
case $totalpages-1:
$it=$totalpages-4;
$itl=$totalpages+1;
break;
default:
$it=$page-2;
$itl=$page+3;
}
for(;$it<$itl;$it++){
?>
<span class="<?php echo $page== $it?'paginate_active':'paginate_button'; ?>">
<a class="pagelinks" href="javascript:void(0);" pageid="<?php echo $it;?>" onClick="changepage(<?php echo $it;?>);" ><?php echo $it; ?></a></span>
<?php
}
?>
</span>
<span class="next paginate_button" ><a class="pagelinks" href="javascript:void(0);" pageid="<?php echo $page<$totalpages?($page+1):$page;?>" onClick="changepage(<?php echo $page<$totalpages?($page+1):$page;?>);">Next</a>
</span>
<span class="last paginate_button" >
<a class="pagelinks" href="javascript:void(0);" pageid="<?php echo $totalpages;?>" onClick="changepage(<?php echo $totalpages;?>);">Last</a>
</span></div>
<div class="dataTables_info">
Showing <?php echo ($page-1)*10+1;?> to <?php echo ($page-1)*10+10;?> of <?php echo $totalposts;?>
</div>