GIDForums  

Go Back   GIDForums > Computer Programming Forums > MySQL / PHP Forum
User Name
Password
Register FAQ Members List Calendar Search Today's Posts Mark Forums Read

 
 
Thread Tools Search this Thread Rate Thread
  #1  
Old 18-Jul-2003, 09:34
zuzupus zuzupus is offline
Junior Member
 
Join Date: Jul 2003
Posts: 70
zuzupus is an unknown quantity at this point

combo box select problem


hi,

i am getting value of project from database

PHP Code:

<?
$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); ?>

<td  align="center">
         <select name="projekt">
             <? foreach($hprojekt as  $value) { ?>
              <option  value="<?= $value ?>"><?= $value ?></option>
                   <? } ?>
           </select>
  </td>
<?= $line["projekt"] ?>//this is for printing

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
  #2  
Old 19-Jul-2003, 07:03
JdS's Avatar
JdS JdS is offline
Senior Member
 
Join Date: Aug 2001
Location: KUL, Malaysia
Posts: 3,371
JdS will become famous soon enough
Hello zuzupus,

Seriously, I had a really hard time understanding your question, can you try re-phrasing it? Or maybe a sample page to view?
  #3  
Old 23-Jul-2003, 12:25
samtediou samtediou is offline
New Member
 
Join Date: Jul 2003
Posts: 18
samtediou is an unknown quantity at this point
zuzupus,

I went through the same dilemna about a month ago--there's a simple fix.

What's happening is that your HTML select box needs the options to have PHP code to write the word 'selected' in order to capture the sumbitted value, otherwise your code will continue to ignore the sumitted value and write the HTML for a drop-down box without any one option explicitly selected. The default submission value of an unselected drop-down box is its first value, in your case 'Dad'.


If you wanted to have Didi selected when you write your page after submission, the HTML code should look like this:

<select name="projekt">
<option></option>
<option value="Dad">Dad</option>
<option value="Mom">Mom</option>
<option value="Didi" selected>Didi</option>
<option value="Uncle">Uncle</option>
<option value="Aunty">Aunty</option>
</select>

Note: Adding the first empty option tag will make your drop-down box show an empty entry as the default.


In order to store the sumitted combo box value in a variable ($name), you can set it equal to the value posted under the combo box's name. Put this code up before your combo box, wherever you initialize variables. If your page is being visited (initially) before the form has been submitted, the variable ($name) with not contain a value.

<?php
$name = $_POST['projekt'];
?>


<select name="projekt">
<option></option>
<option value="Dad" <?php if ($name=="Dad") {echo "selected";}?>>Dad</option>
<option value="Mom" <?php if ($name=="Mom") {echo "selected";}?>>Mom</option>
<option value="Didi" <?php if ($name=="Didi") {echo "selected";}?>>Didi</option>
<option value="Uncle" <?php if ($name=="Uncle") {echo "selected";}?>>Uncle</option>
<option value="Aunty" <?php if ($name=="Aunty") {echo "selected";}?>>Aunty</option>
</select>


So change your code to incorporat this logic:

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

<?
$name = $_POST['projekt'];
?>

.......

<select name="projekt">
<option></option>
<? foreach($hprojekt as $value) { ?>
<option value="<?= $value" if ($name==$value) {echo "selected";} ?>"><?= $value ?></option>

<? } ?>
</select>
=======================

Good luck!
samtediou
 
 

Recent GIDBlogOnce again, no time for hobbies by crystalattice

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
editable combo box zuzupus Web Design Forum 4 13-Dec-2005 16:01
unwanted scrollbar problem kelly001 Web Design Forum 3 24-Oct-2003 11:44
select problem zuzupus MySQL / PHP Forum 0 15-Aug-2003 08:25
join problem zuzupus MySQL / PHP Forum 0 14-Aug-2003 06:11
client side problem zuzupus MySQL / PHP Forum 2 22-Jul-2003 07:47

Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The

All times are GMT -6. The time now is 00:14.


vBulletin, Copyright © 2000 - 2009, Jelsoft Enterprises Ltd.