I'm using this to to retrieve two columns in a database
while($comment[]=mysql_fetch_array($sql));
this returns an array with associative and number indices for each column.
This works great but I would also like to create a new array from the orginial$comment[]
that is just a simple array of stri开发者_运维问答ngs (only the first column). What are my options? Is there any way to accomplish this without looping through a second time?
Depending on how many columns you have, you could do something like:
$result = mysql_query($sql);
while (list($col1[], $col2[]) = mysql_fetch_row($result));
$col1
will be an array of just column 1's values, and $col2
will be similar for column 2's values.
$array = array();
for ($i = 0;$comment = mysql_fetch_array($sql);$i++){
$array[$i] = $comment['field_name'];
}
精彩评论