Change my Query Value , following Select, selection
Posted: Tue Jun 02, 2009 6:52 am
See below my code......
I populate a select box, with a list of Countries, which have and ID number associated with each.
I then want to run my query using the countries ID value (currently hardcoded to 81)
Any help greatly appreciated.... as you will see i'm still new to php...
<html>
<head>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mydbname", $con);
// Go and get Country's
print "<h4>Country : </h4>";
$query="SELECT country_name ,id FROM countries";
$result = mysql_query ($query);
?>
<!-- Populate Select with countries & country ID -->
<form action="display.php" method="post">
<select onchange="display_data(this.value);" name='countryname'>
<?php
while($nt=mysql_fetch_array($result)){
echo "<option value=$nt[id]>$nt[country_name]</option>";
}
?>
</select>
</form>
<?php
//Want to select items_country from Select Option ID above....
$query = "select * FROM items WHERE items_country = 81" ;
$data = mysql_query($query) ;
Print $query;
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<th>Country:</th> <td>".$info['items_country'] . "</td> ";
Print "<th>Era :</th> <td>".$info['items_era'] . " </td>";
Print "<th>title :</th> <td>".$info['items_desc'] . " </td>";
Print "<th>Description :</th> <td>".$info['items_description'] . " </td></tr>";
}
Print "</table>";
?>
</body>
</html>
I populate a select box, with a list of Countries, which have and ID number associated with each.
I then want to run my query using the countries ID value (currently hardcoded to 81)
Any help greatly appreciated.... as you will see i'm still new to php...
<html>
<head>
</head>
<body>
<?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("mydbname", $con);
// Go and get Country's
print "<h4>Country : </h4>";
$query="SELECT country_name ,id FROM countries";
$result = mysql_query ($query);
?>
<!-- Populate Select with countries & country ID -->
<form action="display.php" method="post">
<select onchange="display_data(this.value);" name='countryname'>
<?php
while($nt=mysql_fetch_array($result)){
echo "<option value=$nt[id]>$nt[country_name]</option>";
}
?>
</select>
</form>
<?php
//Want to select items_country from Select Option ID above....
$query = "select * FROM items WHERE items_country = 81" ;
$data = mysql_query($query) ;
Print $query;
Print "<table border cellpadding=3>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print "<th>Country:</th> <td>".$info['items_country'] . "</td> ";
Print "<th>Era :</th> <td>".$info['items_era'] . " </td>";
Print "<th>title :</th> <td>".$info['items_desc'] . " </td>";
Print "<th>Description :</th> <td>".$info['items_description'] . " </td></tr>";
}
Print "</table>";
?>
</body>
</html>