mySQL表
ID |名称
1 |甲
2 |乙
3 | ç
4 | d
5 | ë
mySQL查询
$query = "SELECT * FROM ego_work WHERE 1;
$result = mysql_query($query);
$rows = array();
while ($row = mysql_fetch_array($result)) {
$rows[] = $row;
}
php Code
<?php foreach ($rows as $work): ?>
<span> <?php echo $work['id']; ?>, </span>
<?php endforeach; ?>
<br \>
<?php foreach ($rows as $work): ?>
<span> <?php echo $work['name']; ?>, </span>
<?php endforeach; ?>
RESULT
1,2,3,4,5
E,A,B,C,d
我做错了什么?我想把第二个结果变成A,B,C,D,E
答案 0 :(得分:1)
你可以尝试下面的代码
<?php foreach ($rows as $work): ?>
<span> <?php echo $work['id']; ?>, </span>
<?php endforeach; ?>
<?php reset($rows);?>
<br \>
<?php foreach ($rows as $work): ?>
<span> <?php echo $work['name']; ?>, </span>
<?php endforeach; ?>