help to fix a php page I messed up...

I have succeeded in messing up some php code. And since I’m very new to php, I can’t fix it.

Basically we have a page where there is a drop-down box containing all clothing items in our database. The list should default to a specific item in the list, based on a id number in the url (carried over from what was selected on a previous page).
Instead, the drop down box is defaulting to the first item in list from the database. I may have deleted something that requests the particular item in the url (shirt=#). Any ideas?
Here is the code:

[php]

<? $shirts = get_shirts(); foreach($shirts as $shirt) { echo "$shirt[description]\n"; } ?>

[/php]

If the name of variable for id number in URL is id, your code should be corrected like this:
[php]<?
$shirts = get_shirts();

foreach($shirts as $shirt) {
echo “<option value=”$shirt[id]"".($_REQUEST[“id”]==$shirt[id]?" selected":"").">$shirt[description]\n";
}
?>[/php]

When i entered these corrections I got this error:

Parse error: syntax error, unexpected ‘"’, expecting ‘,’ or ‘;’ in (the line that was corrected)

Probably you missed something when copied/pasted. I do not see parse error. But try also to make these changes, this is more accurate:
[php]echo “<option value=”".$shirt[“id”].""".($_REQUEST[“id”]==$shirt[“id”]?" selected":"").">".$shirt[“description”]."\n";[/php]

you are a genius. Thanks for your help

Sponsor our Newsletter | Privacy Policy | Terms of Service