Link to home
Start Free TrialLog in
Avatar of shruti A
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($result1))
          {
                $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.remark,p.date,user_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.
Avatar of Pawan Kumar
Pawan Kumar
Flag of India image

Not clear to me. Could you please explain more what you are trying to achieve here?
ASKER CERTIFIED SOLUTION
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of shruti A
shruti A

ASKER

@Pawan Kumar whe i executed

insert into message_sent SELECT p.batch_id,p.phone,c.remark,p.date,user_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
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.
just tried for select statement shown 2 rows it is correct
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Change this line and try again

$sql1 = "SELECT DISTINCT remark FROM log";
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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.