Mysql Foreach Loop Syntax
I have a table 'posts' that has all info about my posts. I want to insert
a new row into a different table for all posts that are of type 'public'.
I want to run a query that would look something like this:
$ids = (SELECT post_id FROM posts WHERE post_type = 'public')
foreach($id in $ids){
INSERT INTO new_posts (post_id, post_data) VALUES ($id, 'hello');
}
I know I can insert multiple rows in one sql statement, but I need the
post_id to change for each one and there are too many for me to change it
manually.
What is the correct mysql syntax for this that I can run in my database
manager? (Adminer)
No comments:
Post a Comment