0

Hello everyone,
I have a problem with my drop down list box on my edit page in php. I would like my drop down list box to show what the user has selected, then if the user wishes to, change their selection updating the DB(mysql) at the same time. I have a couple of radio buttons that does the same thing and works fine.

eg <?php if ($dataArow['garageopt'] == "yes"){ echo ' checked="checked"';}?> />

When i try to apply the same method changing the checked=checked to selected it doesen't work.

<select name="cartype" />   
<option value="<?php if ($dataArow['cartype'] == "tvr"){ echo ' selected="selected"';}?>" />tvr</option>
<option value="<?php if ($$dataArow['cartype'] == "lexus"){ echo 'selected';}?>"/>lexue</option>
<option value="<?php if ($$dataArow['cartype'] == "porche"){ echo 'selected';}?>"/></option>
</select>

Can somebody help me please it would be much appreciated.

Thanks.

Edited by codeblock: n/a

2
Contributors
9
Replies
11
Views
7 Years
Discussion Span
Last Post by Wraithmanilian
0

try:

<select name="cartype" />   
<option value="tvr" <?php if ($dataArow['cartype'] == "tvr"){ echo ' selected="selected"';}?> />tvr</option>
<option value="lexus" <?php if ($dataArow['cartype'] == "lexus"){ echo 'selected="selected"';}?> />lexus</option>
<option value="porche" <?php if ($dataArow['cartype'] == "porche"){ echo 'selected="selected"';}?> /></option>
</select>
0

try:

<select name="cartype" />   
<option value="tvr" <?php if ($dataArow['cartype'] == "tvr"){ echo ' selected="selected"';}?> />tvr</option>
<option value="lexus" <?php if ($dataArow['cartype'] == "lexus"){ echo 'selected="selected"';}?> />lexus</option>
<option value="porche" <?php if ($dataArow['cartype'] == "porche"){ echo 'selected="selected"';}?> /></option>
</select>

Thanks for your help, but it doesn't seem to work quit as much as i would like it to. The DB updates thats great, but when the edit page reloads the drop down list box goes back to the first option (tvr),and not to the one that was selected for update eg porche.

Edited by codeblock: n/a

0

Well, let's run a little test. After the select, add this bit of code:

<!-- <?php echo $dataArow['cartype']; ?> -->

That way, we'll see just what $dataArow contains. If it is returning empty, then nothing in the code would be set to "selected", therefore, the first option would always be selected.

0

Well, let's run a little test. After the select, add this bit of code:

<!-- <?php echo $dataArow['cartype']; ?> -->

That way, we'll see just what $dataArow contains. If it is returning empty, then nothing in the code would be set to "selected", therefore, the first option would always be selected.

Hi Wraithmanilian,
The code you provided show no change, on reload, the first option is returned (tvr).

Edited by codeblock: n/a

0

Hi Wraithmanilian,
The code you provided show no change, on reload, the first option is returned (tvr).

With that page rendered, right-click in your browser and view the source. Look under the select and see what is posted between the <!-- and -->

0

With that page rendered, right-click in your browser and view the source. Look under the select and see what is posted between the <!-- and -->

Nothing.

0

Nothing.

Then THAT means that the variable $dataArow is empty, and since it has to equal SOMETHING in order to choose what sets the selected="selected", then nothing gets chosen, therefore, nothing changes.

The problem is that you are returning zero records. It's a MySQL issue.

0

Then THAT means that the variable $dataArow is empty, and since it has to equal SOMETHING in order to choose what sets the selected="selected", then nothing gets chosen, therefore, nothing changes.

The problem is that you are returning zero records. It's a MySQL issue.

Got it workig now. Thanks for your advice.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.