$folder_location='uk';
$page_extension='.php';
class DB_Conf { //database setup for the whole script
public static $DB_Config = array(
'DbConfig' => array(
'Hostname' => 'localhost', //database ip
'Username' => 'hurlinghamcliniccouk', //database user name
'Password' => 'j5lA6mAhGIyrgzCd', //database password
'Database' => 'hurlinghamcliniccouk', //database name
)
);
}
class DB_connect{
public static function connect_db(){
$cont = mysqli_init();
mysqli_options($cont,MYSQLI_OPT_CONNECT_TIMEOUT, 30);
mysqli_real_connect($cont,DB_Conf::$DB_Config['DbConfig']['Hostname'], DB_Conf::$DB_Config['DbConfig']['Username'], DB_Conf::$DB_Config['DbConfig']['Password'], DB_Conf::$DB_Config['DbConfig']['Database']);
// echo @mysqli_ping($cont) ? 'true' : 'false';
return $cont;
}
public static function disconnect_db($cont){
mysqli_close($cont);
}
}
$domain= preg_replace('/^www./','',$_SERVER['HTTP_HOST']);
$path = $_SERVER['REQUEST_URI'];
$path = strtok($path, '?');
$path = str_replace('%20',' ',$path);
$path = str_replace('%09',' ',$path);
$path = str_replace('/'.$folder_location,'',$path);
$path = str_replace($page_extension,'',$path);
$base_url='../';
$cont=DB_connect::connect_db();
$query = mysqli_query($cont, "SELECT * FROM `data` WHERE `url`='$path';");
$page_data=mysqli_fetch_assoc($query);
$type_of_page=$page_data['page_type'];
$page_id=$page_data['id'];
$location_links='';
$keyword_link='';
if( $type_of_page==0){
$location_links='';
$keyword_link='';
}
if( $type_of_page==1){
$query = mysqli_query($cont, "SELECT `linked_to` FROM `index` WHERE `page_id`='$page_id' AND `linked_to_type`='2';");
$index_select=array();
while($row=mysqli_fetch_assoc($query)){
$index_select[]=$row;
};
foreach($index_select as $ind){
$this_id=$ind['linked_to'];
$query = mysqli_query($cont, "SELECT `url`,`Heading` FROM `data` WHERE `id`='$this_id';");
$link=mysqli_fetch_assoc($query);
$location_links.='
'.$link['Heading'].' '.PHP_EOL;
}
}
if( $type_of_page==2){
$query = mysqli_query($cont, "SELECT `linked_to` FROM `index` WHERE `page_id`='$page_id' AND `linked_to_type`='1';");
$index_select=array();
while($row=mysqli_fetch_assoc($query)){
$index_select[]=$row;
};
foreach($index_select as $ind){
$this_id=$ind['linked_to'];
$query = mysqli_query($cont, "SELECT `url`,`Heading` FROM `data` WHERE `id`='$this_id';");
$link=mysqli_fetch_assoc($query);
$keyword_link.=''.$link['Heading'].' '.PHP_EOL;
}
}
if( $type_of_page==3){
$query = mysqli_query($cont, "SELECT `linked_to` FROM `index` WHERE `page_id`='$page_id' AND `linked_to_type`='1';");
$index_select=array();
while($row=mysqli_fetch_assoc($query)){
$index_select[]=$row;
};
foreach($index_select as $ind){
$this_id=$ind['linked_to'];
$query = mysqli_query($cont, "SELECT `url`,`Heading` FROM `data` WHERE `id`='$this_id';");
$link=mysqli_fetch_assoc($query);
$keyword_link.=''.$link['Heading'].' '.PHP_EOL;
}
$query = mysqli_query($cont, "SELECT `linked_to` FROM `index` WHERE `page_id`='$page_id' AND `linked_to_type`='2';");
$index_select=array();
while($row=mysqli_fetch_assoc($query)){
$index_select[]=$row;
};
foreach($index_select as $ind){
$this_id=$ind['linked_to'];
$query = mysqli_query($cont, "SELECT `url`,`Heading` FROM `data` WHERE `id`='$this_id';");
$link=mysqli_fetch_assoc($query);
$location_links.=''.$link['Heading'].' '.PHP_EOL;
}
}
if( $type_of_page==4){
$base_page_id=$page_data['base_page'];
$query = mysqli_query($cont, "SELECT `page_type`, `url` FROM `data` WHERE `id`='$base_page_id';");
$base_page=mysqli_fetch_assoc($query);
$base_url='/'.$folder_location.$base_page['url'];
$base_type=$base_page['page_type'];
##query the top level page
##get the type of page and the id from it
##get the data from the index
if( $base_type==1){
$query = mysqli_query($cont, "SELECT `linked_to` FROM `index` WHERE `page_id`='$base_page_id' AND `linked_to_type`='2';");
$index_select=array();
while($row=mysqli_fetch_assoc($query)){
$index_select[]=$row;
};
foreach($index_select as $ind){
$this_id=$ind['linked_to'];
$query = mysqli_query($cont, "SELECT `url`,`Heading` FROM `data` WHERE `id`='$this_id';");
$link=mysqli_fetch_assoc($query);
$location_links.=''.$link['Heading'].' '.PHP_EOL;
}
}
if( $base_type==2){
$query = mysqli_query($cont, "SELECT `linked_to` FROM `index` WHERE `page_id`='$base_page_id' AND `linked_to_type`='1';");
$index_select=array();
while($row=mysqli_fetch_assoc($query)){
$index_select[]=$row;
};
foreach($index_select as $ind){
$this_id=$ind['linked_to'];
$query = mysqli_query($cont, "SELECT `url`,`Heading` FROM `data` WHERE `id`='$this_id';");
$link=mysqli_fetch_assoc($query);
$keyword_link.=''.$link['Heading'].' '.PHP_EOL;
}
}
if( $base_type==3){
$query = mysqli_query($cont, "SELECT `linked_to` FROM `index` WHERE `page_id`='$base_page_id' AND `linked_to_type`='1';");
$index_select=array();
while($row=mysqli_fetch_assoc($query)){
$index_select[]=$row;
};
foreach($index_select as $ind){
$this_id=$ind['linked_to'];
$query = mysqli_query($cont, "SELECT `url`,`Heading` FROM `data` WHERE `id`='$this_id';");
$link=mysqli_fetch_assoc($query);
$keyword_link.=''.$link['Heading'].' '.PHP_EOL;
}
$query = mysqli_query($cont, "SELECT `linked_to` FROM `index` WHERE `page_id`='$base_page_id' AND `linked_to_type`='2';");
$index_select=array();
while($row=mysqli_fetch_assoc($query)){
$index_select[]=$row;
};
foreach($index_select as $ind){
$this_id=$ind['linked_to'];
$query = mysqli_query($cont, "SELECT `url`,`Heading` FROM `data` WHERE `id`='$this_id';");
$link=mysqli_fetch_assoc($query);
$location_links.=''.$link['Heading'].' '.PHP_EOL;
}
}
}
if($page_data['lat']==0){
$page_data['lat']='0';
$page_data['long']=52;
}
#take the page
#find in the pages
#look at the link structure and get the required links
#read the has reviews in order to search for reviews for the pages that are created
#if its not there create some sort of a 404 page that will try to direct you to the correct place.
DB_connect::disconnect_db($cont);
?>
echo $page_data['meta_title']; ?>
echo $page_data['content']; ?>