Can this be done? (html + database)

Can this be done? (html + database)

Author
Discussion

Dave_ST220

Original Poster:

10,296 posts

206 months

Wednesday 23rd April 2014
quotequote all
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 smile


Dave_ST220

Original Poster:

10,296 posts

206 months

Wednesday 23rd April 2014
quotequote all
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??

Dave_ST220

Original Poster:

10,296 posts

206 months

Wednesday 23rd April 2014
quotequote all
Just thought, I'm sure the bots used to see this info anyway as Google used to display them in the SERP's. Is there a good tool that shows a page as bots see it? Ta

Dave_ST220

Original Poster:

10,296 posts

206 months

Thursday 24th April 2014
quotequote all
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.
The site is already built & has been for some years wink

Dave_ST220

Original Poster:

10,296 posts

206 months

Thursday 24th April 2014
quotequote all
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 smile
It's a MySQL database.

Dave_ST220

Original Poster:

10,296 posts

206 months

Thursday 24th April 2014
quotequote all
Can you give some example code? & that would work on a static html page? Thanks

ETA, I tried this which I thought would work :-

<?php echo $price; ?>

But no joy frown I know nothing about PHP btw!!

Edited by Dave_ST220 on Thursday 24th April 08:47

Dave_ST220

Original Poster:

10,296 posts

206 months

Thursday 24th April 2014
quotequote all
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 smile

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

Dave_ST220

Original Poster:

10,296 posts

206 months

Thursday 24th April 2014
quotequote all
OK, I'll try that. When you say run it I assume just navigate to the URL?

The htaccess method I found was :-

AddType application/x-httpd-php .htm .html

Not tried that either yet though...

Dave_ST220

Original Poster:

10,296 posts

206 months

Thursday 24th April 2014
quotequote all
Ok, done that but no price. This line :-

include ('./path_to_file/my_file.html');

Should be set to the file I'm working on? I don't get how that would work?

With regard to htaccess I need to do it on around 30 pages so I need a generic rule rather than per file really.

Dave_ST220

Original Poster:

10,296 posts

206 months

Thursday 24th April 2014
quotequote all
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 frown

Dave_ST220

Original Poster:

10,296 posts

206 months

Thursday 24th April 2014
quotequote all
Ok, thanks. I'll get reading smile I know there is a config.php file that seems to handle the DB connection (user name & PW etc). I think that is the route of my problems smile

Dave_ST220

Original Poster:

10,296 posts

206 months

Thursday 24th April 2014
quotequote all
Arh, this is falling into place. I can't just query the DB for "price" as there are loads of prices. I need to query it for the product ID too so the two match up. If I've got it all correct in my head it will be easier to hard code each darn page with this info anyway frown As I said currently we paste JS to each page which then renders all the info in the browser but not to bots. (& looking at the JS all that does is pull the info from the DB via another file named data). Sadly it doesn't look possible. Thanks for taking the time anyway smile

Dave_ST220

Original Poster:

10,296 posts

206 months

Thursday 24th April 2014
quotequote all
bishbash said:
Decent bots will use something similar to http://phantomjs.org/ to be able to 'read' the javascript parts of the page if that's what you're worrying about?
That is all I'm worrying about! To recap, we paste some JS to the page. The page then displays the prices in a browser. View source you just see the JS. I need the bot to see the price along with the schema.org tags.

Dave_ST220

Original Poster:

10,296 posts

206 months

Thursday 24th April 2014
quotequote all
Thanks, I think I really need to start again. I've just used a few tools to view the pages as various bots. None of the prices or anything are there. If I compare to competitors all the info is there. Obviously bots will love them more than me frown The weird thing is I know 100% Google was showing this info in the SERP's last year, like they WERE reading the JS & using it. maybe they decided this schema.org lark was the way to go?? Anyway, thanks for all of your time people, some decisions to be made!!