For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > March 2007 > Re: [PHP-DB] Using multiple submits on a page and retaining $POST data









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Re: [PHP-DB] Using multiple submits on a page and retaining $POST data
Dan Shirah

2007-03-16, 6:58 pm

Try something like this:

****Your query here to get your dropdown values****
**
*// This first option value will set your default dropdown to display as
blank*
echo "<OPTION value=\"\">--SELECT--</OPTION>\n";

*// This will create a loop to return each option of your dropdown*
foreach ($query_result as $q)
{
*// This if statement says that IF the value in your database matches your
$_POST(selected) value then mark it as SELECTED*
if ($q['my_column_value'] == $_POST['my_selected_value'])
echo "<OPTION value=\"{$q['my_column_value']}\"
SELECTED>{$q['my_column_value']}</OPTION>\n";
*// This else statement will return your default(unselected) dropdown list
if it can't match the selected value with a value in your database*
else
echo "<OPTION
value=\"{$q['my_column_value']}\">{$q['my_column_value']}</OPTION>\n";
}

Hope that helps.

On 3/16/07, Onochie Anyanetu <ubernoch@gmail.com> wrote:
>
> Almost what I wanted to do.
>
> I am looking for a way to set the default option value to the selection
> the
> user just chose. for example, something like
>
> <select name=cars value=$_POST['cars']>
>
>
> On 3/16/07, Gunawan Wibisono <landavia81@gmail.com> wrote:
> means
> like:
> to
> and
> the
> u
> but
> statement
> retrieved
> submit
> (using
> was
> disabling
> no
> i
> global
> out
> the
>


Polosur

2007-03-17, 8:22 am

Jessica Alba In Anal Action Movie!
http://Jessica-Alba-In-Anal-Action-...hp?movie=148803
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com