[英]Select max id from table in mysql
I want the code to update the row "image" in my database to the name related to the picture the user chose to upload in their answer on my forum. 我希望代码将数据库中的“图像”行更新为与用户在其论坛中的答案中选择上传的图片相关的名称。
I want the query to take the question_id from the url and chose the highest answer id that is connected to that question_id. 我希望查询从URL中获取question_id,并选择连接到该question_id的最高答案ID。 But the value keeps saying "NULL" it does not update.
但是该值一直说“ NULL”,它不会更新。
$mq = "
UPDATE forum_answers
SET image = '".$_FILES['file']['name']."'
WHERE question_id = '$id'
AND a_id = '(SELECT MAX(a_id) FROM forum_answers)'
'
";
$q = mysqli_query($conn,$mq);
My tables 我的桌子
Table: forum_questions
rows: id, topic, detail, name, datetime, reply, view
Sample value: id=45, topic=hej, detail=haha, name=admin, datetime=25/04/17 04:01:15, view=7, reply=0
Table: forum_answers
rows: question_id, a_id, a_name, a_answer, a_datetime, image
The image row here wont update. 此处的图片行不会更新。
Please check below code. 请检查以下代码。 WIsh it helps
希望有帮助
$file_name = $_FILES['file']['name'];
$mq = "UPDATE forum_answers SET image= '$file_name' WHERE question_id='$id'
AND a_id=(SELECT MAX(a_id) FROM forum_answers)";
$mq = "UPDATE forum_answers SET image = '".$_FILES['file']['name']."' WHERE question_id=$id AND a_id='(SELECT MAX(a_id) FROM forum_answers)''";
请尝试这个question_id是整数类型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.