Php 如果其他条件不能正常工作,为什么会出现这种情况?
我在foreach循环中使用if-else条件来检查和插入新标记 但是这两个条件(if和alse)都是同时应用的,而不管mysql find id是否等于foreach posted id。Plz helpPhp 如果其他条件不能正常工作,为什么会出现这种情况?,php,mysql,if-statement,Php,Mysql,If Statement,我在foreach循环中使用if-else条件来检查和插入新标记 但是这两个条件(if和alse)都是同时应用的,而不管mysql find id是否等于foreach posted id。Plz help $new_tags = $_POST['new_tags']; //forget the mysl security for the time being foreach ($new_tags as $fnew_tags) { $sqlq = mysqli_query($
$new_tags = $_POST['new_tags']; //forget the mysl security for the time being
foreach ($new_tags as $fnew_tags)
{
$sqlq = mysqli_query($db3->connection, "select * from o4_tags limit 1");
while($rowq = mysqli_fetch_array($sqlq)) {
$id = $rowq['id'];
if($id == $fnew_tags) { //if ID of the tag is matched then do not insert the new tags but only add the user refrence to that ID
mysqli_query($db3->connection, "insert into user_interests(uid,tag_name,exp_tags) values('$session->userid','$fnew_tags','1')");
}
else
{ //if ID of the tag is not matched then insert the new tags as well as add the user refrence to that ID
$r = mysqli_query($db3->connection, "insert into o4_tags(tag_name,ug_tags,exp_tags) values('$fnew_tags','1','1')");
$mid_ne = mysqli_insert_id($db3->connection);
mysqli_query($db3->connection, "insert into user_interests(uid,tag_name,exp_tags) values('$session->userid','$mid_ne','1')");
}
}
}
我想你是在插话
$r = mysqli_query($db3->connection, "insert into o4_tags(tag_name,ug_tags,exp_tags)
values('$fnew_tags','1','1')");$mid_ne = mysqli_insert_id($db3->connection);
然后使用while($rowq=mysqli\u fetch\u数组($sqlq))
它现在有您刚才插入的记录,因此您的if将被执行我很确定下面的
选择
查询将始终返回相同的记录
$sqlq = mysqli_query($db3->connection, "select * from o4_tags limit 1");
我想大部分时间它都会转到执行2 insert的else
。
您不应该像下面这样编写查询吗
select * from o4_tags where id = $fnew_tags limit 1
我不认为if/else的两个部分都被执行了。尝试在控制台中打印某些内容,而不是在查询中打印,这很可能是if/else中的代码错误。在检查之前,请尝试打印$id$fnew_标记值