Jump to content


Photo

PHP & MySQL - should be simple


  • Please log in to reply
2 replies to this topic

#1 rockonxox

rockonxox
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 29 March 2006 - 10:04 PM

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.

#2 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 29 March 2006 - 10:21 PM

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:
<a href='horsedetail.php?id=5'>Horse 5</a>
and on the second page ("horsedetail.php"), you check the form input and retrieve some data, like this:
$horseid = $_GET['id'];
... SELECT * FROM horsedatabase WHERE id='$horseid' ...


#3 insrtsnhere13

insrtsnhere13
  • Members
  • PipPipPip
  • Advanced Member
  • 64 posts

Posted 30 March 2006 - 02:57 AM

$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>";}
}

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..

$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";}
}

that would basically be what you wanted




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users