FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » populate pulldownbox from query
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: populate pulldownbox from query [message #174090 is a reply to message #174088] Sat, 21 May 2011 12:08 Go to previous messageGo to previous message
Co is currently offline  Co
Messages: 75
Registered: May 2011
Karma:
Member
On 21 mei, 13:00, t...@mountifield.org (Tony Mountifield) wrote:
> In article <cddfd7a4-dfb5-48c0-8ecc-e2c86baaf...@glegroupsg2000goo.googlegroups.com>,
>
> Co  <comp(dot)lang(dot)php(at)googlegroups(dot)com> wrote:
>> I don't think the formatting is the problem.
>> The problem is that the values are not set in the pulldownbox.
>> It does populate the box with the names but the value from the database
>> for the current record is not displayed.
>
>> Marco
>
> What you need to do, within the loop that outputs the <option> elements,
> is to check the value(s) in the row to see if this is the element that
> should be currently displayed, and it so, you need to add the "selected"
> tag to the <option> element, e.g.
>
> <option id="$id" selected>$optiontext</option>
>
> For all other options, omit the "selected".
>
> Cheers
> Tony
> --
> Tony Mountifield
> Work: t...@softins.co.uk -http://www.softins.co.uk
> Play: t...@mountifield.org -http://tony.mountifield.org

Tony,

I changed my code and now it does load the names and give me the
current partner in the field.

<?php
$query="SELECT id, firstname, lastname, rank FROM myMembers WHERE id
<> $id ORDER BY lastname";
$result = mysql_query ($query);
echo "<select name=partner class=formFields id=partner
value=''>Partner</option>";
while($nt=mysql_fetch_array($result)){//Array or records stored in $nt
echo "<option id=$id selected>{$nt['rank']} {$nt['firstname']}
{$nt['lastname']}</option>";
//echo "<option value=$nt[id]>{$nt['rank']} {$nt['firstname']}
{$nt['lastname']} </option>";
/* Option values are added by looping through the array */
}
echo "<option value='$partner'>{$nt['rank']} {$nt['firstname']}
{$nt['lastname']}</option>";
echo "</select>";// Closing of list box
?>

Only problem is that I can't seem to update the field anymore.

Marco
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: he
Next Topic: Detecting Redirected Output
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 24 03:49:34 GMT 2024

Total time taken to generate the page: 0.04841 seconds