martin_fell Posted March 21, 2007 Share Posted March 21, 2007 I'm building a mysql powered blog. I'm putting all the entries in one database (which will get huge), and I want to use a small database to show the latest 11 posts. My code is driving me crazy. The entries are added to the first database, the top 11 entries seem to be counted and stuck in $res. Then it all falls apart. There are no errors, but nothing is added to the second databse. Below is the code. Kind regards Martin <?php //what if? if ($HTTP_POST_VARS['submit']) { //open the database //get input from the form and make up the rest $post_author= "martin_fell"; $post_date= date ("F j".", "."Y"); $post_title= $HTTP_POST_VARS['post_title']; $post_synopsis= $HTTP_POST_VARS['post_synopsis']; $post_body= $HTTP_POST_VARS['post_body']; //parse user input $post_title= mysql_real_escape_string ($post_title); $post_synopsis= mysql_real_escape_string ($post_synopsis); $post_body= mysql_real_escape_string ($post_body); //insert the post into main table $res= mysql_query ("INSERT INTO blog_entries (post_author, post_date, post_title, post_synopsis, post_body) VALUES ('$post_author', '$post_date', '$post_title', '$post_synopsis', '$post_body')"); //empty the blog_entries_latest table $res= mysql_query ("DELETE FROM blog_entries_latest WHERE post_author=$post_author"); //get the latest 11 posts from the main table $res= mysql_query ("SELECT * FROM blog_entries ORDER BY post_time_stamp DESC LIMIT 11"); $num= mysql_num_rows($res); //insert the latest 11 into blog_entries_latest table for ($i=0; $i<$num; $i++) { $row= mysql_fetch_row ($res); $res2= mysql_query ("INSERT INTO blog_entries_latest (post_author, post_date, post_title, post_synopsis, post_body) VALUES ($row[0], $row[2], $row[3], $row[4], $row[5])"); } } //and relax ?> Link to comment https://forums.phpfreaks.com/topic/43661-solved-moving-things-around/ Share on other sites More sharing options...
martin_fell Posted March 21, 2007 Author Share Posted March 21, 2007 I solved it. Thank ***k. the new code is as such //insert the latest 11 into blog_entries_latest table for ($i=0; $i<$num; $i++) { $row= mysql_fetch_row ($res); echo $row[0] . " " . $row[1] . " " . $row[2] . " " . $row[3] . " " . $row[4] . " " . $row[5] . " " . $row[6]; $post_id= $row[0]; $post_author= $row[1]; $post_time_stamp= $row[2]; $post_date= $row[3]; $post_title= $row[4]; $post_synopsis= $row[5]; $post_body= $row[6]; $res2= mysql_query ("INSERT INTO blog_entries_latest (post_author, post_time_stamp, post_date, post_title, post_synopsis, post_body) VALUES ('$post_author', '$post_time_stamp', '$post_date', '$post_title', '$post_synopsis', '$post_body')"); } } Link to comment https://forums.phpfreaks.com/topic/43661-solved-moving-things-around/#findComment-211997 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.