Here's some example code so you can get an idea of how things work. This is a jobs posting database, but you can change things for your own purposes.
Just realize the most important things are to 1. make the connection to the database:
//this makes a connection to a mySQL database
$db= mysql_connect("localhost", "username", "password")
or die("Could not connect: " . mysql_error());
mysql_select_db("name_of_database",$db);
- call the database:
$sql = "select * from jobsdatabase ORDER BY Title";
$result = mysql_query($sql)
or die("Invalid query: " . mysql_error());
- Set up your HTML with links to go to your detail page, ie. a table with repeating rows of information:
<table width="100%" border="0" cellspacing="2" cellpadding="4" class="bodytext">
<tr bgcolor="#996600">
<td width="31%"><font color="#FFFFFF"><strong>Title</strong></font></td>
<td width="47%"><font color="#FFFFFF"><strong>Job Details</strong></font></td>
</tr>
<?php
$sql = "select * from jobsdatabase ORDER BY Title";
$result = mysql_query($sql)
or die("Invalid query: " . mysql_error());
?>
<!-- START WHILE STATEMENT for repeat rows for job openings -->
<?php
//this table will repeat any rows with jobs in the database while($row=mysql_fetch_array($result)) {
?>
<tr bgcolor="#FFFF99">
<input name="jobid" type="hidden" value="<?php echo $row['id']; ?>">
<td><font size="2"><?php echo $row['Title']; ?></font></td>
<td><a href="oppr.php?goto=details&id=<? echo $row['id']; ?>"><font size="2">Details</font></a></td>
</tr>
<?php
}
?>
<!-- END WHILE STATEMENT for repeat rows for job openings -->
</table>
Here's the tricky part. Notice this part in your links:
oppr.php?goto=details&id=<? echo $row['id']; ?>"><
I like to keep things inside each page. So, here's what this is doing. 'oppr.php' is my 'opportunities' page, or jobs listing page. Yours might be called 'cars.php' which is the initial listing of all your cars.
"goto=details" is part of a switch statement, meaning everything is kept on that page, but it's calling up switch "goto", case "details". It would look something like this:
switch ($HTTP_GET_VARS['goto']) {
case "details":
echo "Details stuff here.";
break;
default:
echo "This is the default stuff people see.";
}
If you'd rather point to another page, your links would look more like this:
details.php&id=<? echo $row['id']; ?>
..and then you'd do all your database queries on the details.php page.
Anyway, the last part of that is &id=<? echo $row['id']; ?>. In your database, your cars should be assigned an ID as the first field. Make sure when you create that database that you have an id field in there and set it to autoincrement. When you pull back information using the query setup, you'll then call everything by that ID.
If you are confused, let me know and I'll try to help.