Jump to content

Downdown list - PHP\

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
8 replies to this topic

#1
shiyam198

shiyam198

    Newbie

  • Members
  • PipPip
  • 16 posts
Hi Guys,

The following segment of code (below) is to create a drop down menu from the "lkgroup" column from the table - lk_group.

But it is giving me the error:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

Any help is appreciated.

Thanks,
Shiyam
<SELECT NAME="group">
<?php
while($row = mysql_fetch_array( $result ))
{
echo "<option VALUE=\"$row[\'lkgroup\']\">$row[\'lkgroup\']</option>";
# echo $row['lkgroup']. "<br/>";
}
?>
</SELECT>

Edited by John, 31 August 2008 - 09:33 PM.
Please use [code] or [php] tags when posting code.


#2
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
while($row = mysql_fetch_array( $result ))

{

echo "<option value={$row['lkgroup']}>{$row['lkgroup']}</option>";

# echo $row['lkgroup']. "<br/>";

}

Please use the [php] [ /php] bbtags when posting php code.

#3
chili5

chili5

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 7,247 posts
echo "<option VALUE=\"$row[\'lkgroup\']\">$row[\'lkgroup\']</option>";

Why are you escaping all the ' characters? In fact, I don't really think you need those, because of the double quotes.

echo "<option value=\"$row[lkgroup]\">$row[lkgroup]</option>";

You could also write it like:

echo "<option value=\"" . $row['lkgroup'] . "\">" . $row['lkgroup'] . "</option>";

You don't need to escape the ' characters unless your starting your echo statement with '.

#4
shiyam198

shiyam198

    Newbie

  • Members
  • PipPip
  • 16 posts
Thank you Sir. Your last suggestion worked fine.

#5
Xav

Xav

    Writes binary right handed and hex left handed

  • Members
  • PipPipPipPipPipPipPipPipPip
  • 13,118 posts
Ya see, chil, he called you Sir. :D
Jordan said:

Good members, like yourself, stick around and post for ages to come!
Mr. Xav | Blog | Forums

#6
ArtoStiloz

ArtoStiloz

    Programmer

  • Members
  • PipPipPipPip
  • 175 posts

shiyam198 said:

Thank you Sir. Your last suggestion worked fine.

What about 2. Suggestion?
[SIGPIC][/SIGPIC]
Http://www.ArtoStiloz.Dk

#7
morefood2001

morefood2001

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,720 posts
I believe that using a single ' will work, however I prefer using ". ." in this case.


echo "<option value=\"'$row[lkgroup]'\">'$row[lkgroup]'</option>";



#8
John

John

    Writes binary right handed and hex left handed

  • Moderators
  • 6,321 posts
What about the ' inside $row[lkgroup]? As in $row['lkgroup']

#9
morefood2001

morefood2001

    Speaks fluent binary

  • Members
  • PipPipPipPipPipPipPipPip
  • 1,720 posts

John said:

What about the ' inside $row[lkgroup]? As in $row['lkgroup']

That obviously won't work, thanks for pointing that out.