SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Location
    Dewsbury, UK
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Why does this loop forever ?

    I've been trying to figure this out for like for ever ...

    PHP Code:

    // start index

    $cat = @mysql_query("SELECT url1, url2, url3, filename, title, description, sidebar FROM $table ORDER BY id DESC LIMIT 0,30") or die("Could not populate the index page");

    $message '<table width="100%" cellpadding="0" cellspacing="0" border="1" borderColor="#fafafa" bgcolor="#ffffff">';

    $i 0// $r=@mysql_fetch_array($cat)

     
    while( $r=@mysql_fetch_array($cat) )
     {

     
    $cat1 $r["url1"];
     
    $cat2 $r["url2"];
     
    $cat3 $r["url3"];
     
    $description $r["description"];
     
    $filename $r["filename"];
     
    $title $r["title"];
     
    $sidebar $r["sidebar"];

    $row_breaker 3;

    $trcolor = ($i 2) ? "#f5f5f5""#ffffff";

    $html_string '<h2><a href="'.$filename.'">'.$title.'</a></h2>' $description ' ' $i ;

    $stringy '<td align="center" valign="middle" bgcolor="'.$trcolor.'">'.$html_string.'</td>';

          if (
    $i == 0)  {
    $message .= '<tr>' $stringy ; }

         else if (
    $i $row_breaker == 0)  // will reach here when $i == 4,8,12,16 
      
    {
    $message .= '</tr><tr>' $stringy ;
    }       
          else {
    $message .= $stringy ; }

    $i++;
     }

    while ( 
    $i $row_breaker !== ) {
        
    $trcolor = ($i 2) ? "#f5f5f5""#ffffff";
        
    $message .= '<td align="center" valign="middle" bgcolor="'.$trcolor.'">&nbsp;</td>';
    $i++;
       }

    $message .= "</tr></table>";

    echo (
    $message);

    // end index 
    ?
    piniyini = the wackiness crazed within
    Check out my blog => toseef's blog

  2. #2
    Employed Again Viflux's Avatar
    Join Date
    May 2003
    Location
    London, On.
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In your second while loop, change it to
    PHP Code:
    while ( $i $row_breaker != ) { 

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When your using comparisons in PHP you don't use double ='s, you put the comparison method (in this case NOT !) in place of the first comparison method which is the first = . Resulting in your != to compare the variable with. == means the variable equals and != means the variable does not equal.

    Hope this helps!
    IDM Firm.com
    Internet Design & Marketing Firm

  4. #4
    Employed Again Viflux's Avatar
    Join Date
    May 2003
    Location
    London, On.
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Bah.

    You're supposed to let him say "Wow, thanks! But how'd you know?", then I swoop in with a link to PHP Operators - http://ca.php.net/manual/en/language...comparison.php and propose that he do some reading.

    You ruined my fun!

  5. #5
    SitePoint Enthusiast
    Join Date
    Mar 2005
    Posts
    27
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    lol,

    Sorry Viflux, new to the forums haven't quite learned all the secret ins and outs. Accept my apology!
    IDM Firm.com
    Internet Design & Marketing Firm

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Location
    Dewsbury, UK
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Ah thanks for that guys but I still cant it to work

    I'm trying some other methods at the moment, when/if I figure it out I will let you know :-)
    piniyini = the wackiness crazed within
    Check out my blog => toseef's blog

  7. #7
    SitePoint Enthusiast
    Join Date
    Dec 2002
    Location
    Dewsbury, UK
    Posts
    79
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I got it!

    I'll tell you what the problem was, because I am doing this on a blogger template and customizing my site around it, the number of posts on a page was causing it load that many time. I had it to 30 so this code was being looped 30 times! I simply changed this to 1 and bingo!

    There was nothing much wrong with the code, except the thing you guys ponited out.

    Thank you for the quick replies :-)
    piniyini = the wackiness crazed within
    Check out my blog => toseef's blog


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
  •