25-Feb-2012, 12:25 PM
Hello people,
Small piece of code to auto populate your comments table with empty comment fields / or if you wish a standard text !!!!!
(you first need to have pages in your database).
use at own risk !!!
help/explanation included
Small piece of code to auto populate your comments table with empty comment fields / or if you wish a standard text !!!!!
(you first need to have pages in your database).
use at own risk !!!
help/explanation included
PHP Code:
<?php
// Most users need to run the import file 1 first to populate the pages table first !!!!!!!!!
//script for importing out of your own database and into the table comments of your commentics database.
///////////////////////////////////////////////////////////////////////////////////////////////////////////
// Collecting data out of the table pages and inserting it into the table comments.
$host="127.0.0.1"; // De MySQL host van de server
$gebruiker = "mycommenticsuser_name"; // Your username for MySQL database on server
$wachtwoord = "mycommenticsdatabse password"; // The password for the MySQL database on the server
$dbnaam="mycommentics_databasename"; // The commentics database name on your server
mysql_connect($host, $gebruiker, $wachtwoord); // No need to change
mysql_select_db($dbnaam) or die (mysql_error()); // No need to change
//////////////////////////////////////////////////////////////////////////////////////////////////////////
//connecting to commentics database and gather the info needed to populate the comments table automatically
$id_query =
"SELECT
*
FROM
`pages`
ORDER BY
`id` ASC
";
$id_result = mysql_query($id_query) or die("ERROR: " . mysql_error());
$id_aantal = mysql_num_rows($id_result);
while ($id = mysql_fetch_assoc($id_result)) {
$paginaid = $id["id"];
//this code is the check in your browser wether your page id's are gathered, output should be the same as the number of records in table comments !!
echo('<p><a href="http://www.goedkope-vakanties-boeken.nl/vakantie-frankrijk/">'.$paginaid.'</a></p>');
//
$host="127.0.0.1"; // De MySQL host van de server
$gebruiker = "mycommenticsuser_name"; // Your username for MySQL database on server
$wachtwoord = "mycommenticsdatabse password"; // The password for the MySQL database on the server
$dbnaam="mycommentics_databasename"; // The commentics database name on your server
mysql_connect($host, $gebruiker, $wachtwoord); // No need to change
mysql_select_db($dbnaam) or die (mysql_error()); // No need to change
//edit the insert query below to your own needs.
//1. change the `mycommentics_database` to you own database name.
//2. in this case we do not populate the name, email, website, town etc. since we do not wish to show this in our website.
//if you wish to do this you can create your own version of the insert rule below through your php myadmin panel.
//Simply login to phpmyadmin and add a record (without recordnumber)
//Copy the php myadmin php code ( from insert into >> ending with date/time that is shown in your panel and paste it in the line below.
//make sure that you use the $paginaid that you see below (needed to populate page_id) again !!!!!!!!
mysql_query("INSERT INTO `mycommentics_database`.`comments` (`id`, `name`, `email`, `website`, `town`, `country`, `rating`, `reply_to`, `comment`, `
reply`, `ip_address`, `page_id`, `is_approved`, `approval_reasoning`, `is_admin`, `is_sent`, `sent_to`, `vote_up`, `vote_down`, `is_flagged`, `dated`)
VALUES (NULL, '', '', '', '', '', '0', '0', ' ', '', '', '$paginaid', '1', '', '0', '0', '0', '0', '0', '0', '0000-00-00 00:00:00') ") or die(mysql_error());
mysql_close();
}
//after your done you need to delete this file from your server !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!