|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
|
|
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
|
|
#1
|
|||
|
|||
|
open page with list/menu with a PHP script
function BuscaTipoJuego()
{ $sql = mysql_query("SELECT id, juego FROM tipojueg"); echo "<select name=\"juego\">"; while(list($id, $juego)=mysql_fetch_array($sql)) { $juego= stripslashes($juego); echo "<option value=\"$juego\""; echo ">$juego</option>"; } echo "</select>"; mysql_free_result($sql); } ?> onchange=document.location.href=this.[this.selectedIndex].value; How I going to put this code.. Give me example with my script.. I'm confused... I'm taking the value from a table, and I only use two records in the table(that's not matter, it must be more....) The only to records I use ares ID=1 Name=House ID=2 Name=Depto Only this two records with two fields : ID, and Name... Ok.. In showing it pefectly in the Site with this script, but I need when I select one option of the List/menu it open a Page, but the page is depending the option I selected.. This means, If I have to records, I will have two differents pages, One for HOUSES and other for DEPTOS.. the Name of the pages are: house.php deptos.php If I select House from list menu it open house.php If I select Depto from list menu it open deptos.php IN the Line code you give me, I can't understand How to specify the conditions within my script... Help me with this. Please... NVM |
|
#2
|
||||
|
||||
|
Try this. I'm just adding an onchange javascript event to the select box and telling the page to look at the selected value of the select box and jump to that page. This assumes that the page name will be the juego value plus ".php" and that the given file is in the current directory. Depending on your OS, this may be case-sensitive. Also, you can prepend a directory or full HTTP path to the filename if need be. I'm not sure the javascript will work as is, but this should get you moving in the right direction.
PHP Code:
|
|
#3
|
||||
|
||||
|
Also, please don't post multiple threads on the same topic. Doing so makes it hard to follow the thread, which makes it difficult to provide non-redundant help and makes it harder for others to find helpful information when they read the threads later. Let's keep any further replies to this topic in the original thread. Thanks.
|
|
#4
|
|||
|
|||
|
PHP:------------------------------------------------------------------------------
function BuscaTipoJuego(){ $sql = mysql_query("SELECT id, juego FROM tipojueg"); echo "<select name=\"juego\" onchange=\"document.location.href=this[selectedIndex].value + '.php'\">"; while(list($id,$juego)=mysql_fetch_array($sql)){ $juego= stripslashes($juego); echo "<option value=\"$juego\""; echo ">$juego</option>"; } echo "</select>"; mysql_free_result($sql); } ?> echo "<select name=\"juego\" onchange=\"document.location.href=this[selectedIndex].value + '.php'\">"; OK, but I can't understand how it's going to know which page to take.. If I select HOuse it open house.php page and If I select Depto it open deptos.php page where I specify it, or how it know, I can see the condition, or something else, or I'm wrong.. the example complete must be so..: in VALUE I change for what? house.php, WHERE i CHANGE FOR THE NAME OF THE FILE...(HOUSE.PHP) echo "<select name=\"juego\" onchange=\"document.location.href=this[selectedIndex].HOUSE + '.php'\">"; |
|
#5
|
||||
|
||||
|
The code I've provided should be all you need. Note that the onchange event runs the code "document.location.href=...", which is what actually sends the page to the location. The code I've provided does the following onchange:
1. Look at the selectbox. 2. Find which value is selected. 3. Use that value to generate a URL such that if the value is "House," the page URL will be "House.php" and if the value is "Dept," the page URL will be "Dept.php." 4. Redirect to that URL. Oh, I see now that you've replaced "value" in my code with "HOUSE." Don't do that. "Value" is a keyword that is automatically substituted in this case with the value of the selected option in the select box. Just try the code exactly as I gave it to you. Don't forget that capitalization may matter. For example, if your database value in "juego" is "House" and the page you wish to redirect to is "house.php" with no capital letters, you may get a 404 error. |
![]() |
| Viewing: Dev Articles Community Forums > Programming > PHP Development > open page with list/menu with a PHP script |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|