[英]MySQL Query not returning all rows according to echo ouput
I'm having trouble with a MySQL query, I really can't figure this out. 我在使用MySQL查询时遇到问题,我真的无法弄清楚。
The database is like this: ID = 1,2,3,4 | 数据库是这样的:ID = 1,2,3,4 | Currency = CAD, USD, GBP, EUR
货币=加元,美元,英镑,欧元
Output from the following code is: 以下代码的输出是:
1 1 1 1
1 1 1 1
CC 抄送
CC 抄送
$Curr = mysql_fetch_array(mysql_query("SELECT `ID`, `Currency` FROM `currencies` WHERE `IsActive`=1"));
foreach($Curr as $CurrElem){
echo $CurrElem['Currency'] . ' ' . $CurrElem['ID'] . '<br />';
}
mysql_fetch_array will only ever return one row so you need to loop it mysql_fetch_array只会返回一行,因此您需要循环它
$result = mysql_query("SELECT `ID`, `Currency` FROM `currencies` WHERE `IsActive`=1");
while ($row = mysql_fetch_array($result)) {
// do something
}
Its the mysql_fetch_array that is causing the problems...you are pulling the first item....what you want is.. 它是导致问题的mysql_fetch_array ...您正在提取第一个项目....您想要的是..
$result = mysql_query("SELECT id, name FROM mytable");
while ($row = mysql_fetch_array($result, MYSQL_NUM)) {
printf("ID: %s Name: %s", $row[0], $row[1]);
}
Above is just to show syntax : more @ http://php.net/manual/en/function.mysql-fetch-array.php 以上只是显示语法:更多@ http://php.net/manual/zh/function.mysql-fetch-array.php
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.