Forum Moderators: open

Message Too Old, No Replies

Dynamic prices on html page possible?

How to keep your published prices up to date in html page?

         

silverbytes

7:37 pm on Jul 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a page showing prices. Is a real pain to update it manaually and can't change the file extension for other reasons. Is a .htm page.
It would be great to find a solution to easily update those prices.

More intersting: those prices are in 3 different currencies.

It would be great to change 1 value and have those updated in pages.

Any ideas?

Busy

8:17 pm on Jul 20, 2005 (gmt 0)

10+ Year Member



The answer lies in PHP and MySQL (or another scripting/database language). In order to keep the file a plain html file, you will need to write a script that writes the output to a file (using fwrite() I think) instead of to the browser. Then you can use the resulting file on your site.

Here's what a snippet of the code might look like, just to get an idea...


// Imagine the prices have already been set to $prices[]
// Also imagine $page already contains most of the code for your page
$page .= '<ul>';
foreach ($prices as $p) {
$page .= '<li>Item 1:$'.$p.'</li>'; }
$page .= '</ul></body></html>';
// imagine $filename is the file we want to write to
$handle=fopen($filename);
fwrite($handle, $page);
fclose($handle);

If you're not familiar with an appropriate language, you'll need to take some tutorials to get started, because there's way more to learn than I could go over here.

Oh, and BTW, I haven't really used fwrite myself so my syntax is probably a little off.

BetterSEO

8:18 pm on Jul 20, 2005 (gmt 0)

10+ Year Member



You might not need anything that complicated. Could you accomplish what you want with simple PHP includes? You can have .htm pages execute PHP code by adding a line to your .htaccess file.

silverbytes

8:32 pm on Jul 20, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



BetterSeo: I don't see how includes would help but perhaps you can explain I'd need an include for each type of currency an price.
It would be good something that calculates the proper value and update that on all mentions on page
I guess that last option has a downside right? Does
that affect in any way to my seo work?

For Busy: I already have my html page and can't subsitute that. So the resulting file is not an option to me since I can't throw away my current pages. If didn't get it please explain further, and thank you!

Busy

8:54 pm on Jul 20, 2005 (gmt 0)

10+ Year Member



You're right, my way is too complicated. I didn't know you could do that with the htaccess file.

Includes would be the quickest way to do it. Don't use an include for each item, but use an include for the whole list if you can manage it. That way you can stick the include on every page where you want that list of products, and the only thing you'll have to update will be the one include file.

But really, if you're starting to work with sites that need updating a lot, you'll save yourself a lot of headaches if you set aside a weekend and get down the basics of a good server-side scripting language(like PHP) The time you save in the longrun will be well worth it, and you'll be able to do a lot more with your websites, especially if you learn MySQL at the same time.

silverbytes

2:08 pm on Jul 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I can't creat 1 list for all. Those are pages with different products. Unless is there a way to "paste" a portion of the include which I don't think possible...
However suppousing I do it with php and sql is there downsides of changing .htaccess?

vincevincevince

2:12 pm on Jul 21, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can do it all using an external javascript file.

Use that file to define the prices as variable names (probably as parts of an array).

Then output those values....

Busy

2:25 pm on Jul 21, 2005 (gmt 0)

10+ Year Member



I don't believe there would be any downsides to changing htaccess, but I'm not 100% sure about it.

If you decide to use javascript instead, keep in mind that there will be a relatively small minority of people out there that have javascript turned off or their browsers don't support it, so make sure that the page still makes sense for those guys, even if it just shows a message saying "To view prices, you will need javascript enabled." I think this can be easily done with the NOSCRIPT tag.

silverbytes

12:11 pm on Jul 22, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



About downsides I hardly remember someone talked about a longer time to execute the page which would make a difference with or without that addition in .htaccess

About javascript non supported: does IE 4.x and higher and firefox support it right? In that case that's a 97% of people in my case but I'm not sure about what browsers does. Can someone confir or deny my guessing?

vincevincevince:

Can you explain more detailed that? I don't know how to do that but sounds good!

Busy

1:23 pm on Jul 22, 2005 (gmt 0)

10+ Year Member



According to thecounter dot (cough... no url here!) about 5% of users have had javascript disabled in recent months , your site may be more or less, but there are some people who turn javascript off on purpose if they have slow connections or are paranoid.

IMO, 5% is a number I could live with for one of my sites, but is too much if the site is for a client.