0

我有一个需要显示 sqlite 数据库的网页。现在我正在通过 CGI 动态创建整个页面。但是,我宁愿拥有一个 html 文件,并在文件中使用数据库内容填充一个表。最好的方法是什么?我仅限于 C 语言中的 html、javascript 和 CGI​​。

非常感谢任何帮助。

谢谢!汤姆

4

2 回答 2

1

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?).

于 2008-12-16T18:49:16.820 回答
0

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.

于 2008-12-16T18:52:39.777 回答