tags:

views:

112

answers:

3

Hi, I have a web page that needs to display a sqlite database. Right now i am creating the entire page dynamically through CGI. However, I would rather have one html file and just populate a table within the file with the database content. What is the best method to do that? I am limited to html, javascript and CGI in C.

Any help is greatly appreiated.

Thanks! Tom

+1  A: 

If your content is updated once a day (or hour, etc) then you could schedule the C code as a standalone application via cron to run. It reads in a "header" html template file, generated the table from the database, then copies the "footer" html template file. This generated file gets copied to the web server location you want it, then the webserver can simply serve the HTML file.

If you have no cron, you could move the C into a CGI C code that you can call manually via a "hidden" URL that generates the HTML file in the same way.

If the table updates all the time, then just do the above but return the data to the user rather than creating a file to serve statically.

I assume you don't have access to server-side includes of any sort (embedded web server?).

JeeBee
A: 

How much of this do you have working? Do you have your sqlite connection working in your C code? Writing a plain CGI app isn't difficult, just output your headers, especially Content-Type and preferably Content-Length(if you know it), and then just output the page.

As for a templating system, you can write html files and replace certain tags with the dynamic content. Take a look at some templating systems like Smarty for some inspiration perhaps.

Kekoa
A: 

JeeBee, It needs to be updated all the time. How do you read in a "header" html template file and copy the "footer" html template file with the generated output? Is there an example of this? This sounds like what I am looking for. I am using an embedded server and can change anything as needed on it. Please keep in mind this is the first time I have done this.

Kekoav, Yes, the sqlite code is part of my C code. I execute sqlite functions in here and output html from printfs. I am already out putting the page but that's not what I really want. You mentioned replacing certain tags with dynamic content. Could you point me in the right direction to do that? That's what I'm looking for.

Thanks so much!