Well, the table layout I'm getting the data from is all right there. The sequence goes like this, for each loop (each loop is one comment) I query the database which I get the data from and store all the information in strings.
Then, I query the table the contains all the journal posts and I retrieve the GMT time/date of the post that this comment belongs to.
$query_date = "SELECT post_date_gmt FROM $wp_tables[posts] where ID='$post_ID'";
$result_date = mysql_query($query_date);
$row_date = mysql_fetch_array($result_date);
I then convert this time into a timestamp, example: 20040807200532 (year/month/date/hour/minute/seconds). This is the table ID that I want to store the previous query's data in.
$comment_table_id = gmdate("YmdHis" ,strtotime($row_date['post_date_gmt'])+(((gmdate('
I'))?($tz_offset+1):$tz_offset)*3600));
Now that I have the table's ID, I can query the new table and put in the data from the old table.
// first, connect to the new database
eb_Connect();
// then, insert the data into the table
$queryb = "INSERT INTO $eb_tables[comments]_$comment_table_id (id,dt,name,url,email,entry,remote_ip)
VALUES ('$comment_id','$dt','$author','$url','$email','$e
ntry','$ip')";
if (@mysql_query($queryb)) {
echo "<p>Successfully imported</p>";
} else {
echo "<p>Failed to import</p>";
}
Now before the loop ends, I need to reconnect to the first database
wp_connect();
So far, everything works fine..... but when it comes to the point where it needs to put more than 1 output in the new tables, it fails.
Here's an example:
I have 3 journal entries in one table, and 6 comments in another table. Each comment has a field ('comment_post_ID') that links it to the ID of the journal entry it belongs to. If each entry has two comments, it will only import the first comment for each entry and fail when it comes to importing the second comment.
Now, I've done the same query without trying to store it in a new database and it works fine. It brings back all the comments and I can print them to the screen using the same script and some echo commands. I just can't figure out why it fails when I try to store it.