Forum Moderators: coopster

Message Too Old, No Replies

Passing Values from List Box

         

DontheCat

9:52 pm on Aug 20, 2005 (gmt 0)

10+ Year Member


I am able to populate my Countries Select Field in my form from 'Countries' table using this code after defining the RecordSet Query seperately.

=========================
<select name="country" id="country">
<?php
$result = mysql_query($query_country) or die("Could not run query.");
while ($answer = mysql_fetch_array($result)) {
extract($answer);
echo "<option>" .$country. "</option><br />\n";
}
?>
</select>
=======================
The Countries table has two fields - Country & Country_ID.

How do I log the relevant Country_ID rather than the Country into the target table?

Any direction in the right path would be appreciated :-)

I've defined the Query like this
====================================
mysql_select_db($database_pdo_db, $pdo_db);
$query_country = "SELECT * FROM countries ORDER BY country ASC";
$country = mysql_query($query_country, $pdo_db) or die(mysql_error());
$row_country = mysql_fetch_assoc($country);
$totalRows_country = mysql_num_rows($country);
?>

=============================================

Aleister

12:26 am on Aug 21, 2005 (gmt 0)

10+ Year Member



Maybe this is what you mean:


<select name="country" id="country">
<?php
$result = mysql_query($query_country) or die("Could not run query.");
while ($row = mysql_fetch_array($result)) {
$id = $row['country_id'];
echo "<option>" . $id . "</option><br />\n";
}
?>
</select>

$query_country = "SELECT country_id FROM countries ORDER BY country ASC";

That assumes the "country id" you were talking about is called country_id in your table. You do not seem to be using any other values from that table, so that is the only one this new query gets.

If this is not what you mean let me know, and I will try to help further.

DontheCat

8:50 pm on Aug 23, 2005 (gmt 0)

10+ Year Member


Thanks Ale...

Actually, I wanted the Countries to be displayed in the ListBox and when a country is Selected, the corresponding Country_ID to be logged into a members DB.

What I did was changed the a bit and the datalogging is perfect into the target DB.

<select name="country_ID" class="pcoform_text" >
<?phpdo {
?>
<option value="<?php echo $row_country['country_ID']?>"><?php echo $row_country['country']?></option>
<?php
} while ($row_country = mysql_fetch_assoc($country));

?>

</select>

Works perfectly. Thanks