Jump to content

PHP & MySQL - should be simple


rockonxox

Recommended Posts

I have a database of all the horses I own. All I want to do is list them on my site and have their name linked to their ID# in the database. When their name is clicked, I want information to be shown based on that ID#. How should I go about this?

I am thinking I need a second page with how I want the horse information to be shown. Am I correct in thinking this and if so how should I set it up?

The horses id is 'hid' in the database.
Link to comment
https://forums.phpfreaks.com/topic/6131-php-mysql-should-be-simple/
Share on other sites

Yeah, it's easiest to create a second page. For instance, your first page could be "allmyhorses.php" and the second page "horsedetail.php".

On the first page, you create some links like this:
[code]<a href='horsedetail.php?id=5'>Horse 5</a>[/code]
and on the second page ("horsedetail.php"), you check the form input and retrieve some data, like this:
[code]$horseid = $_GET['id'];
... SELECT * FROM horsedatabase WHERE id='$horseid' ...[/code]
[code]
$sql = mysql_query("SELECT * FROM horses order by id");

if (mysql_num_rows($sql) > 0) {
    while($row  = mysql_fetch_object($sql)) {
        echo "$row->id<br>";
        echo "$row->name<br>";
        echo "<a href=\"details.php?id=$row->id\">More Info</a><br><br>";}
}
[/code]

Something like that for the list would be good. Basically, It would search you database table named Horses and order them by ID number. It would then list then like this.

ID
NAME
MORE INFO

ID...etc

For details.php...

youd want a query like..

[code]
$horseid = $_GET['id']
$sql = mysql_query("SELECT * FROM horses WHERE id='$houseid'");

if (mysql_num_rows($sql) > 0) {
    while($row  = mysql_fetch_object($sql)) {
        echo "$row->id<br>";
        echo "$row->name<br>";
        echo "$row->ANY OTHER ROWS YOU WANT TO SHOW";}
}
[/code]

that would basically be what you wanted

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.