php怎么将数据库中的所有数据赋值给变量
$testingsql="SELECT*FROM`dealer_datadetail`WHEREtreasure<>0orderbytimedesc";//查询所有数据S...
$testingsql = "SELECT * FROM `dealer_datadetail` WHERE treasure <> 0 order by time desc"; //查询所有数据SQL
$testingquery = mysqli_query ($link, $testingsql);
while ($testingrow = mysqli_fetch_array ($testingquery)) {
$allbrand = $testingrow[2]."<br>";
}
echo $allbrand; //只获取了数据库中的最后一个值。
//我想将数据库中数组下标为2的所有字段全部获取后赋值给一个变量,请问该怎么实现。谢谢! 展开
$testingquery = mysqli_query ($link, $testingsql);
while ($testingrow = mysqli_fetch_array ($testingquery)) {
$allbrand = $testingrow[2]."<br>";
}
echo $allbrand; //只获取了数据库中的最后一个值。
//我想将数据库中数组下标为2的所有字段全部获取后赋值给一个变量,请问该怎么实现。谢谢! 展开
1个回答
展开全部
第一种:数组
$allbrand = array();
while ($testingrow = mysqli_fetch_array ($testingquery)) {
$allbrand[] = $testingrow[2];
}
第二种:字符串
$allbrand = '';
while ($testingrow = mysqli_fetch_array ($testingquery)) {
$allbrand .= $testingrow[2]."<br>";
}
请采纳,谢谢
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询