#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. Did you steal it?
    Devshed Supreme Being (6500+ posts)

    Join Date
    Mar 2007
    Location
    Washington, USA
    Posts
    14,074
    Rep Power
    9398
    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. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,959
    Rep Power
    1014
    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]." - ";

    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  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,908
    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