Can this be done? (html + database)
Discussion
I've got a database that contains prices for a wesbite, the prices are displayed on the page via some javascript (we paste a line of JS on the page for the pricing & stock info). The price renders OK in the browser but if you view source code the price is not there, just the JS that then gives the price (makes sense). What I'm now looking at doing is implementing schema org data by way of meta tags. What I'd like to know is can this be done via the existing database? ie, can I just add a line of code to the html pages like <meta itemprop="price" content="£10.00"> where the £10.00 part would be pulled from the DB?? (so there would be soemthing like <?php echo $price; ?> in the inverted commas of the content=)
??
or is it time to start again??
TIA
??
or is it time to start again??
TIA
If I've understood correctly then that's something you would usually do with PHP rather than Javascript. PHP is run on the server before the page is served to the browser, whereas Javascript runs as the page is loading which is why Javascript source can be viewed in the browser (but PHP cannot).
Dave_ST220 said:
The problem I have is all pages are html rather than php. I guess I could look at changing all pages then using an htaccess rule to cover the change from html to php extensions??
Not really, the PHP runs on the server then dishes up the HTML.You'd be better off doing it 'correctly'.
A basic db driven PHP site isn't much more difficult to build than an HTML one.
When you say "a database" what do you mean ?
I'l guessing this isn't a database in the normal sense of the word (MySQL for example) but maybe a json/csv file containing all the prices
Also I'm not sure what the problem is you're trying to solve, is it for google shopping search or similar - depending on what the problem is there might be other ways to solve this rather than PHP
I'l guessing this isn't a database in the normal sense of the word (MySQL for example) but maybe a json/csv file containing all the prices
Also I'm not sure what the problem is you're trying to solve, is it for google shopping search or similar - depending on what the problem is there might be other ways to solve this rather than PHP
WinstonWolf said:
Dave_ST220 said:
The problem I have is all pages are html rather than php. I guess I could look at changing all pages then using an htaccess rule to cover the change from html to php extensions??
Not really, the PHP runs on the server then dishes up the HTML.You'd be better off doing it 'correctly'.
A basic db driven PHP site isn't much more difficult to build than an HTML one.
cornet said:
When you say "a database" what do you mean ?
I'l guessing this isn't a database in the normal sense of the word (MySQL for example) but maybe a json/csv file containing all the prices
Also I'm not sure what the problem is you're trying to solve, is it for google shopping search or similar - depending on what the problem is there might be other ways to solve this rather than PHP
It's a MySQL database.I'l guessing this isn't a database in the normal sense of the word (MySQL for example) but maybe a json/csv file containing all the prices
Also I'm not sure what the problem is you're trying to solve, is it for google shopping search or similar - depending on what the problem is there might be other ways to solve this rather than PHP
Dave_ST220 said:
WinstonWolf said:
Dave_ST220 said:
The problem I have is all pages are html rather than php. I guess I could look at changing all pages then using an htaccess rule to cover the change from html to php extensions??
Not really, the PHP runs on the server then dishes up the HTML.You'd be better off doing it 'correctly'.
A basic db driven PHP site isn't much more difficult to build than an HTML one.
Is your file being parsed by php?
http://stackoverflow.com/questions/7181853/parse-h...
Discusses the why's and wherefores of how to do it.
What do you get in the source when you add the echo statement?
http://stackoverflow.com/questions/7181853/parse-h...
Discusses the why's and wherefores of how to do it.
What do you get in the source when you add the echo statement?
It isn't no, which I guess explains that! Quick read reveals this can be done in htaccess, is that the best & only method? Or can some code be added to the actual HTML pages in question? Thanks for your help so far!!! It's a great help
ETA, all I get in the source when it's added is exactly what I added! It doesn't show on the page in the browser, just in the source.
ETA, all I get in the source when it's added is exactly what I added! It doesn't show on the page in the browser, just in the source.
Edited by Dave_ST220 on Thursday 24th April 09:11
I always write in PHP these days
You could write a very simple php page and call the existing file.
This will show you any errors, prove PHP is running via the echo statement, show your existing page then show you the price below the page. Bodgy as hell but it should get you going. If you don't see a value for price your DB connection isn't working.
Save the below as test.php and run it...
You could write a very simple php page and call the existing file.
This will show you any errors, prove PHP is running via the echo statement, show your existing page then show you the price below the page. Bodgy as hell but it should get you going. If you don't see a value for price your DB connection isn't working.
Save the below as test.php and run it...
<?php
error_reporting(E_ALL);
echo 'PHP is running';
include ('./path_to_file/my_file.html');
echo 'price is ';
echo $price
?>
Tried the htaccess rule & that didn't work either. Sitting here thinking about it I'm guessing I need more code to tell it to actually look at the DB? On one of the pages that IS PHP I can see code like this :-
$sql = "SELECT id, name, menulinktext FROM categories WHERE id=".mysql_real_escape_string($_GET['id']);
$result = mysql_query($sql);
Shame, I thought it would have been simple but should have known better! All the info is sat there in a DB, I thought I could "tap" into it to provide this extra meta info
$sql = "SELECT id, name, menulinktext FROM categories WHERE id=".mysql_real_escape_string($_GET['id']);
$result = mysql_query($sql);
Shame, I thought it would have been simple but should have known better! All the info is sat there in a DB, I thought I could "tap" into it to provide this extra meta info
One step at a time
Because the test file has a .php extension the PHP engine will parse it. If you include the .html that will have been processed. Sounds like $price isn't defined...
Normally it goes like this.
You have a connection string somewhere that connects to your database.
That runs, then a sql query executes and grabs data from the db.
You dump the data into an array and then echo out the values.
This article has enough info for you to hack together a php page that will connect to your database and produce an elementary table.
http://php.about.com/od/phpwithmysql/ss/mysql_php_...
There's a mixture of html and variables grabbed by PHP.
If you get *how* it works the rest should be plain(ish) sailing
Because the test file has a .php extension the PHP engine will parse it. If you include the .html that will have been processed. Sounds like $price isn't defined...
Normally it goes like this.
You have a connection string somewhere that connects to your database.
That runs, then a sql query executes and grabs data from the db.
You dump the data into an array and then echo out the values.
This article has enough info for you to hack together a php page that will connect to your database and produce an elementary table.
http://php.about.com/od/phpwithmysql/ss/mysql_php_...
There's a mixture of html and variables grabbed by PHP.
If you get *how* it works the rest should be plain(ish) sailing
Gassing Station | Computers, Gadgets & Stuff | Top of Page | What's New | My Stuff