开始查询以显示结果:
$at = array();
$num=array();
$i=0;
while($rw=mysql_fetch_array($r))
{
echo $rw['c_number']
$number=$rw['c_number'];
$num[$i]=$number;
$i++;
echo $rw['total'];
$at[] = $rw['total'];
}
//此查询的结果如下:
Mobile numbers bills
03455919448 34
03215350700 56
03474738923 678
03573987932 344
03187438979 1324
//现在想将其插入数据库
$d= 'november';
foreach($num as $num1){
$sql = "insert into billing details(bill,month/year,c_number) values ('$at','$d','$num')";
mysql_error();
$result = mysql_query($sql);
}
//结尾处的插入查询无法正常工作并给出错误:
MySQL returned an empty result set (i.e. zero rows). ( Query took 0.0004 sec )
答案 0 :(得分:0)
我认为您需要将num替换为num1,如
$sql = "INSERT INTO `billing details`(bill,`month/year`,c_number) VALES ('$at','$d','$num1')";
并且不要使用mysql_ *函数,因为它们被删除,而是使用mysqli_ *函数或PDO语句
并将您的表名放在'''中,它似乎有两个不同的名称,而列名称月/年也是
答案 1 :(得分:0)
我不知道究竟想要插入$ num或$ num1?并检查您的表名,列名
$d= 'november';
int i=0; // you are saying that $at has all bills
foreach($num as $num1){
$sql = "insert into billing details(bill,month/year,c_number) values ('$at[i]','$d','$num1[mobile_number]')";
$result = mysql_query($sql);
if (mysql_error()) die('Error, insert query failed');
i++;
}