rockonxox Posted March 29, 2006 Share Posted March 29, 2006 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. Quote Link to comment https://forums.phpfreaks.com/topic/6131-php-mysql-should-be-simple/ Share on other sites More sharing options...
wickning1 Posted March 29, 2006 Share Posted March 29, 2006 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] Quote Link to comment https://forums.phpfreaks.com/topic/6131-php-mysql-should-be-simple/#findComment-22117 Share on other sites More sharing options...
insrtsnhere13 Posted March 30, 2006 Share Posted March 30, 2006 [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.IDNAMEMORE INFOID...etcFor 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 Quote Link to comment https://forums.phpfreaks.com/topic/6131-php-mysql-should-be-simple/#findComment-22161 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.