0

I am just trying to make a php edit script using a combo box or any other method. But I am not sure how to write a script when selecting a sportsid and fetch the related data at the same time.

$sql = "SELECT * FROM sports WHERE sport_id=2";
$query = mysql_query($sql);
while ($row = mysql_fetch_array($query)){
	$id = $row['sportid'];
	$sname = $row['sport_name'];
	$sprice = $row['sport_price'];

}
mysql_free_result($query);
?>
<html>
<head>
<title>Edit User Info</title>
</head>
<body>
<form action="updateinfo.php" method="post">
userid:<br/>
<input type="text" value="<?php echo $id;?>" name="id" >
<br/>
Last Name:<br/>
<input type="text" value="<?php echo $sname;?>" name="sname"/>
<br/>
Last Name:<br/>
<input type="text" value="<?php echo $sprice;?>" name="sprice"/>
<br/>
<br/>
<input type="submit" value="submit changes"/>
</form>
</body>
</html>
2
Contributors
1
Reply
8
Views
6 Years
Discussion Span
Last Post by lagspike
0

First set it so you can have GET variables so you can get different items depending on that variable (like /page.php?sport=3 ) and make your SQL query have $_GET['sport'] at the end (instead of '2').
To add the combo box, you can do another query to get every item in the database:

//add this in wherever you want the combobox
$sql2 = "SELECT * FROM sports";
$query2 = mysql_query($sql);
echo '<select>';
while ($row = mysql_fetch_array($query2)){
        echo '<option><a href="somepage.php?sport='.$row['sport_id'].'">'.$_row['sport_name'].'</a></option>';
}
echo '</select>';

A harder but nicer way to do this (instead of doing a new page every time) would be to learn about JavaScript and AJAX (if you haven't already). It's quite a bit harder to learn, but if you want to try it, then i would recommend you using jQuery and .load()

Edited by lagspike: a quotation mark was in the wrong place

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.