Populate PHP Array from While Loop

后端 未结 5 784
清歌不尽
清歌不尽 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:07

    If you have multiple columns in your Departments table and you want to save in different array.

    $result = mysql_query("SELECT * FROM `Departments`");
    $dept_id = array();
    $dept_name=array();
    while($row = mysql_fetch_assoc($result))
    {
    //fetches and store all results in id column on your departments table
    $dept_id= $row['id'];
    //fetches and store all results in name column on your departments table    
    $dept_name=$row['name'];
    }
    

提交回复
热议问题