ProdigySim
04-22-2004, 07:53 AM
I can write the queries from scratch, I guess, but it would be easier to do this in some sort of loop.
I have a table (mt_template) where multiple rows have the field template_blog_id = 1
I can give a screenshot of the tables if needed, but here's an idea of what one will be like:
template_id = 1, template_blog_id = 6, template_name = index, template_text = <lots of HTML>, etc, etc.
template_id = 2. template_blog_id = 6, template_name = atom, template_text = <different HTML>, etc, etc.
Anyway, I want to grab every row where template_blog_id = 6 and re-enter it with a different template_blog_id.
What I have right now is something like this, but it's not working.....
while( $rows = mysql_fetch_assoc(mysql_query('SELECT * FROM mt_template WHERE template_blog_id = "6";'))) {
$query = mysql_query('INSERT INTO mt_template (template_blog_id, template_name, template_text, etc. etc. etc.)
VALUES (
"' . $newblogid . '", "' . $rows['template_name'] . '", "' . $rows['template_text'] . '", "' $rows['etc'] . '");');
if(!$query) {
echo mysql_error();
}
}
Now, that just gives me an infinite loop and only uses ONE of the rows, trying to insert it over and over again... Am I not using the $rows variable (an associative array) right?
Can anyone tell me what is wrong?
I have a table (mt_template) where multiple rows have the field template_blog_id = 1
I can give a screenshot of the tables if needed, but here's an idea of what one will be like:
template_id = 1, template_blog_id = 6, template_name = index, template_text = <lots of HTML>, etc, etc.
template_id = 2. template_blog_id = 6, template_name = atom, template_text = <different HTML>, etc, etc.
Anyway, I want to grab every row where template_blog_id = 6 and re-enter it with a different template_blog_id.
What I have right now is something like this, but it's not working.....
while( $rows = mysql_fetch_assoc(mysql_query('SELECT * FROM mt_template WHERE template_blog_id = "6";'))) {
$query = mysql_query('INSERT INTO mt_template (template_blog_id, template_name, template_text, etc. etc. etc.)
VALUES (
"' . $newblogid . '", "' . $rows['template_name'] . '", "' . $rows['template_text'] . '", "' $rows['etc'] . '");');
if(!$query) {
echo mysql_error();
}
}
Now, that just gives me an infinite loop and only uses ONE of the rows, trying to insert it over and over again... Am I not using the $rows variable (an associative array) right?
Can anyone tell me what is wrong?
