script working locally but not online
Posted: Sun Apr 11, 2010 4:05 pm
Hi there,
I'm new to PHP but managed to get this script working lovely locally, very pleased with myslef...then I uploaded it...and nothing is displayed in that area! the site is http://www.tyrefinders.co.uk/testing/index.php.
The scripts uses the name of the current page ($thisPage), uses regex to take out caps and spaces, adds "_paragraphs" to the now lowercase and one word page name. This relates to the name of the table in the database, then the results are looped.
I'm too inexperienced to know why it isn't working live, can anyone spot a possible reason? Maybe something to do with the regex?? The first chunk- connect to server and select database works because its used elsewhere in the site.
Thanks for your time!
Geoff
I'm new to PHP but managed to get this script working lovely locally, very pleased with myslef...then I uploaded it...and nothing is displayed in that area! the site is http://www.tyrefinders.co.uk/testing/index.php.
The scripts uses the name of the current page ($thisPage), uses regex to take out caps and spaces, adds "_paragraphs" to the now lowercase and one word page name. This relates to the name of the table in the database, then the results are looped.
I'm too inexperienced to know why it isn't working live, can anyone spot a possible reason? Maybe something to do with the regex?? The first chunk- connect to server and select database works because its used elsewhere in the site.
Code: Select all
<?php
// connect to db
require_once 'a/inc/login.php';
$db_server = mysql_connect($db_hostname, $db_username, $db_password);
// unable to connect
if (!$db_server) die("unable to connect to MYSQL: " . mysql_error());
// select db
mysql_select_db($db_database)
or die("unable to select database: " . mysql_error());
// regulars expressions to find spaces, tabs, newlines etc
$sPattern = '/\s*/m';
// replace spaces, tabs or whatever with no space
$sReplace = '';
// apply expressions and replace to a string and assign to a variable
$thisPage_no_space = preg_replace( $sPattern, $sReplace, $thisPage );
// assign table value with page name
$table = $thisPage_no_space . "_paragraphs";
// get data
$query="SELECT * FROM $table";
$result=mysql_query($query);
// find the ammount of rows
$num=mysql_numrows($result);
mysql_close();
// loop results until number or rows is reached
$i=0;
while ($i < $num) {
// assign selected results to variables
$heading=mysql_result($result,$i,"heading");
$paragraph=mysql_result($result,$i,"paragraph");
echo "<img src=\"a/images/content_left_top.gif\" width=\"475\" height=\"10\" alt=\"top\" />
<div class=\"content_text\"><img src=\"a/images/content_tittle_arrows.gif\" width=\"20\" height=\"9\" alt=\"arrows\" /><h2>$heading</h2>
<p>$paragraph</p>
</div><!-- close content_text -->
<img class=\"bottom15\" src=\"a/images/content_left_bottom.gif\" width=\"475\" height=\"10\" alt=\"top\" />";
if ($i==0) {
echo "<img src=\"a/images/tyres_exhausts_tracking_batteries.gif\" width=\"475\" height=\"70\" alt=\"Tyres Exhausts Tracking Batteries\" />";
}
$i++;
}
?>Geoff