Unstoppable Domains

PHP select query

Spaceship Spaceship
Watch

ridesign1

Established Member
Impact
7
Hi,
I have currently a drop down box on my form which I don't need as there is only one option, how do I alter the code so that the only option is selected and the values for it are returned.
The initial Code:
PHP:
 <form name="program" method="POST">
                            <td width="100%" align="right"height="40" colspan="3"  ><b>ID</b>
                            <select name="programs" onChange="document.program.submit()"><option value="All" ><?=$lhome_AllPrograms?></option>
                                                <?  while($row=mysql_fetch_object($result))

                                                {
                                                if($programs=="$row->program_id")
                                                       $programName="selected";
                                                else
                                                 $programName="";

                                                ?>
                                                  <option <?=$programName?> value="<?=$row->program_id?>"> PGM=<?=$row->program_id?>ย <?=stripslashes($row->program_url)?> </option>
                                                <?
                                                }
                                                ?>
                             </select>
                             </td>
                             </form>

I have changed it to this, but it doesn't return the value of the default selected option. It doesn't need to be be a drop down box as there is one option only.

PHP:
<form name="program" method="POST">
                            <td width="100%" align="right"height="40" colspan="3"  ><b>ID</b>
                            <select name="programs" onChange="document.program.submit()">
                                                <?  while($row=mysql_fetch_object($result))

                                                {
                                                if($programs=="$row->program_id")
                                                       $programName="selected";
                                                else
                                                 $programName="";

                                                ?>
                                                  <option <?=$programName?> value="<?=$row->program_id?>"> PGM=<?=$row->program_id?>ย <?=stripslashes($row->program_url)?>  </option>                                                 <?
                                                }
                                                ?>
                             </select>
                             </td>
                             </form>
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
What I would suggest doing is taking out that option completley from the HTML form, and having PHP work with that 1 option "behind the scenes" if you know what I mean.

I think that would be the simplest thing to do, and it wouldn't confuse your site visitors.
 
0
•••
As Rudy says, take the drop down box out of the form, then I would add a hidden field which sets a parameter variable as though the selection had been made with the drop down box.

No need to change the backend coding that way.

Mike
 
0
•••
but the options on the dropdown come from the database and are different for each user, so would i need to do a sql query to search for the first available option based on the user id?

thanks for your help
 
0
•••
Yes ... sounds like it would work. In that case, I would do it as Rudy suggests, just drop the control from the form and do the processing behind the scenes (assuming you know which user it is after the form post).

Mike
 
0
•••
thanks will give that a go
 
0
•••
Dynadot โ€” .com Registration $8.99Dynadot โ€” .com Registration $8.99
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Payment Flexibility
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back