我有下面的数组,我想用mysql中的2列来填充它。我试过了,但似乎做不出来。如有任何帮助,将不胜感激
mysql表如下:
IDNO|NAME
<?php
$age = array(
$result2 = mysqli_query($con,"SELECT * FROM tbl_suburbs LIMIT 10");
while($row2 = mysqli_fetch_array($result2))
{
$row2['name']=>$row2['id']
}
"Ben"=>"37",
"Joe"=>"43",
);
arsort($age);
foreach($age as $x => $x_value)
{
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
?>
您的目标并非100%明确。代码是错误的。
让我试着猜测一下你真正想要的是什么:
$result2 = mysqli_query($con,"SELECT * FROM tbl_suburbs ORDER BY age DESC LIMIT 10");
$age = array();
while($row2 = mysqli_fetch_array($result2))
{
$age[$row2['name']]=$row2['age'];
}
foreach($age as $x => $x_value)
{
echo "Key=" . $x . ", Value=" . $x_value;
echo "<br>";
}
如果你需要澄清和/或改进,请告诉我。