我有一个名为分配的表格,如此
CREATE TABLE allocate(
mid int(10),
pid int(20),
day1 int(2),
day2 int(2),
...
day31 int (2)
);
在mid
中,我有一个对应于一个月的数字(1是1月,2是2月等)。在第1天到第31天,我有数值。我现在正在尝试检索和更新相同的数据,但我无法做到。
我正在使用以下代码检索每个月的数据:
mysql_connect("$host", "$username", "$password")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$sql = "select * from allocate where product_id = '".$product_id."' "; //
$res = mysql_query($sql) or die(mysql_error());
while($row = mysql_fetch_array($res))
{
$day1 = $row['day1'];
$day2 = $row['day2'];
$day3 = $row['day3'];
$day4 = $row['day4'];
$day5 = $row['day5'];
$day6 = $row['day6'];
$day7 = $row['day7'];
$day8 = $row['day8'];
$day9 = $row['day9'];
$day10 = $row['day10'];
$day11 = $row['day11'];
$day12 = $row['day12'];
$day13 = $row['day13'];
$day14 = $row['day14'];
$day15 = $row['day15'];
$day16 = $row['day16'];
$day17 = $row['day17'];
$day18 = $row['day18'];
$day19 = $row['day19'];
$day20 = $row['day20'];
$day21 = $row['day21'];
$day22 = $row['day22'];
$day23 = $row['day23'];
$day24 = $row['day24'];
$day25 = $row['day25'];
$day26 = $row['day26'];
$day27 = $row['day27'];
$day28 = $row['day28'];
$day29 = $row['day29'];
$day30 = $row['day30'];
$day31 = $row['day31'];
}
echo $day1;
在这里,我得到了1月第1天到第31天的值。我该如何解决这个问题?正确地插入分配。
答案 0 :(得分:1)
,您正在引用字段product_id
select * from allocate where product_id =
在您的架构中不存在。另外要按行打印数据,你应该在while循环中有echo
,它会循环遍历你的结果行。