【发布时间】:2011-07-01 09:04:35
【问题描述】:
我正在尝试使用数组查询我的数据库,我正在尝试计算数据库中每个国家/地区的查询返回的行数,并计算每个国家/地区的数字等于1.使用如下代码:
<?php
include ('mysqli_connect.php'); // indclude mysql connection functions
$countries = array('united states','canada','united kingdom');
foreach($countries as $country){
//e.g. $r_spain holds the results from the query below with spain as $country
$r_.$country = mysqli_query($dbc,"SELECT * FROM feelings WHERE country = '$country' AND digit='1'");
//loop through the results
while($row = mysqli_fetch_array($r_.$country, MYSQLI_ASSOC)){
$rowCount = mysqli_num_rows($r_.$country);
echo $country."=".$rowCount;
}
}
?>
这是我收到的错误消息:
可捕获的致命错误:类对象 mysqli_result 无法转换 串起来 /home2/designwr/public_html/uwe/notalone/updates/percentage.php 在第 9 行
谁能指出我正确的方向?
【问题讨论】:
-
你为什么使用 mysqli 而不是 mysql? mysqli 并没有真正用得那么多...
-
我不知道 :) 我是这么教的,是不是很糟糕?
-
非常错误......mysqli 是连接到 MySQL 的 OO 方式,所以它现在是第一选择。
-
我认为您应该使用 mysqli 或 PDO 并利用它们提供的准备好的语句。
-
我想知道,这些 mysqli 宣传人员中是否至少有一个会使用准备好的语句提出适当的解决方案。恐怕他们都没有真正使用它;)