Forum Moderators: coopster

Message Too Old, No Replies

Drop Menu From MySQL Array and pass other variables

         

recsx

6:20 pm on May 30, 2004 (gmt 0)

10+ Year Member



Need some help if possible

I Have a Drop menu that is populated from a mysql_querry

the array is built and all is good; but i need another value passed to a hidden field as to what option was selected.

Say i have the menu filled from mysql
<OPTION VALUE="Value1">Option1</OPTION>
<OPTION VALUE="Value2">Option2</OPTION>
<OPTION VALUE="Value3">Option3</OPTION>

and i select Option2, i need the Attributes that coresponds from Option2 in the database to be echoed to the hidden field within $PHP_SELF e.g. auto do it else on change or something so that the main form is ready to be submited with the new values.

Database Structure
¦-Field1 -¦-Field2 -¦-Field3 -¦-Attributes-¦
¦ Value1 ¦ Value2 ¦ Value3 ¦ The Attrib ¦
--------------------------------------------
The select tag
This is Populated from a MySQL DB
<SELECT Name="select">
<OPTION VALUE="Value1">Option1</OPTION>
<OPTION VALUE="Value2">Option2</OPTION>
<OPTION VALUE="Value3">Option3</OPTION>
</SELECT>

<INPUT TYPE="hidden" VALUE="<?PHH echo $the Attributes from what was selected?>">

How can i do this without using JavaScript and just PHP
i need it server side so in case the user has turned off JavaScript

HERE IS MY CURRENT SCRIPT:

<?PHP
$package_result = mysql_query("SELECT * FROM packages",$mysql_ID);

echo '<select name="package" TABINDEX="18"><OPTION>';
echo $myrow["package"];
echo "</OPTION>";

while ($row_item = mysql_fetch_assoc($package_result)){
$pname = $row_item["pname"];
echo "<OPTION value=\"$pname\">$pname</OPTION>";
}
echo '</SELECT>';
mysql_free_result ($package_result);
?>
<INPUT TYPE="hidden" VALUE="<?PHP echo $i need it here?>">

WhosAWhata

8:59 pm on May 30, 2004 (gmt 0)

10+ Year Member



sorry,
the whole point to a server-side script (like PHP) is that everything is done before it reaches the user there is no onChange function to PHP, JavaScript is the only option unless you are willing to reload the page everytime the user changes their selection

an alternative might be to have the javascript in place, but set the page to reload in the <noscript> or whatever you call it,
good luck

recsx

9:21 pm on May 30, 2004 (gmt 0)

10+ Year Member



Thanks for the reply.

I guess i'll try and rephrase this.
I dont want JavaScript.
It was fun in the past but now that i am making application (Not big ones at that) for online use i realy realy dont want someone using this app with JavaScript turned off as it will not post proper information to the dabase.
This database is for RADIUS attributes passed to clients on a wide are Wireless ISP network.

So...

Say i have a drop list populated by a query to the database how can i sort the results?

there must be a way that says for what ever option you selected place its value in another variable NO? YES?

like say
if ($drop_list){
do this?
}
im not even sure if PHP can tell that a drop list has changed from what i know it only knows about SUBMIT buttons YES? NO?

i think that this is an interesting subject and should be looked into further.

Give me some input if you have time.

Thanks

WhosAWhata

9:28 pm on May 30, 2004 (gmt 0)

10+ Year Member



this is basically how it breaks down
once the page loads, PHP doesn't "see" anything that happens
once you submit a form, the page is reloaded (or changes to a new page) so PHP gets to see any form variables that were passed
the only way to repopulate a dropdown menu with php would be to submit the form eveytime something on the page changes, then procees it and send it back (YOU DO NOT WANT TO DO THIS! VERY MESSY)

the best way is to use javascript, then add something to say if the user has javascript disabled(there is an HTML tag for this) then reload evertime your thing changes

recsx

9:35 pm on May 30, 2004 (gmt 0)

10+ Year Member



Ok thanks.

I think you answered my question.

I guess I was looking for a miracle basically searching for something that was never there.

I knew that PHP could not see anything that was there unless you submitted it but like the submit button when presses it can see that something has changed.

And i was thinking about a JavaScript not enabled kinda thing like (Sorry you don’t have JavaScript GO AWAY!) sorta thing but i did not know that there was a basic generic HTML tag to check it, if there is then maybe i will have to go that route cause like you say posting to many *.php script is very messy and i don't like it ether.

Right now my app (Not Form) is very large all within one file and I don’t want to mess with it.

So in conclusion:
What is this nifty tag that says you aint got JS?

if you don’t mind?

Thanks

recsx

10:21 pm on May 30, 2004 (gmt 0)

10+ Year Member



OK Duh!

<NOSCRIPT>
Bla Bla you aint got JS
</NOSCRIPT>

but hey i always try and go the extra mile.

How about this
Can PHP! check if JS in ON or OFF?

I think that checking it with PHP would be better

you can have a script that says if it aint on do this else if it is do this like...

if (JS=true){
My page and all of the rest of my scripts here
}else{
Get lost or turn on your JS or get a new browser
}

Oh! with my luck there is now way to do this

I guess i would have to make a stupid redirect if JS is true or just post a message, i realy hate having to make more files just to do one simple little thing.

Got any thought's?

WhosAWhata

10:48 pm on May 30, 2004 (gmt 0)

10+ Year Member



if($_SERVER['HTTP_USER_AGENT']->javascript==1)

recsx

12:06 am on May 31, 2004 (gmt 0)

10+ Year Member



Kool man u da best

Now if a guy come without JS he will see nothing but a message

else tada we be jaming

Great thanks a bunch.

Not to bug but can you help me out with a related problem.

My drop menu thing i decided to go another route.

make a list of links (unless you have a better idea)
from a query

and if a user clicks on a link the associated value will be entered into a hidden field.

link say
<A HREF="$PHP_SELF?blabla = this>$variable name here from the querry</A>

id this possible?