0

I'm trying to develop a PHP script that notifies premium members of changes made to certain features of my website but I'm not sure how to add the multiple records to the notifications table. What I have is:

    $get_pro_sql = "SELECT id FROM members WHERE pro = '1'";
    $get_pro_res = mysqli_query($con, $get_pro_sql);

while($row = mysqli_fetch_assoc($get_pro_res){
    $memberid = $row["id"];
}
$message = "My New Message";
foreach($row){



    $insert_note_sql = "INSERT INTO notes(id, recipient, message, ..., ...) VALUES('', 'Member_Id__Returned_From_Previous_Query', '$message')";
    $insert_note_res = mysqli_query($con, $insert_note_sql);
    // Inserts 5 Records

Any ideas on how this can be achieved?

1 Answer 1

1

You could this by using a sub query to insert multiple rows.

Actually you can achieve it like this:

INSERT INTO Results (People, names )
   SELECT d.id, 'Henry'
   FROM Names f
   JOIN People d ON d.id  = f.id

In the subquery you can select the actual values to be inserted.

More on this topic here

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.