View Full Version : Add to database, create new file

09-29-2003, 10:04 PM
I want to insert information through a form to a databse (thats not the problem for me)...

From each entry into the database I want to create a page for that i.e. http://www.mydomain.com/somefile.php?article=7787

and that would intern lead the user to the 7787 article in the database. Same way for somefile.php?article=1, etc. etc.

How can I do this??


09-29-2003, 10:36 PM
Are you joking ?

You mean like George, who creates a new file each time you open a thread like showthread.php?threadid=26988

What you describe are typical html-links in a dynamically generated page.
For instance you select all articles of a firm and run the recordset in a while loop, building the urls like
<a href=\"somepage?article=" . $row['aritcleID'] . "\"> ...
and display them in a table like


They all point to the same page (somefile.php) and inside
somefile.php, you will grab the value for article (with $_GET['article'] and use it inside a select or so. Then you build the page with the results from the select and display them

The whole point in a db-driven webapplication is to have only a few dynamically build files that completely generic and are filled in with date from the db.

Or do i misunderstand the question ?

09-29-2003, 10:39 PM
No, you did not misunderstand the question. Now, could you show me the code of how to do this?


09-29-2003, 11:08 PM
Euh ... OK. Say we have this page (page.php) where we select all articles from a specific catagory. So you build the selectstatement and run it, and then you loop through the recordset and build the list of links. Like:

$select = ("SELECT articleID, articlename FROM article WHERE catagory = 1 "); // normally, this 1 will also be grabed from the querystring or from a form
$result = mysql_query($sql_select,$link) or die(mysql_error());
while ($row = mysql_fetch_array($results,$link)) {
echo("<br /><a href=\"somepage.php?article=" . $row['articleID'] . "\" title=\"Show details of article ". $row['articlename']. "\">All about " . $row['articlename'] . "</a>");

So this will display a list a links. When you hoover over them, you'll see the adress in the adresbar looks like http://domain.com/somepage.php?article=145

If the user clicks on one of them, somepage.php is loaded.

Now in this page, you will run some code for the selected article, like selecting all details of it, like

$select=("SELECT article.articlename, article.price, suppliers.suppliername, suppliers.suppliersadress, suppliers.supplierID FROM article INNER JOIN suppliers ON article.supID = suppliers.suopliersID WHERE articleID = " . $_GET['article'] ); // so the value is grabbed from the querystring and injected in the SQL statement
$result = mysql_query($select,$link);
then your code to check if the recordset isn't empty and to display the data from the recordset

When you display this data, you could display the suppliersnames as links to "... href=\"supplierdetails.ph?supplier=" . $row['supplierID'] . "\" ..." etc

You see ?

09-29-2003, 11:14 PM
If you are going to create static pages from the data submitted in the form then why do you also want to store it in a database?

Like raf said if you just store it in the database you can then dynamically create the pages on the fly using a template. In other words, open the template stick in the data retrieved from the database and display it to the user.

09-29-2003, 11:26 PM
Well, then how can I dynamically create pages on the fly??


09-30-2003, 12:09 AM
Originally posted by SDP2006
Well, then how can I dynamically create pages on the fly??


Ok just to make sure you folks from South Carolina understand....when we say dynamically create pages on the fly we mean they do not actually exist and are only created temporarily using the data from the database and putting that data into the code being stored in the template.


09-30-2003, 12:44 AM
Oh yeah, spookster...

Might wanna change ur sig, Isabel is only what? 2 weeks old?

09-30-2003, 01:26 AM
Originally posted by SDP2006
Well, then how can I dynamically create pages on the fly??


Do you even read the answers and code people give you?

09-30-2003, 01:36 AM
Of course I read them...geez:D

09-30-2003, 01:41 AM
*cough* look at raf's post

09-30-2003, 01:52 AM
Originally posted by SDP2006
Oh yeah, spookster...

Might wanna change ur sig, Isabel is only what? 2 weeks old?

Is that better? :D

Yes as Nightfire pointed out raf has already discussed this a bit. Besides there are many threads on this if you use the search feature not to mention dozens of tutorials on this at places like www.zend.com and www.php.net . You just have to look around.

09-30-2003, 03:37 AM
Love ur new sig...

We here in tha Upstate caint reeed becuz of 'ire low eye q's