我有一个像这样的关联数组:
$arr = array('format' => 'A4', 'coulor' => 'red', 'height' = > '30');
我想在像这样的mysql查询中使用它:
reset($arr);
$first_key = key($arr); // get the first key of the array
$sql = "// sql query here...";
$result = mysqli_query($link, $sql);
while($row = mysqli_fetch_assoc($result))
{
echo $row[$first_key]; // will echo out the content of a table field
}
如何推进此关联数组的游标,以便我可以回显出mysql表中下一列的内容
答案 0 :(得分:0)
如果您确实需要使用$arr
的密钥,请执行以下操作:
while($row = mysqli_fetch_assoc($result))
{
foreach($arr as $key=>$v)
echo $row[$key];
}
否则你可以简单地使用mysqli_fetch_row()
这样你的键就是整数,你可以通过这样做来获得下一个:
while($row = mysqli_fetch_row($result)) {
echo $row[0]; // will echo out the content of a table field
echo $row[1]; // will echo out the content of a table field
}