combo box select problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
zuzupus
Forum Commoner
Posts: 70
Joined: Thu Jul 17, 2003 4:54 am

combo box select problem

Post by zuzupus »

hi,

i am getting value of project from database

Code: Select all

<?php
$query = "SELECT kunde,projektnr from emp_kunde";
$result = mysql_query($query) or die("Query failed: $query");
$projekt = array();
while ($row = mysql_fetch_assoc($result))
{
array_push($projekt, $row["projektnr"]);
}
$hprojekt = array_unique($projekt);
?>
<form >
<td align="center">
<select name="projekt">
<? foreach($hprojekt as $value) { ?>
<option value="<?= $value ?>"><?= $value ?></option>
<? } ?>
</select>
</td>

<?= $line["projekt"] ?>//this is for printing

</form>

let say the value for project combo box is

Apple,Mango so when i select mango from project field and then submit the form i will get mango as printed value,i want mango must be shown selected in new line,whatever i select it will be shown as selectd on next new line,but in my case always Apple as selected in new line

let say in my list
1.Dad
2.Mom
3.Didi //if i select didi from this field then new line should be didi
4.Uncle as selected
5.Aunty

but above code always shown as Dad selected,

how i cna get selected item as shown in new line

thanks
Last edited by zuzupus on Fri Jul 18, 2003 9:44 am, edited 1 time in total.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

Please edit your post to add in for the code so that it is easier to read.

Mac
RedRasper
Forum Commoner
Posts: 48
Joined: Thu Apr 24, 2003 6:36 am

Post by RedRasper »

Try using <option selected> in your combo box. The first item is automatically selected if you don't specify one.

You need to do an if statement to check if the item was the same as the one selected. (It also means you need to either post/get the item when you submit.)

Hope thats of some help?

RedRasper
Post Reply