我无法弄清楚为什么这段代码不起作用。我试图创建一个临时表并将一些数据拉入其中,然后过滤掉一些数据。但我似乎无法回应数据它只是回应列名称。这是代码:
if (!$conn) {
echo "<a href='getschedule.php'><button>Go Back</button></a>";
die("Connection failed: " . mysqli_connect_error());
}else{
echo "Connected successfully<br><br>";
}
$seasontemp = "CREATE TEMPORARY TABLE seasontemp (
id int NOT NULL,
firstname varchar(255),
lastname varchar(255),
number varchar(255),
address varchar(255),
plan_start date NOT NULL,
plan_comp int(11),
plan_skip int(11),
trim_start date,
trim_comp int(11),
trim_skip int(11),
spray_start date,
spray_comp int(11),
PRIMARY KEY(id)
)";
mysqli_query($conn, $seasontemp) or die ("Sql error : ".mysqli_error($conn));
$insertseason = "INSERT INTO seasontemp
(id, plan_start, plan_comp, plan_skip, trim_start, trim_comp, spray_start, spray_comp)
SELECT id, plan_start, plan_comp, plan_skip, trim_start, trim_comp, spray_start, spray_comp
FROM services WHERE plan='17'";
mysqli_query($conn, $insertseason) or die ("Sql error : ".mysqli_error($conn));
$seasonids = "SELECT 'id', 'plan_start' FROM seasontemp";
$r1 = mysqli_query($conn, $seasonids ) or die ("Sql error : ".mysqli_error($conn));
if(mysqli_num_rows($r1) > 0){
$start = mysqli_fetch_assoc($r1);
$start_date = $start['plan_start'];
echo $start_date;
}
mysqli_close($conn);
答案 0 :(得分:1)
"SELECT 'id', 'plan_start' FROM seasontemp";
将其替换为:
"SELECT `id`, `plan_start` FROM seasontemp"; // wrong quotes added here.
答案 1 :(得分:1)
将"SELECT 'id', 'plan_start' FROM seasontemp";
替换为"SELECT id, plan_start FROM seasontemp";
注意:删除单引号的字段,否则使用&#34;`&#34;不是&#34;&#39;&#34;。
答案 2 :(得分:0)
您检查您的插入查询是否正确?
$insertseason = "INSERT INTO seasontemp
(id, plan_start, plan_comp, plan_skip, trim_start, trim_comp, spray_start, spray_comp)
SELECT id, plan_start, plan_comp, plan_skip, trim_start, trim_comp, spray_start, spray_comp
FROM services WHERE plan='17'";
我认为错误的插入查询。纠正它