gpt4 book ai didi

php - 从数据库中获取行式数据

转载 作者:行者123 更新时间:2023-11-29 00:27:32 26 4
gpt4 key购买 nike

我有一个像这样名为allocate的表

CREATE TABLE allocate(
mid int(10),
pid int(20),
day1 int(2),
day2 int(2),
...
day31 int (2)
);

mid 中,我有一个对应于月份的数字(1 是一月,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 天的值。我该如何解决这个问题?正确地插入到分配中。

最佳答案

在您的 sql 查询中,您指的是字段 product_id

select * from allocate where product_id = 

在您的架构中不存在。另外,要按行打印数据,您应该在 while 循环中包含 echo,它会按行循环遍历您的结果。

关于php - 从数据库中获取行式数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18265110/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com