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

Auto populate your pages table
#1

Hello people,

for those of you with dynamic sites that wish to auto populate the pages table here is a script that can do it.

You need to have some understanding of php and sql, but help is included between the lines.

Change the queries to your situation / wishes.
in the example we connect to 2 tables, but if you store your url structure info in less or more you can copy it several times.

PHP Code:
<?php 
//script that connect to your main website database and inserts into commentics table
//script gathers main website url structure and inserts it into your commentics pages table.
// You need to have a good understanding of php and sql, use at own risk!!!
// You need to edit the queries to your situation !!!!!!!!!!!!!!!!!!!!!!!!!!!!!

//DATABASE VARIABLES connecting to database 1 (main website for importing all urls)

$host="127.0.0.1"; // MySQL host server
$gebruiker = "mainwebsite_db"; // Username MySQL database on server change to your own
$wachtwoord = "password"; // Password for accessing database change to your own
$dbnaam="mydatabase_name"; // Name of database on your server change to your own

mysql_connect($host, $gebruiker, $wachtwoord); // No need to change
mysql_select_db($dbnaam) or die (mysql_error()); // No need to change


///////////////////////////////////////////////////////////////////////////////////////////////////////////
//Our dynamic website has 4 tables that contain varibiables used to create urls in ouw main site
//In this posting we only show 2 imports - connections being made
//You can adjust this to your needs


// import 1
$regio_query =
"SELECT
*
FROM
`regios`
ORDER BY
`regionaam` ASC
"
;

$regio_result = mysql_query($regio_query) or die("FOUT: " . mysql_error());
$regio_aantal = mysql_num_rows($regio_result);


while (
$regio = mysql_fetch_assoc($regio_result)) {
$regionaampje = ereg_replace(' ', '-', $regio["regionaam"]);
$regiotje = strtolower($regionaampje);
$regios = $regio["regionaam"];
echo(
'<p><a href="http://www.mywebsite.nl/vakantie-frankrijk/'.strtolower($regionaampje).'/">' . $regio["regionaam"] . '</a></p>');

$host2="127.0.0.1"; // De MySQL host of server
$gebruiker2 = "commentics_username"; // username of MySQL database for commentics on your server change to your own
$wachtwoord2 = "commenticpassword"; // Password MySQL database on server
$dbnaam2="commentics_db"; // Database name for commentics on your server

mysql_connect($host2, $gebruiker2, $wachtwoord2); // No need to edit
mysql_select_db($dbnaam2) or die (mysql_error()); // No need to edit

//change line 52 commentics_database to your own database name
mysql_query("INSERT INTO `commentics_database`.`pages` (
`id` ,
`custom_id` ,
`reference` ,
`url` ,
`is_form_enabled` ,
`dated`
)
VALUES (
NULL , '
$regios', 'http://www.mywebsite.nl/vakantie-frankrijk/$regiotje/', '
http://www.mywebsite.nl/vakantie-frankrijk/
$regiotje/', '0', '2012-02-16 12:23:48') ") or die(mysql_error());

mysql_close();
}

/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

//step - import 2

$host="127.0.0.1"; // MySQL host server
$gebruiker = "mainwebsite_db"; // Username MySQL database on server change to your own
$wachtwoord = "password"; // Password for accessing database change to your own
$dbnaam="mydatabase_name"; // Name of database on your server change to your own

mysql_connect($host, $gebruiker, $wachtwoord); // No need to change
mysql_select_db($dbnaam) or die (mysql_error()); // No need to change

//you need to edit / make your own query to get the info/output you wish to import

$select = "SELECT * FROM mydatabase GROUP BY plaats ASC";
$exec = mysql_query($select) or die ('Ojee, foutieve query! '.mysql_error());

while(
$plaats = mysql_fetch_array($exec)){
$link = ereg_replace(' ', '-', $plaats['plaatstitel']);
$campingkje = 'campings';
$campingslinkje = ereg_replace(' ', '-', $plaats['campingnaam']);
$plaatsje = strtolower($link);
$plaatstitel = ($plaats['plaatstitel']);
$regionaampje = ereg_replace(' ', '-', $plaats["departement"]);
$regiotje = strtolower($regionaampje);


echo (
'<p><a href="http://www.mywebsite.nl/vakantie-frankrijk/'.$regiotje.'/'.strtolower($link).'"
title="Vakantie in '
.$plaats['plaats']. '">' .$plaats['plaatstitel']. '</a></p>');

$host2="127.0.0.1"; // De MySQL host of server
$gebruiker2 = "commentics_username"; // username of MySQL database for commentics on your server change to your own
$wachtwoord2 = "commenticpassword"; // Password MySQL database on server
$dbnaam2="commentics_db"; // Database name for commentics on your server

mysql_connect($host2, $gebruiker2, $wachtwoord2); // No need to edit
mysql_select_db($dbnaam2) or die (mysql_error()); // No need to edit

//change line 52 commentics_database to your own database name
mysql_query("INSERT INTO `commentics_database`.`pages` (
`id` ,
`custom_id` ,
`reference` ,
`url` ,
`is_form_enabled` ,
`dated`
)
VALUES (
NULL , '
$plaatstitel', 'http://www.mywebsite.nl/vakantie-frankrijk/$regiotje/$plaatsje', '
http://www.mywebsite.nl/vakantie-frankrijk/
$regiotje/$plaatsje', '0', '2012-02-16 12:23:48') ") or die(mysql_error());

mysql_close();



}
Reply


Possibly Related Threads…
Thread / Author Replies Views Last Post
Last Post by Steven
19-Jun-2017, 08:04 PM
Last Post by kooler
02-Aug-2013, 05:29 PM
Last Post by Norbs
05-Dec-2011, 03:05 PM
Last Post by Steven
15-Mar-2011, 12:32 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)