mysql_connect('localhost:3036', 'root', 'xxxx');
mysql_select_db('extractor');
$query = mysql_query("SELECT trackingno FROM xx where orderid='".$item->increment_id."'");
$compiledresults = mysql_fetch_array($query);
foreach($compiledresults as $items){
echo $items."</br>";
}
它总是最多只返回两个值。知道为什么吗?
最佳答案
只需将您的代码修改为:
$query = mysql_query("SELECT trackingno FROM xx where orderid='".$item->increment_id."'");
if ($query){
while ($data = mysql_fetch_assoc($query)){
echo $data['trackingno'] ;
}
}
你得到 2 个项目的原因是你使用了一次 mysql_fetch_array
。这只为您提供了数据库中的一行。数组中的第一个元素是数字索引,另一个是字符串索引。
所以你有:$compiledresults[0]
和 $compiledresults['trackingno']
事实上。
关于php - mysql 只返回 2 个结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17378306/