SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Thread: while loop??

  1. #1
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    while loop??

    Hello,

    my while loop is not working properly. its not considering my first row value. from second row value its working fine. it just strange. can anyone please have look on my code and tell me what is wrong in there.

    here is my code:
    PHP Code:
    <?
    $sqlpage    
    $op->runsql("SELECT  a.username,a.avatar,r.visitor_id,r.visiting_count,TIMESTAMPDIFF(MINUTE, r.recent_visited, NOW()) AS MinsSinceLastVisit FROM recent_visitor as r ,author as a WHERE (r.visitor_id = a.id) AND r.profile_owner = '$uid' ORDER BY r.recent_visited DESC  LIMIT $start$limit_value");
     if(
    mysql_num_rows($sqlpage) > 0){
    ?>
    <p class="msgText">Total <strong><?=$total_records;?></strong><?if($total_records >1){
    ?> Recent Visitor's<?}else{?> Recent Visitor<?}}?></p>
    <?
                          
    if(mysql_num_rows($sqlpage) > 0){

           while(
    $row1 $op->select($sqlpage)){
           
    $imagearr explode(",",$row1['avatar']);
            
    $imagearr[0]= preg_replace("/\/avatar\//","/small/"$imagearr[0]);



          
    ?>
          <a href='/profile/<?=$blog->spacereplace($row1['username']);?>/' title="<?=$row1['username']?>"><img src="<?=$retpath;?>/<?=$imagearr[0];?>" width="40" height="40" alt="<?=$row1['username']?>"/></a>
          <?


                $Ymin 
    60 24 365;
                
    $Mmin 60 24 30;
                
    $Wmin 60 24 7;
                
    $Dmin 60 24;
                
    $Hmin 60;

                
    $Y = (int)($minutes_dif $Ymin);
                
    $minutes_dif $minutes_dif &#37; $Ymin;

                
    $MON = (int)($minutes_dif $Mmin);
                
    $minutes_dif $minutes_dif $Mmin;

                
    $W = (int)($minutes_dif $Wmin);
                
    $minutes_dif $minutes_dif $Wmin;

                
    $D = (int)($minutes_dif $Dmin);
                
    $minutes_dif $minutes_dif $Dmin;

                
    $H = (int)($minutes_dif $Hmin);
                
    $minutes_dif $minutes_dif $Hmin;

                if(
    $Y ){
                      echo 
    "$Y year(s) ";

                      }else if(
    $MON 0){
                      echo 
    "$MON month(s) ";
                      }
                      else if(
    $W 0){
                      echo 
    "$W week(s) ";
                      }
                      else if(
    $D 0){
                      echo 
    "$D day(s) ";
                      }
                      else if(
    $H 0){

                      echo 
    "$H hour(s) ";
                      }
                      else if(
    $minutes_dif 0){

                      echo 
    "$minutes_dif minute(s) ";
                      }
          echo 
    "ago";  ?>(<?=$row1['visiting_count']?>visits)<? echo"\t";
                 
    $i++; }
                   }

    ?>
    when i echoed my query, i found that my database table is like this
    username visitor_id visiting_count MinsSinceLastVisit
    nehapi 12 23 0
    sidharth 15 26 21
    manoj 11 35 27
    kaushal 10 27 961
    nanda 9 15 1112
    For the first row my last column value(MinsSinceLastVisit)is not increasing .it means my first value is not changing only.any suggestion?


    thanks in advance.

  2. #2
    Follow Me On Twitter: @djg gold trophysilver trophybronze trophy Dan Grossman's Avatar
    Join Date
    Aug 2000
    Location
    Philadephia, PA
    Posts
    20,578
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You don't assign a value to $minutes_dif anywhere in your code

    But that's not the problem, since you're getting the wrong value from the query, this isn't caused by any of the PHP code in this file

    Are you updating that row on the same page you run this script?

  3. #3
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thank dan_grassman for you reply.

    Are you updating that row on the same page you run this script?
    I am not updating query particularly with firing the update query but its related to time that column is getting updated automatically after every minute. like this

    TIMESTAMPDIFF(MINUTE, r.recent_visited, NOW()) AS MinsSinceLastVisit
    so what you think about it?

  4. #4
    SitePoint Guru deepM's Avatar
    Join Date
    Dec 2007
    Location
    India
    Posts
    705
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    no reply. anyways i have solved the problem.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •