Page 1 of 1
database help
Posted: Sun Jun 02, 2002 6:14 am
by epic
How do i make it so a page will go into a mysql table thingo. like
http://www.phpcomplete.com/content.php?id=10 <-- how do you make it so a page is assosciated with a table id? or do i have to make a page in php and make it include the information i want? this must be easier than making 50 html pages or no one would do it.
sorry if i sound like a newb the truth is i am.

Posted: Sun Jun 02, 2002 7:43 am
by MattF
You would have a mySQL table with a few rows such as id, content, title, date etc and then you would have a page template with a header and footer, then in the middle you would have code maybe like this:
Code: Select all
<?php
include "header";
$db = mysql_connect("localhost","username","Password");
mysql_select_db("database");
$result = mysql_query("SELECT * FROM content WHERE id = '". $_GETї'id']."'");
if(mysql_num_rows($result) != 1) echo "Page not found.";
else
{
$page = mysql_fetch_array($result);
echo "<h1>".pageї'title']."</h1>";
echo "<p>".pageї'content']."</p>";
}
include "footer";
?>
Posted: Sun Jun 02, 2002 7:31 pm
by epic
cheers. the header and footer would contain the page format. like layout and links and etc. also how do i get the header and footer on the same page? do i just create a page called header.php and footer.php
Posted: Mon Jun 03, 2002 6:25 am
by MattF
You could make a php file with a head function and a foot function, then you need only include one file and then call each function in the right place.
Posted: Sat Jun 08, 2002 12:40 am
by epic
when i use your code i get this error.
Parse error: parse error, expecting `','' or `';'' in /home/sites/site22/web/php2/index.php on line 10
then when i took out the html "<h1>" etc. all i got was.
.page['title'].
.page['content'].
can you tell me if i have configured something wrong?
i got the footer and header thing done aswell thanks.

Posted: Sat Jun 08, 2002 3:00 am
by MattF
Code: Select all
echo "<h1>".pageї'title']."</h1>";
echo "<p>".pageї'content']."</p>";
Should have been:
Code: Select all
echo "<h1>".$pageї'title']."</h1>";
echo "<p>".$pageї'content']."</p>";
Posted: Sat Jun 08, 2002 5:35 am
by epic
k thanks for your help.

can you suggest a tutoral where it explains how to totally setup the ?id=1 thingo. I have gotten it working now but i just want to make the main page. when you just go to the main page you get "Page not found" im trying to make it say. all the titles in the table and links to there id numbers. But i still want it to say page not found when they come accross a not used id number. If thats possible