Populate PHP Array from While Loop

后端 未结 5 783
清歌不尽
清歌不尽 2020-12-12 19:41

If I am fetching data from a MySQL database and using a while loop to iterate through the data how would I add each one to array?

$result = mysql_query(\"SEL         


        
5条回答
  •  盖世英雄少女心
    2020-12-12 20:17

    my fav is the following;

    $result=odbc_exec($conn,$sql);
    if ($result) {
        while($found_results[] = odbc_fetch_array($result)) { } 
        array_pop($found_results); //pop off the empty line from while loading
    }
    

    you dont need to pop the last line, but it does leave a blank if you omit it. works the same for mysql obviously.

提交回复
热议问题