Click to See Complete Forum and Search --> : php/database driven website


JDM71488
02-06-2005, 11:01 AM
example...

http://www.onlinecarstereo.com/CarAudio/ProductDetail.aspx?ProductID=14320

not aspx pages, but notice the ProductID, i want to have tutorials stored in my database and links to them given UIDs... so the page will be like a template, and the info will load accordingly...

i just don't know how to setup the page, or the database, SO, does anyone know of any good tutorials?

thanks,
JDM

phpnovice
02-06-2005, 11:19 AM
Don't know of any tutorials (though I'm sure there are plenty out there), but maybe I can offer pointers. What database will you be using? MySQL?

ShrineDesigns
02-06-2005, 11:39 AM
sql table:CREATE TABLE tutorials (
id MEDIUMINT NOT NULL AUTO_INCREMENT DEFAULT '0',
title TINYTEXT NOT NULL DEFAULT '',
tutorial MEDIUMTEXT NOT NULL DEFAULT '',
added MEDIUMINT NOT NULL DEFAULT '0',
PRIMARY KEY (id)
)display it<?php
$db = mysql_connect('localhost', 'root', '');
mysql_select_db('dbname', $db);

$result = mysql_query("SELECT * FROM tutorials WHERE id = '{$_GET['id']}'");

if($result === false)
{
$tutorial = array
(
'id' => '',
'title' => 'not found!',
'tutorial' => 'this tutorial does not exist',
'added' => ''
);
}
else
{
$tutorial = mysql_fetch_array($result, MYSQL_ASSOC);
mysql_free_result($result);
}
?>
<html>
<head>
<title><?php echo $tutorial['title']; ?></title>
</head>
<body>
<h3><?php echo $tutorial['title']; ?></h3>
<p><?php echo $tutorial['tutorial']; ?></p>
</body>
</html>

Stephen Philbin
02-06-2005, 12:08 PM
Have a read up on using GET and POST from forms. POST is the way of sending form data that is not in the address and GET is when you do put data in the address. Like whatever.com/fishing/quota.php?country=japan&company=yakamoto

In that address the GET variables are $_GET['country'] (which holds the value of "japan") and $_GET['company'] (which holds the value of "yakomoto"). You can use these variables in a mysql query that has been sent by php to get the details of the fishing quota for the yakamoto company in japan by making a query a bit likemysql_query("SELECT quota FROM table_of_quotas WHERE country = '$_GET[country]' AND company_name = '$_GET[company]'");

So the basic gist of it is that someone fills in a form with the country and company fields in it, then the info they put in the form is sent to the next page in the address bar, then php GETs the info from the address bar and uses it in the query to find the wanted data. A form is one way of doing it, but there's plenty of other ways of doing it and plenty of other bits of info you can pass along in this way.

Hopefully that's given you the basic idea. Good luck with yer project. ;)

JDM71488
02-06-2005, 12:55 PM
wow... it seems so simple now... i grew up teaching myself "post" over get, but now i see it's uses...

i really want to thank you guys for your help... i wish you good things in life...

take care...

JDM71488
02-06-2005, 10:07 PM
sorry to double post, but if i edited my last one, no one would think i replied the second time...

i get the whole thing except for this part:

if($result == false)
{
$tutorial = array
(
'id' => '',
'title' => 'not found!',
'tutorial' => 'this tutorial does not exist',
'added' => ''
);
}

nothing is displayed on the screen when an invalid id is entered... i know they are pointers "=>", but how would i set the title to "Not Found!" and the others accordingly?

ilya
02-08-2005, 02:35 PM
heres is a msword doc tutorial on building a mysql/php driven website that i uploaded..have fun ;)




mysql/php driven website tutorial (http://fallen-throne.com/images/mysql-php.doc)

NogDog
02-08-2005, 03:06 PM
Originally posted by JDM71488
sorry to double post, but if i edited my last one, no one would think i replied the second time...

i get the whole thing except for this part:

if($result == false)
{
$tutorial = array
(
'id' => '',
'title' => 'not found!',
'tutorial' => 'this tutorial does not exist',
'added' => ''
);
}

nothing is displayed on the screen when an invalid id is entered... i know they are pointers "=>", but how would i set the title to "Not Found!" and the others accordingly?
Try this, perhaps:

if($result === false or mysql_num_rows($result) == 0)
{
$tutorial = array
(
'id' => $_GET['id'],
'title' => 'not found!',
'tutorial' => 'this tutorial does not exist',
'added' => ''
);
}

The => is used to define a specific array key for each value. Without it (just a list of comma-separated values), each value would be assigned the next available numeric array index as its key. So the value to the left of the => is the array key and the value to the right is the value assigned to that array element.

JDM71488
02-08-2005, 04:34 PM
thanks ilya for that document, i saved it on my computer... and thanks nogdog for the change in script...i fittled around with it, but couldn't get it to work...

if you want to see what i'm doing, heres the site:

http://math.accessjdm.com

http://cpp.accessjdm.com

i have a lot of others i'm going to convert, but as for now, they are just sub-domains. i eventually want to make one big site driven off the same database...

Stephen Philbin
02-08-2005, 08:20 PM
Slightly off topic, but I think you should know.....

If you're getting into databases (which you obviously are doing) then I recomend you have a look at relational database design. (Hint: relational databases need the innodb table type engine to support relational database design. You can use another engine but I forget its name.)

I'm not saying go rebuilding your entire site to work of an entirely reworked database (that'd just be insane), but it can be good stuff to know for future projects. ;)

JDM71488
02-08-2005, 11:36 PM
oh i am... im in academy of information technology at my HS, and now we are learning oracle... (erd, relational dbs, etc...) we are moving rather slow, but those are my goals...