By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,614 Members | 1,653 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,614 IT Pros & Developers. It's quick & easy.

mutiple selection view in select box

P: 45
hi,
i am new to this forum.i need help for view a mutiple selected value from database.....that is already selected value display..

my code.....[php]
$jobcount=count($vinloc);
print" <td><select name=\"selintloc[]\" size=\"3\" width=\"25\" class=\"widthed\" multiple=\"multiple\" tabindex=\"5\">";
for($c=0;$c<$jobcount;$c++)
{
print"<option value=\"$vinloc[$c]\" selected>$vinloc[$c]</option>";

print"<option value=\"Bangalore\" ".("Bangalore"==$vinloc [$c]?"selected=on":"")." >Bangalore</option>";
print"<option value=\"Calcutta\" ".("Calcutta"==$vinloc[$c]?"selected=on":"" ).">Calcutta</option>";
print"<option value=\"chennai \" ".("Chennai"==$vinloc[$c]?"selected=on":"" )." >Chennai</option>";
print"<option value=\"Delhi\" ".("Delhi"==$vinloc[$c]?"selected=on":"" ).">Delhi</option>";
print"<option value=\"Hyderabad\" ".("Hyderabad"==$vinloc[$c]?"selected=on":"").">Hyderabad</option>";
print"<option value=\"Kochi\" ".("Kochi"==$vinloc[$c]?"selected=on":"").">Kochi</option>";
print"<option value=\"Mumbai\" ".("Mumbai"==$vinloc[$c]?"selected=on":"" ).">Mumbai</option>";
}
[/php]
it display twice the all value......
Feb 25 '08 #1
Share this Question
Share on Google+
3 Replies


harshmaul
Expert 100+
P: 490
Hi,
Firstly welcome the thescripts :)
Secondly next time please use code tags :(
Thirdly your problem...
You are echoing the options on every iteration of the for loop. You need to re work your logic.
Forthly if you can't work it out, i'm gonna write some code when i get time and you can look at it later.

Thanks :)
Feb 25 '08 #2

harshmaul
Expert 100+
P: 490
Hi again, heres some badic code, it might need a spot of debugging as i haven't got apache at work, but i think it should give you at least some direction


[PHP]<?php
//Bangalore loop
$strSelected = "";
for($c=0;$c<$jobcount;$c++)
{
$strSelected = ("Bangalore"==$vinloc [$c]?"selected=on":$strSelected);
}?>
<option value="Bangalore" <?php echo $strSelected ?>>Bangalore</option>

<?php
//Calcutta Loop
$strSelected = "";
for($c=0;$c<$jobcount;$c++)
{
$strSelected = ("Calcutta"==$vinloc [$c]?"selected=on":$strSelected);
}?>
<option value="Calcutta" <?php echo $strSelected ?>>Calcutta</option>

<?php
//Chennai Loop
$strSelected = "";
for($c=0;$c<$jobcount;$c++)
{
$strSelected = ("Chennai"==$vinloc [$c]?"selected=on":$strSelected);
}?>
<option value="Chennai" <?php echo $strSelected ?>>Chennai</option>

<?php
//Chennai Loop
$strSelected = "";
for($c=0;$c<$jobcount;$c++)
{
$strSelected = ("Delhi"==$vinloc [$c]?"selected=on":$strSelected);
}?>
<option value="Delhi" <?php echo $strSelected ?>>Delhi</option>[/PHP]
Feb 25 '08 #3

P: 45
hi harshmaul


it great..Thank you very much.....
Feb 25 '08 #4

Post your reply

Sign in to post your reply or Sign up for a free account.