This is the community forum. For a developer response use the Client Area.
Follow us on Facebook, Twitter and YouTube!

Auto populate your comments table
#1

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

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 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
Reply


Possibly Related Threads…
Thread / Author Replies Views Last Post
Last Post by Steven
28-Mar-2023, 12:17 PM
Last Post by noblues
26-Sep-2013, 05:44 PM
Last Post by kooler
02-Aug-2013, 05:29 PM
Last Post by Steven
27-Jan-2013, 09:31 PM
Last Post by Steven
15-Mar-2011, 12:32 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)