Forum Moderators: coopster
=========================
<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);
?>
=============================================
<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.
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