Shalini Shalini - 3 years ago 147
PHP Question

how to run update query for all values fetch by previous query

I want to run an sql select query which fetches P_no and after that an update query is run for it. It always update only 1 value.

$d=date('Y-m-d');
$qu="select P_no from date_summary where `Nextcall_1`='$d' or
`Nextcall_2`='$d' or `Nextcall_3`='$d' or `Nextcall_4`='$d'
or`Nextcall_5`='$d' or `Nextcall_6`='$d' or `Nextcall_7`='$d' or
`Nextcall_8`='$d' or `Nextcall_9`='$d' or `Nextcall_10`='$d' or
`Nextcall_11`='$d'";
$res=mysqli_query($con,$qu);
if($res && mysqli_num_rows($res)>0)
{
while($row=mysqli_fetch_assoc($res))
{
$p1=$row["P_no"];
$qu="update notification_status set Noti_status='Unchecked' where
P_no=$p1";
$res=mysqli_query($con,$qu);
}
}

Answer Source

You could use the in operator:

UPDATE notification_status
SET    noti_status='Unchecked'
WHERE  p_no IN (SELECT p_no FROM date_summary WHERE /* etc... */)
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download