Click to See Complete Forum and Search --> : Help: Drop Down Box controlled by PHP coding.


riz-man
03-04-2008, 02:14 PM
I’ve worked on a PHP website that when uploaded to the Internet works perfectly fine. However, before I uploaded the website to my server, I uploaded it to my Apache directory on my computer (I have the server installed locally). One of the pages uses a drop down list (in a form) and in this drop down list there are two options – 1) “Sort Alphabetically” and 2) “Sort Numerically (by id)”.

When viewing the site locally, why do I see “selected=”selected”>" infront of the “Sort Numerically (by id)” option? The coding does not work on my machine locally because of this. Please view the attached file for your reference.

Does anyone know why this happens? Why do I get the problem locally but not when I upload on the internet?

It's not a serious problem as it works when I upload the site to the Internet but I would like to know for my own reference and because it means that I cannot test that particular part of the website locally.

The actual coding where this apparent problem happens is as follows:

<option value="cat_id"<? if ($shopConfig['categorySort'] == 'cat_id') { ?> selected<? } ?>>Sort Numerically (by id)</option>

Are all the <? ?> } in the right places?

Thank you for your time.

Riz

Sorehead
03-04-2008, 03:55 PM
Hi Riz,

when adding a selected attribute you should enter it like - selected="selected" e.g.

<option value="cat_id"<? if ($shopConfig['categorySort'] == 'cat_id') { ?> selected="selected" <? } ?>>Sort Numerically (by id)</option>

Thats the only thing I can see wrong with the line of code above.

riz-man
03-04-2008, 04:46 PM
Sorehead,

Thanks for you help but unfortunately, that didn't help. The original coding was as you stated - I had changed it in an attempt to find a solution.

I have, however, found the solution now. It involved changing the <? to <?php so that it should look like...

<option value="cat_id"<?php if ($shopConfig['categorySort'] == 'cat_id') { ?> selected<?php } ?>>Sort Numerically (by id)</option>

or rather...

<option value="cat_id"<?php if ($shopConfig['categorySort'] == 'cat_id') { ?> selected="selected" <?php } ?>>Sort Numerically (by id)</option>

with the correct selected attribute as you indicated.

Woo hoo! :)