Wednesday 6 March 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

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...