SunQuest
 
           PHP Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsProgrammingPHP Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
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  
Old September 26th, 2003, 07:51 AM
nestorvaldez nestorvaldez is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 40 nestorvaldez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 21 sec
Reputation Power: 6
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

Reply With Quote
  #2  
Old September 26th, 2003, 08:11 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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:
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)){
        
$juegostripslashes($juego);
        echo 
"<option value=\"$juego\"";
        echo 
">$juego</option>";
    }
    echo 
"</select>";
    
mysql_free_result($sql);
}
?> 

Reply With Quote
  #3  
Old September 26th, 2003, 08:14 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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.

Reply With Quote
  #4  
Old September 26th, 2003, 11:40 AM
nestorvaldez nestorvaldez is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Posts: 40 nestorvaldez User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 21 sec
Reputation Power: 6
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'\">";

Reply With Quote
  #5  
Old September 26th, 2003, 11:58 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to dhouston
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.

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingPHP Development > open page with list/menu with a PHP script


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway