Connecting Tech Pros Worldwide Forums | Help | Site Map

how I make to recoup the value of database and to keep selected in combobox

Newbie
 
Join Date: Sep 2007
Posts: 1
#1: Sep 19 '07
Hi friends,

how I make to recoup the value of database and to keep selected in combobox to edit my form?

in script below it is selected field of the table that possesss id of the first item of database.

I am catching id of a URL:

[PHP]<?php echo "<a href='alterar_cliente.php?id=$id'>Alterar</a>"; ?>[/PHP]

[PHP]<?php
include("../config.php");
$sql = mysql_query("SELECT cidade FROM clientes");
$aux = mysql_fetch_array($sql);
$cidade_cliente = $aux["cidade"];

echo "<select name=\"cidade\">";
$sql_cidade = mysql_query("SELECT * FROM cidades ORDER BY cidade ASC");
while($linha=mysql_fetch_array($sql_cidade)) {
if ($linha[1] == $cidade_cliente) {
echo"<option value=\"$linha[1]\" selected>$linha[1]</option>";
} else {
echo"<option value=\"$linha[1]\">$linha[1]</option>";
}
};
echo "</select>";
?> [/PHP]

somebody could help me?

ronverdonk's Avatar
Moderator
 
Join Date: Jul 2006
Location: The Netherlands
Posts: 4,139
#2: Sep 19 '07

re: how I make to recoup the value of database and to keep selected in combobox


Maybe you should rephrase your question or show us a sample of the code you intend to use to update the db. All I can see in the code shown is that you construct a drop-down box with values from the database.
This drop-down is not within a form and nowhere is to be seen what you intend to do with the selected value from the box.
Show us the code you produced for handling the selected value from the drop-down box and we can see how we can assist you there.

Ronald
Reply