SitePoint Sponsor

User Tag List

Results 1 to 8 of 8
  1. #1
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Exclamation While ... condition problem.

    Hai all,

    Note:- $raw is just initilized below and no any previous values it has.

    Code:
    while ($raw=mysql_fetch_array($query)):
    I picked up the above code from an ebook and really woked well.
    but what is this condition. I really not undestand this condition.
    i mean what $raw's get each and every loop?

    Assume i have 50 records in the table.

  2. #2
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    On each iteration of the while loop mysql_fetch_array will assign the next 'row' of the result set (your 50 records) to $raw. In plain English you could read it as:

    while(there are still records to fetch, assign the next record from the results to $raw):

  3. #3
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by PHP Manual
    array mysql_fetch_array ( resource result [, int result_type] )

    Returns an array that corresponds to the fetched row and moves the internal data pointer ahead.
    Which means that on every iteration, the function returns next row from the result set. Once it reaches the end of the result set, it returns FALSE, which in turn ends the loop.
    Saul

  4. #4
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Hai mark.. and php d..

    what happen if i sad like this?
    Code:
    while (mysql_fetch_array($query)):
    will it loop just 50 times?

  5. #5
    Sell crazy someplace else markl999's Avatar
    Join Date
    Aug 2003
    Location
    Manchester, UK
    Posts
    4,007
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what happen if i sad like this?
    What did it do when you tried it?

  6. #6
    ✯✯✯ silver trophybronze trophy php_daemon's Avatar
    Join Date
    Mar 2006
    Posts
    5,284
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Yep, it will. Doesn't make sense doing so, though. If you want to select a part of the result set, probably you need to use LIMIT clause in your query in first place.
    Saul

  7. #7
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Talking

    Quote Originally Posted by markl999 View Post
    What did it do when you tried it?
    Yah mar, it does nothing. i am really want to know here what will happen if you take the $raw out.

    will this just loop 50 times?

  8. #8
    SitePoint Guru afridy's Avatar
    Join Date
    Mar 2007
    Posts
    966
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    as php demon says, 'Yep it will', then i really undestand what
    Code:
    while (mysql_fetch_array($query)):
    This loop does. Yah. when the last raw fetched the $raw get empty. loop exits.

    Thank you Mark and php Demaon for the support.


    Thank you


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
  •