Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8373795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:46:09+00:00 2026-06-09T14:46:09+00:00

I keep getting this warning: Warning: Invalid argument supplied for foreach() in here is

  • 0

I keep getting this warning:

Warning: Invalid argument supplied for foreach() in
here is my full code which performe function list output from mysql and paging it 10 output per page , the error appear in last page

<?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>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:46:11+00:00Added an answer on June 9, 2026 at 2:46 pm

    Try the code blow. Your $tweeps might on some occasions not be an array or object, check if the array is not empty and is_array($tweeps).

    $i = 0;
    $total_amount = count($tweeps);
    if(is_array($total_amount) && !empty($tweeps))
    {
        foreach  ($tweeps as $tweep)
        {
            $i++;
            if ($total_amount == $i)
            {
               $class = 'divrow divrowlast';
            }
            else
            {
               $class = 'divrow';
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What's wrong with my code? I keep getting this error: Warning: mysql_query(): supplied argument
I keep getting 'warning: control reaches end of non-void function' with this code: -
I keep getting 'warning: control reaches end of non-void function' with this code: static
I keep getting this RuntimeError which I'm not sure how to fix. Here's what
I keep getting this error: Warning: preg_match() [function.preg-match]: Unknown modifier 't' in D:\xampp\htdocs\administrator\components\com_smms\functions\plugin.php on
Warning: mkdir() [function.mkdir]: No such file or directory in I keep getting this annoying
I keep getting this warning with the line of code below, 'initWithFrame:reuseIdentifier:' is deprecated.
Ok, here is the deal, I keep on getting this warning : 'AppDelegate' may
I keep getting this error: Warning: mysql_query() [function.mysql-query]: Access denied for user 'mcabinet'@'localhost' (using
I keep getting this as a warning I want to avoid getting this warning

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.