Jenling Posted April 7, 2008 Share Posted April 7, 2008 Dear expert, I want to use array to do the system. I want to get the query from database and use array to display the data. How can I do that? My code is as below: <? $sql="select MRname from meetingroom"; $resu = mysql_query($sql, $connect) or die('Error when running command<br>'.$sql); $num=@mysql_num_rows($resu); while($row_Recordset=mysql_fetch_array($resu, MYSQL_BOTH)){ $m=array($row_Recordset[MRname]); } $meeting = array($m); Link to comment https://forums.phpfreaks.com/topic/99925-array/ Share on other sites More sharing options...
The Little Guy Posted April 7, 2008 Share Posted April 7, 2008 Some thing like this could work: <?php $myArray $sql="select MRname from meetingroom"; $resu = mysql_query($sql, $connect) or die('Error when running command<br>'.$sql); $num=@mysql_num_rows($resu); while($row_Recordset=mysql_fetch_array($resu, MYSQL_BOTH)){ $myArray[] = $row_Recordset['Column_Name_Here']; } ?> Link to comment https://forums.phpfreaks.com/topic/99925-array/#findComment-510959 Share on other sites More sharing options...
Jenling Posted April 7, 2008 Author Share Posted April 7, 2008 It still cant work...I wonder why. can u give me more idea? I want to display the particular column with array.. Link to comment https://forums.phpfreaks.com/topic/99925-array/#findComment-510986 Share on other sites More sharing options...
Barand Posted April 7, 2008 Share Posted April 7, 2008 try <?php $sql="select MRname from meetingroom"; $resu = mysql_query($sql, $connect) or die('Error when running command<br>'.$sql); $m = array(); // create empty array while($row_Recordset=mysql_fetch_assoc($resu)){ $m[] = $row_Recordset['MRname']; // add names to array } // output the array foreach ($m as $room) { echo $room, '<br />'; } ?> Link to comment https://forums.phpfreaks.com/topic/99925-array/#findComment-511003 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.