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
Switch to threaded view of this topic Create a new topic Submit Reply
populate pulldownbox from query [message #174051] Fri, 20 May 2011 18:30 Go to next message
Co is currently offline  Co
Messages: 75
Registered: May 2011
Karma: 0
Member
Hi All,

I am having trouble populating a pulldownbox with records from a table
in mySQL database.

I have a table with personnel records.
One of the fields is partner which holds a numeric value pointing to
the id of another record.
I am trying to get the value of the currently selected person's
partner.

for example:
id=1 name=John partner=2
id=2 name=Jane partner=1

With the code I use I do get the pulldownbox filled but it doesn't
display the name right partner info in the box.

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

Can anyone help me here?

Regards
Marco
Re: populate pulldownbox from query [message #174053 is a reply to message #174051] Fri, 20 May 2011 18:40 Go to previous messageGo to next message
Luuk is currently offline  Luuk
Messages: 329
Registered: September 2010
Karma: 0
Senior Member
On 20-05-2011 20:30, Co wrote:
> echo "<option value=$partner>$nt[rank] $nt[firstname] $nt[lastname]</

echo "<option value=$partner>$nt['rank'] $nt['firstname'] $nt['lastname']</

--
Luuk
Re: populate pulldownbox from query [message #174055 is a reply to message #174051] Fri, 20 May 2011 19:13 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/20/2011 2:30 PM, Co wrote:
> echo "<option value=$partner>$nt[rank] $nt[firstname] $nt[lastname]</
> option>";

echo "<option value=$partner>{$nt[rank]} {$nt[firstname]}
{$nt[lastname]}</option>";


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: populate pulldownbox from query [message #174056 is a reply to message #174051] Fri, 20 May 2011 20:06 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Fri, 20 May 2011 11:30:02 -0700, Co wrote:

> Can anyone help me here?

General observation, html attributes, such as the select name, option
values etc should be enclosed in quotes at the html level, such as one of
the following:

echo "<option value='$some_var_name'>some text</value>";
echo "<option value=\"$some_var_name\">some text</value>";
echo '<option value="$some_var_name">some text</value>';

Rgds

Denis McMahon
Re: populate pulldownbox from query [message #174057 is a reply to message #174055] Fri, 20 May 2011 20:19 Go to previous messageGo to next message
Denis McMahon is currently offline  Denis McMahon
Messages: 634
Registered: September 2010
Karma: 0
Senior Member
On Fri, 20 May 2011 15:13:01 -0400, Jerry Stuckle wrote:

> On 5/20/2011 2:30 PM, Co wrote:
>> echo "<option value=$partner>$nt[rank] $nt[firstname] $nt[lastname]</
>> option>";
>
> echo "<option value=$partner>{$nt[rank]} {$nt[firstname]}
> {$nt[lastname]}</option>";

Hmm

I thought:

echo "<option value='$partner'>{$nt['rank']} {$nt['firstname']}
{$nt['lastname']}</option>";

But I'm failing to find an appropriate page in the manual for a
definitive answer.

Rgds

Denis McMahon
Re: populate pulldownbox from query [message #174058 is a reply to message #174057] Fri, 20 May 2011 20:41 Go to previous messageGo to next message
Michael Fesser is currently offline  Michael Fesser
Messages: 215
Registered: September 2010
Karma: 0
Senior Member
.oO(Denis McMahon)

> On Fri, 20 May 2011 15:13:01 -0400, Jerry Stuckle wrote:
>
>> On 5/20/2011 2:30 PM, Co wrote:
>>> echo "<option value=$partner>$nt[rank] $nt[firstname] $nt[lastname]</
>>> option>";
>>
>> echo "<option value=$partner>{$nt[rank]} {$nt[firstname]}
>> {$nt[lastname]}</option>";
>
> Hmm
>
> I thought:
>
> echo "<option value='$partner'>{$nt['rank']} {$nt['firstname']}
> {$nt['lastname']}</option>";

Correct.

> But I'm failing to find an appropriate page in the manual for a
> definitive answer.

Complex (curly) syntax
http://www.php.net/manual/en/language.types.string.php#language.types.strin g.parsing.complex

Micha
Re: populate pulldownbox from query [message #174060 is a reply to message #174056] Fri, 20 May 2011 21:02 Go to previous messageGo to next message
Co is currently offline  Co
Messages: 75
Registered: May 2011
Karma: 0
Member
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
Re: populate pulldownbox from query [message #174061 is a reply to message #174056] Fri, 20 May 2011 22:16 Go to previous messageGo to next message
Jeff North is currently offline  Jeff North
Messages: 58
Registered: November 2010
Karma: 0
Member
On 20 May 2011 20:06:38 GMT, in comp.lang.php Denis McMahon
<denis(dot)m(dot)f(dot)mcmahon(at)gmail(dot)com>
<4dd6c9cd$0$30688$bed64819(at)gradwell(dot)net> wrote:

> | On Fri, 20 May 2011 11:30:02 -0700, Co wrote:
> |
> | > Can anyone help me here?
> |
> | General observation, html attributes, such as the select name, option
> | values etc should be enclosed in quotes at the html level, such as one of
> | the following:
> |
> | echo "<option value='$some_var_name'>some text</value>";
> | echo "<option value=\"$some_var_name\">some text</value>";
> | echo '<option value="$some_var_name">some text</value>';
> |
> | Rgds
> |
> | Denis McMahon
Not to quibble about such a matter but you don't necessarily need
quotes around attributes (I prefer quotes as any syntax highlighting
editor will show the values up).

http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2
In certain cases, authors may specify the value of an attribute
without any quotation marks. The attribute value may only contain
letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45),
periods (ASCII decimal 46), underscores (ASCII decimal 95), and colons
(ASCII decimal 58). We recommend using quotation marks even when it is
possible to eliminate them.
Re: populate pulldownbox from query [message #174063 is a reply to message #174060] Fri, 20 May 2011 22:24 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/20/2011 5:02 PM, Co 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

Again, what is this in relation to?

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: populate pulldownbox from query [message #174064 is a reply to message #174057] Fri, 20 May 2011 22:28 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/20/2011 4:19 PM, Denis McMahon wrote:
> On Fri, 20 May 2011 15:13:01 -0400, Jerry Stuckle wrote:
>
>> On 5/20/2011 2:30 PM, Co wrote:
>>> echo "<option value=$partner>$nt[rank] $nt[firstname] $nt[lastname]</
>>> option>";
>>
>> echo "<option value=$partner>{$nt[rank]} {$nt[firstname]}
>> {$nt[lastname]}</option>";
>
> Hmm
>
> I thought:
>
> echo "<option value='$partner'>{$nt['rank']} {$nt['firstname']}
> {$nt['lastname']}</option>";
>
> But I'm failing to find an appropriate page in the manual for a
> definitive answer.
>
> Rgds
>
> Denis McMahon

Yup, you're right - I was concentrating on the braces and forgot the quotes.

Mea culpa.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: populate pulldownbox from query [message #174065 is a reply to message #174061] Fri, 20 May 2011 22:29 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/20/2011 6:16 PM, Jeff North wrote:
> On 20 May 2011 20:06:38 GMT, in comp.lang.php Denis McMahon
> <denis(dot)m(dot)f(dot)mcmahon(at)gmail(dot)com>
> <4dd6c9cd$0$30688$bed64819(at)gradwell(dot)net> wrote:
>
>> | On Fri, 20 May 2011 11:30:02 -0700, Co wrote:
>> |
>> |> Can anyone help me here?
>> |
>> | General observation, html attributes, such as the select name, option
>> | values etc should be enclosed in quotes at the html level, such as one of
>> | the following:
>> |
>> | echo "<option value='$some_var_name'>some text</value>";
>> | echo "<option value=\"$some_var_name\">some text</value>";
>> | echo '<option value="$some_var_name">some text</value>';
>> |
>> | Rgds
>> |
>> | Denis McMahon
> Not to quibble about such a matter but you don't necessarily need
> quotes around attributes (I prefer quotes as any syntax highlighting
> editor will show the values up).
>
> http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2
> In certain cases, authors may specify the value of an attribute
> without any quotation marks. The attribute value may only contain
> letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45),
> periods (ASCII decimal 46), underscores (ASCII decimal 95), and colons
> (ASCII decimal 58). We recommend using quotation marks even when it is
> possible to eliminate them.

I believe that's why he said SHOULD, and not MUST.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: populate pulldownbox from query [message #174067 is a reply to message #174058] Fri, 20 May 2011 22:44 Go to previous messageGo to next message
Chuck Anderson is currently offline  Chuck Anderson
Messages: 63
Registered: September 2010
Karma: 0
Member
Michael Fesser wrote:
> .oO(Denis McMahon)
>
>
>> On Fri, 20 May 2011 15:13:01 -0400, Jerry Stuckle wrote:
>>
>>
>>> On 5/20/2011 2:30 PM, Co wrote:
>>>
>>>> echo "<option value=$partner>$nt[rank] $nt[firstname] $nt[lastname]</
>>>> option>";
>>>>
>>> echo "<option value=$partner>{$nt[rank]} {$nt[firstname]}
>>> {$nt[lastname]}</option>";
>>>
>> Hmm
>>
>> I thought:
>>
>> echo "<option value='$partner'>{$nt['rank']} {$nt['firstname']}
>> {$nt['lastname']}</option>";
>>
>
> Correct.
>
>
>> But I'm failing to find an appropriate page in the manual for a
>> definitive answer.
>>
>
> Complex (curly) syntax
> http://www.php.net/manual/en/language.types.string.php#language.types.strin g.parsing.complex
>
> Micha
>

Since constants are not evaluated within strings, the quotes on array
keys and curly braces are not needed.

(from http://www.php.net/manual/en/language.types.array.php )
// The following is okay, as it's inside a string. Constants are not
looked for
// within strings, so no E_NOTICE occurs here
print "Hello $arr[fruit]"; // Hello apple


The OP's original syntax is valid.
echo "<option value=$nt[id]>$nt[rank] $nt[firstname]
$nt[lastname]</option>";

The formatting of the "<option ..." line is not the problem.

I'd put print_r($nt) within the while loop and look at the query results.

--
*****************************
Chuck Anderson • Boulder, CO
http://cycletourist.com
Turn Off, Tune Out, Drop In
*****************************
Re: populate pulldownbox from query [message #174068 is a reply to message #174065] Fri, 20 May 2011 22:49 Go to previous messageGo to next message
Co is currently offline  Co
Messages: 75
Registered: May 2011
Karma: 0
Member
On 21 mei, 00:29, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 5/20/2011 6:16 PM, Jeff North wrote:
>
>
>
>
>
>
>
>
>
>> On 20 May 2011 20:06:38 GMT, in comp.lang.php Denis McMahon
>> <denis.m.f.mcma...@gmail.com>
>> <4dd6c9cd$0$30688$bed64...@gradwell.net>  wrote:
>
>>> | On Fri, 20 May 2011 11:30:02 -0700, Co wrote:
>>> |
>>> |>  Can anyone help me here?
>>> |
>>> | General observation, html attributes, such as the select name, option
>>> | values etc should be enclosed in quotes at the html level, such as one of
>>> | the following:
>>> |
>>> | echo "<option value='$some_var_name'>some text</value>";
>>> | echo "<option value=\"$some_var_name\">some text</value>";
>>> | echo '<option value="$some_var_name">some text</value>';
>>> |
>>> | Rgds
>>> |
>>> | Denis McMahon
>> Not to quibble about such a matter but you don't necessarily need
>> quotes around attributes (I prefer quotes as any syntax highlighting
>> editor will show the values up).
>
>> http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2
>> In certain cases, authors may specify the value of an attribute
>> without any quotation marks. The attribute value may only contain
>> letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45),
>> periods (ASCII decimal 46), underscores (ASCII decimal 95), and colons
>> (ASCII decimal 58). We recommend using quotation marks even when it is
>> possible to eliminate them.
>
> I believe that's why he said SHOULD, and not MUST.
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

sorry Jerry you lost me.
The form I am using this on is an profile edit page.
The user should get all his profile data and be able to change it and
save it.
That is why I need the value from the database along with the names
loaded in the listbox.

Marco
Re: populate pulldownbox from query [message #174070 is a reply to message #174067] Fri, 20 May 2011 22:56 Go to previous messageGo to next message
Co is currently offline  Co
Messages: 75
Registered: May 2011
Karma: 0
Member
On 21 mei, 00:44, Chuck Anderson <cycletour...@invalid.invalid> wrote:
> Michael Fesser wrote:
>> .oO(Denis McMahon)
>
>>> On Fri, 20 May 2011 15:13:01 -0400, Jerry Stuckle wrote:
>
>>>> On 5/20/2011 2:30 PM, Co wrote:
>
>>>> > echo "<option value=$partner>$nt[rank] $nt[firstname] $nt[lastname]</
>>>> > option>";
>
>>>> echo "<option value=$partner>{$nt[rank]} {$nt[firstname]}
>>>> {$nt[lastname]}</option>";
>
>>> Hmm
>
>>> I thought:
>
>>> echo "<option value='$partner'>{$nt['rank']} {$nt['firstname']}
>>> {$nt['lastname']}</option>";
>
>> Correct.
>
>>> But I'm failing to find an appropriate page in the manual for a
>>> definitive answer.
>
>> Complex (curly) syntax
>> http://www.php.net/manual/en/language.types.string.php#language.types...
>
>> Micha
>
> Since constants are not evaluated within strings, the quotes on array
> keys and curly braces are not needed.
>
> (fromhttp://www.php.net/manual/en/language.types.array.php)
> // The following is okay, as it's inside a string. Constants are not
> looked for
> // within strings, so no E_NOTICE occurs here
> print "Hello $arr[fruit]"; // Hello apple
>
> The OP's original syntax is valid.
> echo "<option value=$nt[id]>$nt[rank] $nt[firstname]
> $nt[lastname]</option>";
>
> The formatting of the "<option ..." line is not the problem.
>
> I'd put print_r($nt) within the while loop and look at the query results.
>
> --
> *****************************
>  Chuck Anderson Boulder, CO
> http://cycletourist.com
>  Turn Off, Tune Out, Drop In
> *****************************

Chuck,

you are right. All the values get loaded in the listbox.
However the box itself stays empty. That shouldnt be.
There should be the name of the partner of the user in there.
Because it is represented by a numeric value, I think it gives a
problem.

Marco
Re: populate pulldownbox from query [message #174072 is a reply to message #174051] Fri, 20 May 2011 23:02 Go to previous messageGo to next message
Jeff North is currently offline  Jeff North
Messages: 58
Registered: November 2010
Karma: 0
Member
On Fri, 20 May 2011 11:30:02 -0700 (PDT), in comp.lang.php Co
<vonclausowitz(at)gmail(dot)com>
<7e34dca3-a1f3-4bdf-acbd-8288e6a30581(at)gu8g2000vbb(dot)googlegroups(dot)com>
wrote:

> | Hi All,
> |
> | I am having trouble populating a pulldownbox with records from a table
> | in mySQL database.
> |
> | I have a table with personnel records.
> | One of the fields is partner which holds a numeric value pointing to
> | the id of another record.
> | I am trying to get the value of the currently selected person's
> | partner.
> |
> | for example:
> | id=1 name=John partner=2
> | id=2 name=Jane partner=1
> |
> | With the code I use I do get the pulldownbox filled but it doesn't
> | display the name right partner info in the box.
> |
> | $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 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
> | ?>
> |
> | Can anyone help me here?
> |
> | Regards
> | Marco

When you View Source of the page what do you see where the lists are
supposed to be (there could be php error messages hiding there).
Re: populate pulldownbox from query [message #174073 is a reply to message #174072] Sat, 21 May 2011 02:29 Go to previous messageGo to next message
Chuck Anderson is currently offline  Chuck Anderson
Messages: 63
Registered: September 2010
Karma: 0
Member
Jeff North wrote:
> On Fri, 20 May 2011 11:30:02 -0700 (PDT), in comp.lang.php Co
> <vonclausowitz(at)gmail(dot)com>
> <7e34dca3-a1f3-4bdf-acbd-8288e6a30581(at)gu8g2000vbb(dot)googlegroups(dot)com>
> wrote:
>
>
>> | Hi All,
>> |
>> | I am having trouble populating a pulldownbox with records from a table
>> | in mySQL database.
>> |
>> | I have a table with personnel records.
>> | One of the fields is partner which holds a numeric value pointing to
>> | the id of another record.
>> | I am trying to get the value of the currently selected person's
>> | partner.
>> |
>> | for example:
>> | id=1 name=John partner=2
>> | id=2 name=Jane partner=1
>> |
>> | With the code I use I do get the pulldownbox filled but it doesn't
>> | display the name right partner info in the box.
>> |
>> | $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 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
>> | ?>
>> |
>> | Can anyone help me here?
>> |
>> | Regards
>> | Marco
>>
>
> When you View Source of the page what do you see where the lists are
> supposed to be (there could be php error messages hiding there).
>

I always get tripped up by that one as it's common (for me) to output
the select tag followed by a php loop to create options. This puts the
error message within the select block and the browser does not display it.

--
*****************************
Chuck Anderson • Boulder, CO
http://cycletourist.com
Turn Off, Tune Out, Drop In
*****************************
Re: populate pulldownbox from query [message #174075 is a reply to message #174070] Sat, 21 May 2011 02:33 Go to previous messageGo to next message
Chuck Anderson is currently offline  Chuck Anderson
Messages: 63
Registered: September 2010
Karma: 0
Member
Co wrote:
> On 21 mei, 00:44, Chuck Anderson <cycletour...@invalid.invalid> wrote:
>
>> Michael Fesser wrote:
>>
>>> .oO(Denis McMahon)
>>>
>>>> On Fri, 20 May 2011 15:13:01 -0400, Jerry Stuckle wrote:
>>>>
>>>> > On 5/20/2011 2:30 PM, Co wrote:
>>>> >
>>>> >> echo "<option value=$partner>$nt[rank] $nt[firstname] $nt[lastname]</
>>>> >> option>";
>>>> >>
>>>> > echo "<option value=$partner>{$nt[rank]} {$nt[firstname]}
>>>> > {$nt[lastname]}</option>";
>>>> >
>>>> Hmm
>>>>
>>>> I thought:
>>>>
>>>> echo "<option value='$partner'>{$nt['rank']} {$nt['firstname']}
>>>> {$nt['lastname']}</option>";
>>>>
>>> Correct.
>>>
>>>> But I'm failing to find an appropriate page in the manual for a
>>>> definitive answer.
>>>>
>>> Complex (curly) syntax
>>> http://www.php.net/manual/en/language.types.string.php#language.types...
>>>
>>> Micha
>>>
>> Since constants are not evaluated within strings, the quotes on array
>> keys and curly braces are not needed.
>>
>> (fromhttp://www.php.net/manual/en/language.types.array.php)
>> // The following is okay, as it's inside a string. Constants are not
>> looked for
>> // within strings, so no E_NOTICE occurs here
>> print "Hello $arr[fruit]"; // Hello apple
>>
>> The OP's original syntax is valid.
>> echo "<option value=$nt[id]>$nt[rank] $nt[firstname]
>> $nt[lastname]</option>";
>>
>> The formatting of the "<option ..." line is not the problem.
>>
>> I'd put print_r($nt) within the while loop and look at the query results.
>>
>>
> Chuck,
>
> you are right. All the values get loaded in the listbox.
> However the box itself stays empty. That shouldnt be.
> There should be the name of the partner of the user in there.
> Because it is represented by a numeric value, I think it gives a
> problem.
>
>

Did you try my print_r suggestion - and look at the page source for it's
output - or error messages - hidden in the select block?

--
*****************************
Chuck Anderson • Boulder, CO
http://cycletourist.com
Turn Off, Tune Out, Drop In
*****************************
Re: populate pulldownbox from query [message #174077 is a reply to message #174070] Sat, 21 May 2011 02:36 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/20/2011 6:56 PM, Co wrote:
> On 21 mei, 00:44, Chuck Anderson<cycletour...@invalid.invalid> wrote:
>> Michael Fesser wrote:
>>> .oO(Denis McMahon)
>>
>>>> On Fri, 20 May 2011 15:13:01 -0400, Jerry Stuckle wrote:
>>
>>>> > On 5/20/2011 2:30 PM, Co wrote:
>>
>>>> >> echo "<option value=$partner>$nt[rank] $nt[firstname] $nt[lastname]</
>>>> >> option>";
>>
>>>> > echo "<option value=$partner>{$nt[rank]} {$nt[firstname]}
>>>> > {$nt[lastname]}</option>";
>>
>>>> Hmm
>>
>>>> I thought:
>>
>>>> echo "<option value='$partner'>{$nt['rank']} {$nt['firstname']}
>>>> {$nt['lastname']}</option>";
>>
>>> Correct.
>>
>>>> But I'm failing to find an appropriate page in the manual for a
>>>> definitive answer.
>>
>>> Complex (curly) syntax
>>> http://www.php.net/manual/en/language.types.string.php#language.types...
>>
>>> Micha
>>
>> Since constants are not evaluated within strings, the quotes on array
>> keys and curly braces are not needed.
>>
>> (fromhttp://www.php.net/manual/en/language.types.array.php)
>> // The following is okay, as it's inside a string. Constants are not
>> looked for
>> // within strings, so no E_NOTICE occurs here
>> print "Hello $arr[fruit]"; // Hello apple
>>
>> The OP's original syntax is valid.
>> echo "<option value=$nt[id]>$nt[rank] $nt[firstname]
>> $nt[lastname]</option>";
>>
>> The formatting of the "<option ..." line is not the problem.
>>
>> I'd put print_r($nt) within the while loop and look at the query results.
>>
>> --
>> *****************************
>> Chuck Anderson Boulder, CO
>> http://cycletourist.com
>> Turn Off, Tune Out, Drop In
>> *****************************
>
> Chuck,
>
> you are right. All the values get loaded in the listbox.
> However the box itself stays empty. That shouldnt be.
> There should be the name of the partner of the user in there.
> Because it is represented by a numeric value, I think it gives a
> problem.
>
> Marco

Marco, that part is strictly an HTML problem. Try alt.html.

--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: populate pulldownbox from query [message #174078 is a reply to message #174068] Sat, 21 May 2011 02:44 Go to previous messageGo to next message
Jerry Stuckle is currently offline  Jerry Stuckle
Messages: 2598
Registered: September 2010
Karma: 0
Senior Member
On 5/20/2011 6:49 PM, Co wrote:
> On 21 mei, 00:29, Jerry Stuckle<jstuck...@attglobal.net> wrote:
>> On 5/20/2011 6:16 PM, Jeff North wrote:
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>> On 20 May 2011 20:06:38 GMT, in comp.lang.php Denis McMahon
>>> <denis.m.f.mcma...@gmail.com>
>>> <4dd6c9cd$0$30688$bed64...@gradwell.net> wrote:
>>
>>>> | On Fri, 20 May 2011 11:30:02 -0700, Co wrote:
>>>> |
>>>> |> Can anyone help me here?
>>>> |
>>>> | General observation, html attributes, such as the select name, option
>>>> | values etc should be enclosed in quotes at the html level, such as one of
>>>> | the following:
>>>> |
>>>> | echo "<option value='$some_var_name'>some text</value>";
>>>> | echo "<option value=\"$some_var_name\">some text</value>";
>>>> | echo '<option value="$some_var_name">some text</value>';
>>>> |
>>>> | Rgds
>>>> |
>>>> | Denis McMahon
>>> Not to quibble about such a matter but you don't necessarily need
>>> quotes around attributes (I prefer quotes as any syntax highlighting
>>> editor will show the values up).
>>
>>> http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2
>>> In certain cases, authors may specify the value of an attribute
>>> without any quotation marks. The attribute value may only contain
>>> letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45),
>>> periods (ASCII decimal 46), underscores (ASCII decimal 95), and colons
>>> (ASCII decimal 58). We recommend using quotation marks even when it is
>>> possible to eliminate them.
>>
>> I believe that's why he said SHOULD, and not MUST.
>>
>
> sorry Jerry you lost me.
> The form I am using this on is an profile edit page.
> The user should get all his profile data and be able to change it and
> save it.
> That is why I need the value from the database along with the names
> loaded in the listbox.
>
> Marco

Marco, that comment wasn't directed at you.

Your first problem is - are you getting the correct data from the
database? If not, you need to do that first - which is a MySQL
question, not a PHP one (and should be asked in comp.databases.mysql).

If you are getting the correct information back from the database,
what's wrong with the partner name?


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex(at)attglobal(dot)net
==================
Re: populate pulldownbox from query [message #174082 is a reply to message #174075] Sat, 21 May 2011 07:27 Go to previous messageGo to next message
Co is currently offline  Co
Messages: 75
Registered: May 2011
Karma: 0
Member
On 21 mei, 04:33, Chuck Anderson <cycletour...@invalid.invalid> wrote:
> Co wrote:
>> On 21 mei, 00:44, Chuck Anderson <cycletour...@invalid.invalid> wrote:
>
>>> Michael Fesser wrote:
>
>>>> .oO(Denis McMahon)
>
>>>> > On Fri, 20 May 2011 15:13:01 -0400, Jerry Stuckle wrote:
>
>>>> >> On 5/20/2011 2:30 PM, Co wrote:
>
>>>> >>> echo "<option value=$partner>$nt[rank] $nt[firstname] $nt[lastname]</
>>>> >>> option>";
>
>>>> >> echo "<option value=$partner>{$nt[rank]} {$nt[firstname]}
>>>> >> {$nt[lastname]}</option>";
>
>>>> > Hmm
>
>>>> > I thought:
>
>>>> > echo "<option value='$partner'>{$nt['rank']} {$nt['firstname']}
>>>> > {$nt['lastname']}</option>";
>
>>>> Correct.
>
>>>> > But I'm failing to find an appropriate page in the manual for a
>>>> > definitive answer.
>
>>>> Complex (curly) syntax
>>>> http://www.php.net/manual/en/language.types.string.php#language.types....
>
>>>> Micha
>
>>> Since constants are not evaluated within strings, the quotes on array
>>> keys and curly braces are not needed.
>
>>> (fromhttp://www.php.net/manual/en/language.types.array.php)
>>> // The following is okay, as it's inside a string. Constants are not
>>> looked for
>>> // within strings, so no E_NOTICE occurs here
>>> print "Hello $arr[fruit]"; // Hello apple
>
>>> The OP's original syntax is valid.
>>> echo "<option value=$nt[id]>$nt[rank] $nt[firstname]
>>> $nt[lastname]</option>";
>
>>> The formatting of the "<option ..." line is not the problem.
>
>>> I'd put print_r($nt) within the while loop and look at the query results.
>
>> Chuck,
>
>> you are right. All the values get loaded in the listbox.
>> However the box itself stays empty. That shouldnt be.
>> There should be the name of the partner of the user in there.
>> Because it is represented by a numeric value, I think it gives a
>> problem.
>
> Did you try my print_r suggestion - and look at the page source for it's
> output - or error messages - hidden in the select block?
>
> --
> *****************************
>  Chuck Anderson • Boulder, CO
> http://cycletourist.com
>  Turn Off, Tune Out, Drop In
> *****************************

Chuck,

it doesn't show probably it gets filled before I see the page.

Marco
Re: populate pulldownbox from query [message #174083 is a reply to message #174078] Sat, 21 May 2011 07:29 Go to previous messageGo to next message
Co is currently offline  Co
Messages: 75
Registered: May 2011
Karma: 0
Member
On 21 mei, 04:44, Jerry Stuckle <jstuck...@attglobal.net> wrote:
> On 5/20/2011 6:49 PM, Co wrote:
>
>
>
>
>
>
>
>
>
>> On 21 mei, 00:29, Jerry Stuckle<jstuck...@attglobal.net>  wrote:
>>> On 5/20/2011 6:16 PM, Jeff North wrote:
>
>>>> On 20 May 2011 20:06:38 GMT, in comp.lang.php Denis McMahon
>>>> <denis.m.f.mcma...@gmail.com>
>>>> <4dd6c9cd$0$30688$bed64...@gradwell.net>    wrote:
>
>>>> > | On Fri, 20 May 2011 11:30:02 -0700, Co wrote:
>>>> > |
>>>> > |>    Can anyone help me here?
>>>> > |
>>>> > | General observation, html attributes, such as the select name, option
>>>> > | values etc should be enclosed in quotes at the html level, such as one of
>>>> > | the following:
>>>> > |
>>>> > | echo "<option value='$some_var_name'>some text</value>";
>>>> > | echo "<option value=\"$some_var_name\">some text</value>";
>>>> > | echo '<option value="$some_var_name">some text</value>';
>>>> > |
>>>> > | Rgds
>>>> > |
>>>> > | Denis McMahon
>>>> Not to quibble about such a matter but you don't necessarily need
>>>> quotes around attributes (I prefer quotes as any syntax highlighting
>>>> editor will show the values up).
>
>>>> http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2
>>>> In certain cases, authors may specify the value of an attribute
>>>> without any quotation marks. The attribute value may only contain
>>>> letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45),
>>>> periods (ASCII decimal 46), underscores (ASCII decimal 95), and colons
>>>> (ASCII decimal 58). We recommend using quotation marks even when it is
>>>> possible to eliminate them.
>
>>> I believe that's why he said SHOULD, and not MUST.
>
>> sorry Jerry you lost me.
>> The form I am using this on is an profile edit page.
>> The user should get all his profile data and be able to change it and
>> save it.
>> That is why I need the value from the database along with the names
>> loaded in the listbox.
>
>> Marco
>
> Marco, that comment wasn't directed at you.
>
> Your first problem is - are you getting the correct data from the
> database?  If not, you need to do that first - which is a MySQL
> question, not a PHP one (and should be asked in comp.databases.mysql).
>
> If you are getting the correct information back from the database,
> what's wrong with the partner name?
>
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================

I do get the right data from the database.
The listbox gets filled correctly.

It is just that the name which is currently set as partner doesn't
show in the box.
I tried to fix that with:
echo "<option value='$partner'>{$nt['rank']} {$nt['firstname']}
{$nt['lastname']}</option>";
Problem is that I cannot do it at first I have to wait until the do
while loop for filling the listbox
has run.

Marco
Re: populate pulldownbox from query [message #174088 is a reply to message #174060] Sat, 21 May 2011 11:00 Go to previous messageGo to next message
tony is currently offline  tony
Messages: 19
Registered: December 2010
Karma: 0
Junior Member
In article <cddfd7a4-dfb5-48c0-8ecc-e2c86baaff2e(at)glegroupsg2000goo(dot)googlegroups(dot)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: tony(at)softins(dot)co(dot)uk - http://www.softins.co.uk
Play: tony(at)mountifield(dot)org - http://tony.mountifield.org
Re: populate pulldownbox from query [message #174089 is a reply to message #174088] Sat, 21 May 2011 11:39 Go to previous messageGo to next message
Co is currently offline  Co
Messages: 75
Registered: May 2011
Karma: 0
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

should that be in this sentence?
echo "<option value=$nt[id]>{$nt['rank']} {$nt['firstname']}
{$nt['lastname']} </option>";

Marco
Re: populate pulldownbox from query [message #174090 is a reply to message #174088] Sat, 21 May 2011 12:08 Go to previous messageGo to next message
Co is currently offline  Co
Messages: 75
Registered: May 2011
Karma: 0
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
Re: populate pulldownbox from query [message #174091 is a reply to message #174089] Sat, 21 May 2011 12:09 Go to previous messageGo to next message
crankypuss is currently offline  crankypuss
Messages: 147
Registered: March 2011
Karma: 0
Senior Member
Co <vonclausowitz(at)gmail(dot)com> wrote:

> 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
>
> should that be in this sentence?
> echo "<option value=$nt[id]>{$nt['rank']} {$nt['firstname']}
> {$nt['lastname']} </option>";
>
> Marco

This is none of my business, but in my experience writing long lines
of cryptic code is inherently bad. First off, if you get one
character wrong it doesn't work and then there you are. Secondly, the
next guy to pick up your code is going to have to decrypt it all.
Thirdly, if you use several lines of code it's easier to relate an
error message to the offending code, and if you should be so lucky as
to be using an interactive debugger it'll step through each line and
you can actually see what's going on. jmo.

--
no aluminum siding offers today
Re: populate pulldownbox from query [message #174094 is a reply to message #174083] Sat, 21 May 2011 13:05 Go to previous messageGo to next message
TK is currently offline  TK
Messages: 6
Registered: May 2011
Karma: 0
Junior Member
On 5/21/2011 2:29 AM, Co wrote:

> I do get the right data from the database.
> The listbox gets filled correctly.
>
> It is just that the name which is currently set as partner doesn't
> show in the box.
> I tried to fix that with:
> echo "<option value='$partner'>{$nt['rank']} {$nt['firstname']}
> {$nt['lastname']}</option>";
> Problem is that I cannot do it at first I have to wait until the do
> while loop for filling the listbox
> has run.
Inset this in your while loop:
// Substitue your variable names

$f='';
if($rowAff['c_id']==$row['ch_id']) {$f="selected=\"selected\"";}
echo "<option $f
value=\"{$rowAff['c_id']}\">{$rowAff['church']}</option>\n";}

$f makes the current choice show in the option box. If I understood the
problem correctly.


--
TK ~ aka Terry Kimpling
http://wejuggle2.com/
If you can be legally insane, can you not be illegally insane?
Re: populate pulldownbox from query [message #174105 is a reply to message #174061] Sat, 21 May 2011 21:19 Go to previous message
Thomas 'PointedEars'  is currently offline  Thomas 'PointedEars'
Messages: 701
Registered: October 2010
Karma: 0
Senior Member
Jeff North wrote:

[attribution novel trimmed, quotation fixed; see <http://learn.to/quote>]

> Denis McMahon wrote:
>> General observation, html attributes, such as the select name, option
>> values etc should be enclosed in quotes at the html level, such as one
>> of the following:
>>
>> echo "<option value='$some_var_name'>some text</value>";
>> echo "<option value=\"$some_var_name\">some text</value>";
>> echo '<option value="$some_var_name">some text</value>';

The third one is not equivalent to the former two; the outer single quotes
prevent variable expansion. It would have to be

echo '<option value="' . $some_var_name . '">some text</value>';

Another possibility are HereDoc strings:

echo <<<HTML
<option value="{$some_var_name}">some text</value>
HTML;

Do not forget htmlspecialchars($some_var_name) in any case!

> Not to quibble about such a matter but you don't necessarily need
> quotes around attributes (I prefer quotes as any syntax highlighting
> editor will show the values up).
>
> http://www.w3.org/TR/html4/intro/sgmltut.html#h-3.2.2
> In certain cases, authors may specify the value of an attribute
> without any quotation marks. The attribute value may only contain
> letters (a-z and A-Z), digits (0-9), hyphens (ASCII decimal 45),
> periods (ASCII decimal 46), underscores (ASCII decimal 95), and colons
> (ASCII decimal 58). We recommend using quotation marks even when it is
> possible to eliminate them.

Mark the last sentence which is essentially what Denis said, and consider
that XML-based document types *require* the quotes (for well-formedness).


PointedEars
--
var bugRiddenCrashPronePieceOfJunk = (
navigator.userAgent.indexOf('MSIE 5') != -1
&& navigator.userAgent.indexOf('Mac') != -1
) // Plone, register_function.js:16
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: he
Next Topic: Detecting Redirected Output
Goto Forum:
  

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

Current Time: Sat Nov 30 03:25:18 GMT 2024

Total time taken to generate the page: 0.02564 seconds