shruti A
asked on
query is affecting 4 rows instead of 2
$sql1 = "SELECT remark FROM log";
$result1 = mysqli_query($db, $sql1);
while($row1 = mysqli_fetch_assoc($result 1))
{
$remark=($row1['remark']);
$word = "success";
if (stripos($remark,$word)!== false)
{
$ins = mysqli_query($db,'insert into message_sent SELECT p.batch_id,p.phone,c.remar k,p.date,u ser_id FROM to_numbers p INNER JOIN log c ON c.phone = p.phone');
}
}
here i'm executing this query when I execute only sql statement it will affect 2 rows it is correct, If i executed above code it is affecting 4 rows so where is going wrong how can i solve this.
$result1 = mysqli_query($db, $sql1);
while($row1 = mysqli_fetch_assoc($result
{
$remark=($row1['remark']);
$word = "success";
if (stripos($remark,$word)!==
{
$ins = mysqli_query($db,'insert into message_sent SELECT p.batch_id,p.phone,c.remar
}
}
here i'm executing this query when I execute only sql statement it will affect 2 rows it is correct, If i executed above code it is affecting 4 rows so where is going wrong how can i solve this.
Not clear to me. Could you please explain more what you are trying to achieve here?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
@Pawan Kumar whe i executed
insert into message_sent SELECT p.batch_id,p.phone,c.remar k,p.date,u ser_id FROM to_numbers p INNER JOIN log c ON c.phone = p.phone'
above code in sql on phpmyadmin it works properly
when i executed with php code it not working properly affecting extra rows
insert into message_sent SELECT p.batch_id,p.phone,c.remar
above code in sql on phpmyadmin it works properly
when i executed with php code it not working properly affecting extra rows
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
As far as SQL is concerned this looks fine to me. I request you to check the PHP code, there might be an issue there.
ASKER
just tried for select statement shown 2 rows it is correct
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Change this line and try again
$sql1 = "SELECT DISTINCT remark FROM log";
$sql1 = "SELECT DISTINCT remark FROM log";
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Presumably, the SELECT within the INSERT has 2 records; thus each INSERT results in n*2 records; in this case, 2*2=4 records are being inserted. Without further information from OP, it is presumed that this logic error has been corrected by these answers.