SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Addict
    Join Date
    Sep 2006
    Posts
    238
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    function, increment, while

    Hello

    I have this code:

    PHP Code:
    while (my while loop) {

                
    $number mysql_num_rows($pics_query);
                    
    $i 1;
                    if (
    $i $number) {
                        echo 
    $number;
                    }
                    
    $i++;


    It's a simple if else statement to check if a row is latest submission.

    How can I put that script in the loop into a function?

    For some reason the increment isnt working in a function.

    Thanks

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    72 Post(s)
    Tagged
    0 Thread(s)
    because in every iteration of your loop, you reset $i to 1.
    incidentally, you'd do far better to do a single query. Use a date field in your table, ORDER BY on it, and LIMIT 1.
    Never grow up. The instant you do, you lose all ability to imagine great things, for fear of reality crashing in.


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
  •