gpt4 book ai didi

php - 可以在获取数组中使用插入查询

转载 作者:行者123 更新时间:2023-11-30 22:59:57 27 4
gpt4 key购买 nike

我不确定为什么这个问题还没有得到回答,据我所知,我想知道是否可以在我试过的 while 循环中添加一个插入查询,但它会不断插入更多评论(如果它发现 4 个状态更新,它将在数据库中发布评论 4 次)

我知道我有两次插入查询,这不是问题,因为我有查询向数据库提交评论,当前查询用于测试目的。

<?php
require_once ("core/connection.php");
require_once ("core/group_functions.php");



//We need to post the message update in to the database
if(isset($mybb->input['post_message_submit'])) {
$post_message_submit = $mybb->input['post_message_submit'];
$post_message = $mybb->input['post_message'];
$comment_post = $mybb->input['comment_post'];
if(($post_message_submit) && ($post_message)) {


$insert_query = $db->query("INSERT INTO " . TABLE_PREFIX . "groups_posts" . "(posted_by, group_name, post_body)
VALUES ('$mybb_username', '$get_group_url' ,'$post_message')");


} else {
echo "<text style='color:red;'> You Must Specify A Message</a></text>";
}
}



echo "
<form action='' method='POST'>
<textarea name='post_message' id='post_message' placeholder='Whats Going On?'></textarea><br>
<input type='submit' name='post_message_submit' value='Post'>
</form>

";


$fetch_index_query = $db->query("SELECT post_id,posted_by,post_body,post_active,group_name FROM " . TABLE_PREFIX . "groups_posts WHERE group_name='$get_group_url'");





while($fetch_index_groups_array = $db->fetch_array($fetch_index_query)) {
$post_id_row = $fetch_index_groups_array['post_id'];
$posted_by = $fetch_index_groups_array['posted_by'];
$g_name = $_fetch_index_groups_array['g_name'];
$g_body = $fetch_index_groups_array['post_body'];
echo"<br>" . "<a href=''> $posted_by </a>" . "<br>" . $gname
. "<br>____________";


$fetch_comments_query = $db->query("SELECT g_name,post_body,comment_by FROM spud_groups_comments WHERE post_id='$post_id_row'");
while($fetch_groups_comments = $db->fetch_array($fetch_comments_query)) {
$post_body = $fetch_groups_comments['post_body'];
echo ("<br>" . $post_body);




}

$insert_query2 = $db->query("INSERT INTO " . TABLE_PREFIX . "groups_comments" . "(comment_by, post_id, post_body)
VALUES ('$mybb_username', '$post_id_row' ,'$comment_post')");




echo "<br>
<form action='' method='POST'>
<input type='text' name='comment_post' placeholder='Comment then Hit Enter'>
</form>
";





}

//We have done everything we need to do we can now exit and not execute anything beyond this point
exit();
?>

最佳答案

尝试为插入查询实例化其他 $DB 对象。即不要使用您用来获取数组的同一个查询,因为下一次使用将覆盖您正在循环的第一个查询的结果。

关于php - 可以在获取数组中使用插入查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24544083/

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