#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0

    Smile Infinit loop by WHILE


    Friends,

    I'm using PHP 5.4.10 and when I'm trying to read data from a MS SQL database server, I get the first record repeated unlimited!

    my codes is:

    PHP Code:
    $res_Total mssql_fetch_array(mssql_query($query_Total));
    while (
    $res_Total){
    print 
    $Total $res_Total[0]." - ";

    Help me please!
  2. #2
  3. Come play with me!
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    13,761
    Rep Power
    9397
    If you get inside the loop then $res_Total == true, right? So where inside the loop do you change it so that it might become false?
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0

    Question


    Originally Posted by requinix
    If you get inside the loop then $res_Total == true, right? So where inside the loop do you change it so that it might become false?
    Thanks,

    But such this codes is working when I'm fetching data from an Oracle database server..!

    so what's the solution ?
  6. #4
  7. Banned
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,938
    Rep Power
    0
    Hi,

    Originally Posted by sina14
    But such this codes is working when I'm fetching data from an Oracle database server..!
    I doubt that.

    In fact, the code makes no sense whatsoever. You fetch one row from the result set of the query, discarding the rest. Then you make a loop using this array as a condition (??), and in the loop, you write the first entry of the first row into a variable again and again and print it again and again.

    I have no idea what that's supposed to do. If you want to loop through all rows, you need to fetch the rows in the loop:

    PHP Code:
    $total_query mssql_query($query_Total);
    while (
    $total_row mssql_fetch_array($total_query )) {
        print 
    $total_row[0]." - ";

  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2013
    Posts
    3
    Rep Power
    0
    Originally Posted by Jacques1
    Hi,



    I doubt that.

    In fact, the code makes no sense whatsoever. You fetch one row from the result set of the query, discarding the rest. Then you make a loop using this array as a condition (??), and in the loop, you write the first entry of the first row into a variable again and again and print it again and again.

    I have no idea what that's supposed to do. If you want to loop through all rows, you need to fetch the rows in the loop:

    PHP Code:
    $total_query mssql_query($query_Total);
    while (
    $total_row mssql_fetch_array($total_query )) {
        print 
    $total_row[0]." - ";

    Thank you so much!
    Actually I have to run my query before data fetching in a while statement...
    Now I think it's working!
  10. #6
  11. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,699
    Rep Power
    6351
    Actually I have to run my query before data fetching in a while statement...
    Yes, that's why his code contained the "query" function BEFORE the while loop. See how there's more than one line?
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo