SitePoint Sponsor |
|
User Tag List
Results 1 to 25 of 52
Thread: Need Help
-
Aug 12, 2005, 04:51 #1
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Need Help
I have this form where the dropdown list contains names of Video Games...The list menu will contain the MAPS or BOARDS that are associated with that game. So when the user selects say...Counter-Strike the list menu is populated with all the possible MAPS that are associated with the game...The user can select all the maps he wants and then click SUBMIT...at that time...the Game name all the maps...and other stuff entered from the form...get posted on a db... I am creating a RECENT MATCHES for clan site.
I am thinking I need a javascript..But I don't know how to implement the js with the php.
-
Aug 12, 2005, 07:00 #2
- Join Date
- Feb 2005
- Location
- Chester, Cheshire
- Posts
- 565
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
yeah i think JS would be the way to go with something like this... or .NET (boo!) you need to automatically postback the form right?
-
Aug 12, 2005, 07:03 #3
- Join Date
- Jul 2005
- Location
- West Springfield, Massachusetts
- Posts
- 17,290
- Mentioned
- 198 Post(s)
- Tagged
- 3 Thread(s)
PHP with Javascript
To use PHP variables in javascript do something like this
PHP Code:<script .......
var jsVar = <?php echo $phpVar; ?>;
.....Big Change Coming Soon - if you want your PMs save them now!
What you need to do to prepare for our migration to Discourse
A New SitePoint Forum Experience: Our Move to Discourse
-
Aug 12, 2005, 07:07 #4
- Join Date
- May 2005
- Location
- S.W. France
- Posts
- 2,496
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Yes thats a javascript job.
You'll need to make an array for each item in your first dropbox, with an element for each option you want in the second dropbox when selected.
Name your form and both dropboxes and the javascript can then update the second dropbox contents from the array when an item has been chosen from the first dropbox.
Example
Code:<script language="JavaScript"> <!-- var games=document.formname.games.options.length var game=new Array(games) for (i=0; i<games; i++) game[i]=new Array() game[0][0]=new Option("optiontext","optionvalue") game[0][1]=new Option("optiontext","optionvalue") game[0][2]=new Option("optiontext","optionvalue") game[1][0]=new Option("optiontext","optionvalue") game[1][1]=new Option("optiontext","optionvalue") game[1][2]=new Option("optiontext","optionvalue") game[1][3]=new Option("optiontext","optionvalue") game[2][0]=new Option("optiontext","optionvalue") game[2][1]=new Option("optiontext","optionvalue") game[2][2]=new Option("optiontext","optionvalue") game[2][3]=new Option("optiontext","optionvalue") game[3][0]=new Option("optiontext","optionvalue") game[3][1]=new Option("optiontext","optionvalue") game[3][2]=new Option("optiontext","optionvalue") game[3][3]=new Option("optiontext","optionvalue") game[4][0]=new Option("optiontext","optionvalue") game[4][1]=new Option("optiontext","optionvalue") var temp=document.formname.boards function getboards(x){ for (m=temp.options.length-1;m>0;m--) temp.options[m]=null for (i=0;i<game[x].length;i++){ temp.options[i]=new Option(game[x][i].text,game[x][i].value) } temp.options[0].selected=true } //--> </script>
the first dropbox will be named 'games'
the second dropbox will be named 'boards'
change optiontext and optionvalue to suit your data
The handler
Code:onChange="getboards(this.options.selectedIndex)"
Hope it helps
Terry
Edit:
Forgot to say, once you get it working you can script a douple loop in PHP to build your array from the contents of the database.A Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
-
Aug 12, 2005, 07:13 #5
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ACtually...I appreciate your help guys...But I have decided to NOT use a javascript approach..Instead I am keeping it with JUST php...Here is how I am doing it..
First I am using a paging method to better fit my needs..
my main code
Code:<?php ###Matches Input Script### require_once ('database.php'); require_once ('func2.inc.php'); if (!$_REQUEST['m'] == "1" || !$_REQUEST['m'] == "2" || !$_REQUEST['m'] == "3"){ echo "<form name=match_game method=post action=?m=2>"; dropdownform(); echo "<input type=submit name=next value=\"Next Step\">"; echo "</form>"; } #########################Start of M-2############################### if ($_REQUEST['m'] == "2") { $result = mysql_query("SELECT gameid,game_name FROM games WHERE gameid = '$game'"); if (!$result) { echo 'Could not run query: ' . mysql_error(); exit; } $row = mysql_fetch_row($result); echo "Maps Available for <strong>" . $row[1]; echo"</strong>"; echo "<form name=match_maps method=post action=?m=3>"; echo "<input type=text value=\"$row[1]\"><br>"; ListMenuForm (); echo "<input type=submit name=next value=\"Next Step\">"; echo "</form>"; } ?>
Code:<?php function dropdownform () { $query = mysql_query( "SELECT * FROM `games` ORDER BY `gameid` ASC"); echo "<select name=\"game\">"; while ( $array = mysql_fetch_array( $query ) ) { echo " <option value={$array['gameid']}>{$array['game_name']}</option>"; } echo "</select>"; } function ListMenuForm () { $query = mysql_query( "SELECT map FROM maps WHERE game_id = '$game'"); echo "<select name=\"map\" size=\"5\" multiple>"; while ( $array = mysql_fetch_array( $query ) ) { $row1 = mysql_fetch_row($result); echo " <option>{$row1[1]}</option>"; } echo "</select>"; } ?>
-
Aug 12, 2005, 07:19 #6
- Join Date
- May 2005
- Location
- S.W. France
- Posts
- 2,496
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Thats cluncky, and cheating !!!!
A Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
-
Aug 12, 2005, 07:24 #7
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
What do you mean clunky? lol
-
Aug 12, 2005, 07:28 #8
- Join Date
- May 2005
- Location
- S.W. France
- Posts
- 2,496
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Refreshing screen when no need to, breaks the flow of the user, hence clunky !
The difference between a round wheel and a triangular one.A Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
-
Aug 12, 2005, 07:29 #9
- Join Date
- May 2003
- Location
- UK
- Posts
- 50
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
some nice xml http requests would be sweet for that job, but whatever works
-
Aug 12, 2005, 07:31 #10
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
It's just the javascript approach scares me...I don't know javascript therefore I am not able to do it...I am better off doing this and figuring this out then trying to worry about javascript lol.
The thing is...is that it doesn't work correctly...I am having a hard time displaying the MAPS in the list menu. I think it has to do something with the query or something along those lines.
-
Aug 12, 2005, 07:33 #11
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Mandes I was reading your javascript...If I place my dropdown function in that wouldn't it work?
-
Aug 12, 2005, 07:46 #12
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ugh! Screw it...I will just do something else! LMFAO! Problem fixed.
-
Aug 12, 2005, 07:48 #13
- Join Date
- May 2005
- Location
- S.W. France
- Posts
- 2,496
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Your dropdown function gives you the games dropbox.
(By the way, why are you escaping all the " in the select code. This is code, only need to escape characters that are going to be saved or passed to other forms)
You will need to add a name="games" and the onchange handler I gave above to the select statement. Then just create the second dropbox with name="boards"
As I said above make sure that the form has a name="formname" statement too.A Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
-
Aug 12, 2005, 07:54 #14
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I do that because there are SPACES in the names of the games..IE: Rainbow Six 3. If you don't make it \"\" then it only displays the FIRST part of the name.
-
Aug 12, 2005, 07:56 #15
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
ok so my php script has
Code:<?php ###Matches Input Script### require_once ('database.php'); require_once ('func2.inc.php'); include ('test1.js'); echo "<form name=formname method=post>"; dropdownform(); echo "<select name=\"boards\" id=\"boards\">"; echo "<input type=submit name=next value=\"Next Step\">"; echo "</form>"; ?>
Code:function dropdownform () { $query = mysql_query( "SELECT * FROM `games` ORDER BY `gameid` ASC"); echo "<select name=\"games\" onChange=\"getboards(this.options.selectedIndex)\">"; while ( $array = mysql_fetch_array( $query ) ) { echo " <option value={$array['gameid']}>{$array['game_name']}</option>"; } echo "</select>"; }
-
Aug 12, 2005, 07:59 #16
- Join Date
- May 2005
- Location
- S.W. France
- Posts
- 2,496
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
I don't see that !!
You've put the slashes in the "name=....." part not the data part, how can that make a difference ??
Nearly all my dropboxes have spaces in the description text, never had to compensate for it.A Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
-
Aug 12, 2005, 08:03 #17
- Join Date
- May 2005
- Location
- S.W. France
- Posts
- 2,496
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
All looks OK, (except for the slashes)
A Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
-
Aug 12, 2005, 08:03 #18
- Join Date
- May 2003
- Location
- UK
- Posts
- 50
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
As far as i can see the slashes are in the right place, what do you mean, Mandes?
Mav3n needs to escape the " in the attribute values in the echo command as he is encapsulating the entire string in " as well. If Mav3n was using single quotes around the string then there wouldn't be a need to, but that looks good to me.
-
Aug 12, 2005, 08:09 #19
- Join Date
- Jul 2005
- Location
- West Springfield, Massachusetts
- Posts
- 17,290
- Mentioned
- 198 Post(s)
- Tagged
- 3 Thread(s)
buggy bugs
What kind of error messages are you getting? What does the screen output look like? Can you echo $varValues to pinpoint the problem area?
Big Change Coming Soon - if you want your PMs save them now!
What you need to do to prepare for our migration to Discourse
A New SitePoint Forum Experience: Our Move to Discourse
-
Aug 12, 2005, 08:13 #20
- Join Date
- May 2005
- Location
- S.W. France
- Posts
- 2,496
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by ShEx
I didn't notice the double quotes around the whole statement, probably because I don't program like that myself. I stand corrected.A Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
-
Aug 12, 2005, 08:18 #21
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I am not getting any error messages...The GAMES dropdown box is populating just fine....But I think that's because I am still using the query in my func2.inc.php...
This will take me some time..But I think that it will be well worth it in the end.
Again...No error messages
Main Page
Code:<?php ###Matches Input Script### require_once ('database.php'); require_once ('func2.inc.php'); include ('test1.js'); echo "<form name=formname method=post>"; dropdownform(); echo "<br>"; ListMenuForm (); echo "<input type=submit name=next value=\"Next Step\">"; echo "</form>"; ?>
Code:<?php function dropdownform () { $query = mysql_query( "SELECT * FROM `games` ORDER BY `gameid` ASC"); echo "<select name=\"games\" onChange=\"getboards(this.options.selectedIndex)\">"; while ( $array = mysql_fetch_array( $query ) ) { echo " <option value={$array['gameid']}>{$array['game_name']}</option>"; } echo "</select>"; } function ListMenuForm () { $query = mysql_query( "SELECT map FROM maps WHERE game_id = '$game'"); echo "<select name=\"boards\" size=\"5\" multiple>"; while ( $array = mysql_fetch_array( $query ) ) { $row1 = mysql_fetch_row($result); echo " <option value={$game}>{$row1[1]}</option>"; } echo "</select>"; } ?>
Code:<script language="JavaScript"> <!-- var games=document.formname.games.options.length var game=new Array(games) for (i=0; i<games; i++) game[i]=new Array() game[0][0]=new Option("optiontext","optionvalue") game[0][1]=new Option("optiontext","optionvalue") game[0][2]=new Option("optiontext","optionvalue") game[1][0]=new Option("optiontext","optionvalue") game[1][1]=new Option("optiontext","optionvalue") game[1][2]=new Option("optiontext","optionvalue") game[1][3]=new Option("optiontext","optionvalue") game[2][0]=new Option("optiontext","optionvalue") game[2][1]=new Option("optiontext","optionvalue") game[2][2]=new Option("optiontext","optionvalue") game[2][3]=new Option("optiontext","optionvalue") game[3][0]=new Option("optiontext","optionvalue") game[3][1]=new Option("optiontext","optionvalue") game[3][2]=new Option("optiontext","optionvalue") game[3][3]=new Option("optiontext","optionvalue") game[4][0]=new Option("optiontext","optionvalue") game[4][1]=new Option("optiontext","optionvalue") var temp=document.formname.boards function getboards(x){ for (m=temp.options.length-1;m>0;m--) temp.options[m]=null for (i=0;i<game[x].length;i++){ temp.options[i]=new Option(game[x][i].text,game[x][i].value) } temp.options[0].selected=true } //--> </script>
-
Aug 12, 2005, 08:21 #22
- Join Date
- May 2005
- Location
- S.W. France
- Posts
- 2,496
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
OK, look at the source code produced in your browser (right mouse, view source). The javascript should look just like your js code above ?
A Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
-
Aug 12, 2005, 08:28 #23
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
View-> page source printed...
Code:<script language="JavaScript"> <!-- var games=document.formname.games.options.length var game=new Array(games) for (i=0; i<games; i++) game[i]=new Array() game[0][0]=new Option("optiontext","optionvalue") game[0][1]=new Option("optiontext","optionvalue") game[0][2]=new Option("optiontext","optionvalue") game[1][0]=new Option("optiontext","optionvalue") game[1][1]=new Option("optiontext","optionvalue") game[1][2]=new Option("optiontext","optionvalue") game[1][3]=new Option("optiontext","optionvalue") game[2][0]=new Option("optiontext","optionvalue") game[2][1]=new Option("optiontext","optionvalue") game[2][2]=new Option("optiontext","optionvalue") game[2][3]=new Option("optiontext","optionvalue") game[3][0]=new Option("optiontext","optionvalue") game[3][1]=new Option("optiontext","optionvalue") game[3][2]=new Option("optiontext","optionvalue") game[3][3]=new Option("optiontext","optionvalue") game[4][0]=new Option("optiontext","optionvalue") game[4][1]=new Option("optiontext","optionvalue") var temp=document.formname.boards function getboards(x){ for (m=temp.options.length-1;m>0;m--) temp.options[m]=null for (i=0;i<game[x].length;i++){ temp.options[i]=new Option(game[x][i].text,game[x][i].value) } temp.options[0].selected=true } //--> </script> <form name="formname" method="post"><select name="games" onChange="getboards(this.options.selectedIndex)"> <option value=1>Rainbow Six 3</option> <option value=2>Ghost Recon: Summit Strike</option></select><br><select name="boards" size="5" multiple></select><br><input type=submit name=submit value="Submit"></form>
-
Aug 12, 2005, 08:28 #24
- Join Date
- Jul 2005
- Location
- West Springfield, Massachusetts
- Posts
- 17,290
- Mentioned
- 198 Post(s)
- Tagged
- 3 Thread(s)
bug bugging
The problem then is wth MAPS?
PHP Code:function ListMenuForm () {
$query = mysql_query( "SELECT map FROM maps WHERE game_id = '$game'");
echo "<select name=\"boards\" size=\"5\" multiple>";
while ( $array = mysql_fetch_array( $query ) )
{
$row1 = mysql_fetch_row($result);
echo " <option value={$game}>{$row1[1]}</option>";
}
echo "</select>";
}
the array "$row1[1]" is a non existant value
Maybe $row1[0] or $row1['map'] would work?Big Change Coming Soon - if you want your PMs save them now!
What you need to do to prepare for our migration to Discourse
A New SitePoint Forum Experience: Our Move to Discourse
-
Aug 12, 2005, 08:56 #25
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Code:function ListMenuForm () { $query = mysql_query( "SELECT game_id,map FROM maps WHERE game_id = '$game'"); $row = mysql_fetch_row($query); echo "<select name=\"boards\" size=\"5\" multiple>"; while ( $array = mysql_fetch_array( $query ) ) { echo " <option value={$game}>{$row[map]}</option>"; } echo "</select>"; }
Bookmarks