mysql 获取数组
我正在尝试做一个提取 4 行且每行有 2 列的 fetch 数组.无论如何我可以将每行中的每个单独字段单独定义为变量吗?
I am trying to do a fetch array which pulls out 4 rows and each row has 2 columns. Is there anyway I can define each individual field in each row as a variable individually?
row 1 name, id
row 2 name, id
row 3 name, id
row 4 name, id
<?php echo $row1name;?>
<?php echo $row1id;?>
<?php echo $row2name;?>
<?php echo $row2id;?>
<?php echo $row3name;?>
<?php echo $row3id;?>
<?php echo $row4name;?>
<?php echo $row4id;?>
这有意义吗?
推荐答案
$r = array();
$query = mysql_query("select id,name from table");
while ($row = mysql_fetch_assoc($query)) {
$r[] = $row;
}
echo $r[1]['name'];
echo $r[3]['id'];
等等.
你可以的
echo '<pre>';
print_r($r);
如果您想查看数组的内容.
if you want to see the content of your array.
相关文章