Wednesday, March 6, 2019

php - Mysqli SELECT INSERT and UPDATE Query simulatenously

Hello I have a Database named as "admin" in which i have two tables
Table 1 Name = "register"
Table 2 Name = "noti"




In Register Table i've approx more than 10+ User entries which comes through Registration Page
In Noti Table, its empty at this time (Column Name is also "noti")



I want to perform this thing
First I want to count the total no. of records in "register" table
and it checks, if the records are greater than ZERO then it runs the INSERT query otherwise it runs the UPDATE Query



And i want to INSERT and UPDATE that count value into "noti" table



Here's my code




include('config.php');
$sql2 = "SELECT count(*) as count FROM register";
$result2 = mysqli_query($con, $sql2);
if($result2->num_rows>0)
{
while($rw1=$result2->fetch_array())
{
$value1 = $rw1['count'];


$result = mysqli_query($con, "SELECT count(*) as count FROM register ");

if(!empty($value1)) {
mysqli_query($con, "UPDATE noti SET noti = '$value1' ");
}
else
{
mysqli_query($con, "INSERT INTO noti(noti) VALUES ('$value1') ");
}

}
}
?>

No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...