SitePoint Sponsor |
|
User Tag List
Results 26 to 50 of 52
Thread: Need Help
-
Aug 12, 2005, 08:57 #26
- Join Date
- May 2005
- Location
- S.W. France
- Posts
- 2,496
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
OK this works for me.
I've commented out all your database bits and added hardcoding for the dropboxes. Also put your functions on the same script for easy of debug.
PHP 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="Select game">Select Game</option>';
echo '<option value="test1">test1</option>';
echo '<option value="test2">test2</option>';
echo '<option value="test3">test3</option>';
echo '<option value="test4">test4</option>';
echo "</select>";
}
function ListMenuForm ()
{
// $query = mysql_query( "SELECT map FROM maps WHERE game_id = '$game'");
echo "<select name=\"boards\" size=\"1\" >";
echo "<option value=\"null\">null</option>";
// while ( $array = mysql_fetch_array( $query ) )
// {
// $row1 = mysql_fetch_row($result);
// echo " <option value={$game}>{$row1[1]}</option>";
// }
echo "</select>";
}
###Matches Input Script###
//require_once ('database.php');
//require_once ('func2.inc.php');
echo "<form name=formname method=post>";
dropdownform();
echo "<br>";
ListMenuForm ();
echo "<input type=submit name=next value=\"Next Step\">";
echo "</form>";
include ('test1.js');
?>
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("Choose Game","Choose Game") game[1][0]=new Option("optiontext1","optionvalue") game[1][1]=new Option("optiontext1","optionvalue") game[1][2]=new Option("optiontext1","optionvalue") game[1][3]=new Option("optiontext1","optionvalue") game[2][0]=new Option("optiontext2","optionvalue") game[2][1]=new Option("optiontext2","optionvalue") game[2][2]=new Option("optiontext2","optionvalue") game[2][3]=new Option("optiontext2","optionvalue") game[3][0]=new Option("optiontext3","optionvalue") game[3][1]=new Option("optiontext3","optionvalue") game[3][2]=new Option("optiontext3","optionvalue") game[3][3]=new Option("optiontext3","optionvalue") game[4][0]=new Option("optiontext4","optionvalue") game[4][1]=new Option("optiontext4","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>
A Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
-
Aug 12, 2005, 09:00 #27
- Join Date
- May 2005
- Location
- S.W. France
- Posts
- 2,496
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Mittineague
Have posted working code.A Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
-
Aug 12, 2005, 09:07 #28
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Nevermind previous post...
Ok the script is working...So now...how do we go about getting the information from the Database? Don't we have to edit the Javascript to do that?
And another thing..I need the maps to be displayed into a list menu so that mutliple maps can be selected.
-
Aug 12, 2005, 09:41 #29
- Join Date
- May 2005
- Location
- S.W. France
- Posts
- 2,496
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
[QUOTE=Mav3n]Ok the script is working...So now...how do we go about getting the information from the Database? Don't we have to edit the Javascript to do that?[\quote]
Good, yes now we have to end the javascript, or to be more precise we need to insert PHP into the middle of the javascript. To do this we have to save the javascript into PHP variables, save the PHP result from the database into a PHP variable and sandwich them together.
Put your javascript into a .PHP file and change for the following:
PHP Code:$java1 = '<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()'. "\n";
Put PHP code here to make array, save array as $array
$java2 = '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>';
echo $java1 . $array . $java2;
Now write some PHP to go in the middle that will make a third variable called $array. This code must produce the same rows as was originally in the javascript but with your database values. I can't do this for you now as I'm about to go out but after your sql query use something like
PHP Code:while ($row = mysql_fetch_array($sql)){
$array = $array . 'game' . '[' . $row['Game_No'] . '][' . $row['Board_No_For_Game'] . ']=new Option("' . $row['Board_Description'] . '","' . $row['Board_Value'] . '")' . "\n";
}
And another thing..I need the maps to be displayed into a list menu so that mutliple maps can be selected.
Good luck, I'll check back tomorrow.
TerryA Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
-
Aug 12, 2005, 09:57 #30
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Here is what I got
Code:<?php require_once('database.php'); $java1 = '<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()'; function dropdownform () { $query = mysql_query( "SELECT * FROM `games` ORDER BY `gameid` ASC"); echo "<select name=\"games\" onChange=\"getboards(this.options.selectedIndex)\">"; echo '<option value="Select game">Select Game</option>'; while ( $array = mysql_fetch_array( $query ) ){ echo "<option value={$array['gameid']}>{$array['game_name']}</option>"; } echo "</select>"; } function ListMenuForm () { $query = mysql_query( "SELECT id,map,game_id FROM maps WHERE game_id = '$game'"); echo "<select name=\"boards\" size=\"5\" multiple>"; echo '<option value="Select game">--Select Maps--</option>'; while ( $array = mysql_fetch_row( $query ) ){ echo "<option value={$array['game_id']}>{$array['map']}</option>"; } echo "</select>"; } $java2 = '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>'; echo $java1 . $array . $java2; ?>
http://67.176.26.57/webpage/matches.php
That's what I am getting
-
Aug 12, 2005, 10:00 #31
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
database MAPS is set up with three tables...Id ( primary auto_increment ) map,game_id...game_id gets it's variable from the ID in the database games when the game is inputed with this script
http://67.176.26.57/webpage/maps.php
-
Aug 12, 2005, 16:58 #32
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I have found out the problem...in the games dropdown box I have the gameid in the value of the option. That value is the game_id for the maps. here is my database structure
games
gameid ( auto_increment )
game_name
--maps--
id
map_name
game_id ( is generated using mysql_insert_id() on a previous script so therefore game_id will have the same number as 'id' in db games for that post.)
What's happening is the gameid from the games database isn't going anywhere...so therefore there is no way for the map list to filter out ONLY the maps that equal the posted game_id. Not unless there is something I am missing.
So somehow I need to pass the $array['gameid'] from dropdown 'games' to dropdown 'boards' I have blocked out the areas that need attention
PHP Code:function dropdownform ()
{
$query = mysql_query( "SELECT * FROM `games` ORDER BY `gameid` ASC");
//echo "<select name=\"games\" //onChange=\"getboards(this.options.selectedIndex)\">";
//echo '<option value="Select game">Select Game</option>';
while ( $array = mysql_fetch_array( $query ) ){
//echo "<option value={$array['gameid']}>{$array['game_name']}</option>";
}
echo "</select>";
}
function ListMenuForm ()
{
//$query = mysql_query( "SELECT id,map,game_id FROM maps WHERE //game_id = '$games'"); //Notice $games is the value of the games dropdown box.
echo "<select name=\"boards\" size=\"5\" multiple>";
echo '<option value="Select game">--Select Maps--</option>';
while ( $array = mysql_fetch_row( $query ) ){
echo "<option value={$array['game_id']}>{$array[1]}</option>";
}
echo "</select>";
}
-
Aug 12, 2005, 18:29 #33
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
BIggity BUMP^^^ lol
-
Aug 13, 2005, 00:17 #34
- Join Date
- May 2005
- Location
- S.W. France
- Posts
- 2,496
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Mav3n
TerryA Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
-
Aug 13, 2005, 01:57 #35
- Join Date
- May 2005
- Location
- S.W. France
- Posts
- 2,496
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
OK Finished script below, assumes your tables look like this
TABLE games
FIELD gameid
FIELD game_name
TABLE maps
FIELD id
FIELD map
FIELD game_id
Just need to change my 'require database' code for yours.
Have fun
PHP Code:<?php
require 'dbconnect.inc.php'; //CHANGE TO YOUR DATABASE INCLUDE FILE *****************************************
//your function to make games dropbox
function dropdownform () {
echo '<select name="games" onChange="getboards(this.options.selectedIndex)">';
echo '<option value="Select game">Select A Game</option>'; // Give instruction
$query = mysql_query( "SELECT *
FROM games
ORDER BY game_name ASC
");
while ( $result = mysql_fetch_array( $query )) {
echo '<option value="' . $result['game_id'] . '">' . $result['game_name'] .'</option><br />';
}
echo "</select>";
}
// your function to make maps dropbox
function ListMenuForm () {
echo '<select name="boards" size="5" multiple >';
echo '<option value="null">Select Game First</option>';
echo '</select>';
}
//START MAIN PHP SCRIPT//
//Build Form
echo '<table bgcolor="#ff9900" align="center" valign="top" width=400 border=0><tr><td width=200>';
echo '<form name="formname" method="post">';
dropdownform();
echo '<td>';
ListMenuForm ();
echo '<tr><td colspan=2 align="right"><input type="submit" name=next value="Next Step">';
echo '</form>';
echo '</table>';
//END MAIN PHP SCRIPT//
// START JAVASCRIPT
//Make first half of javascript put in $java1
$java1 = '<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()' . "\n";
//Make array of choices in $array
$array = 'game[0][0]=new Option("Choose Game","Choose Game")' . "\n";
$query = mysql_query( "SELECT game_id
FROM maps
GROUP BY game_id ASC
");
$noofgames = mysql_num_rows($query); //find number of games available
while ( $result = mysql_fetch_array( $query )) {
//subsearch to find details of each map for gameno
$query2 = mysql_query( "SELECT *
FROM maps
WHERE game_id = '$noofgames'
");
$numofmap = mysql_num_rows($query2); //find number of maps available for game
while ( $result2 = mysql_fetch_array( $query2 )) {
$array = $array . 'game' . '[' . $noofgames . '][' . ($numofmap - 1) . ']=new Option("' . $result2['map'] . '","' . $result2['game_id'] . '")' . "\n";
$numofmap = $numofmap - 1; //decrease map no by one and loop
} //end subsearch while
$noofgames = $noofgames - 1; //decrease game no by one and loop
}//end while
//End make array
//Make second half of javascript put in $java2
$java2 = '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>';
//Write javascript to html
echo $java1 . $array . $java2;
//END JAVASCRIPT//
?>A Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
-
Aug 13, 2005, 03:19 #36
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hmm..That's still not really gettin the job done...I am not sure what the deal is with it...I don't think that the id is passing...
<option value="' . $result['game_id'] . '"> is just not going to the query.
In order for the MAPS to be displayed correctly..The game_id inside of the maps database has to match the gameid of the game selected.
http://67.176.26.57/webpage/matches.php
-
Aug 13, 2005, 04:23 #37
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Well actually I stand corrected...The values are inDEED being sent to the HTML print out..But the menu isn't being updated when the dropdown box is selected.
-
Aug 13, 2005, 04:54 #38
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
OK...well the script now works...At least it works ALMOST...When the game is picked...Say ID #1 it displays the maps from ID#2.
-
Aug 13, 2005, 05:02 #39
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Nevermind..changed the query! Thanks...Works GREAT! Now for my next trick...add more form fields to it...and somehow split the information up and submit it into two databases...Thanks guys!
Mandes your the MAN!! This was a great learning experience for me..And I shall keep this script all the time!!! Thanks...I will be sure to place that you helped with this script ( pretty much wrote it ), in the admin panel...Do you have a webpage that you would like for me to place on there?
-
Aug 13, 2005, 06:46 #40
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Hey Mandes...or anyone for that matter....I was able to get all the information into the DATABASE just fine after they submit...THe only thing I am lacking is the MAPS being inserted into the correct database...If the user selects multiple maps then how will I be able to insert that? I need to insert it as an array. I know I need a FOR loop in there to insert all the maps selected...But I don't know where or how
-
Aug 13, 2005, 08:12 #41
- Join Date
- May 2005
- Location
- S.W. France
- Posts
- 2,496
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
I assume your updating the maps table we used earlier ? You dont want to post arrays into the database you need to extract the map info and give them ech an entry.
I was going through this with someone the other day look in this forum under Problem sending data from page1 to page2.
See if that helps
Terry
Still not sure why you had to change the last script I posted, that worked fine here straight from the page, still as long as youre sorted, no more clunky, clunky in your websites..A Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
-
Aug 13, 2005, 08:25 #42
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
lol Thanks...well actually no I am not posting to the SAME database...I want the maps that are in the list menu to be posted to a database called match_maps...
--Table--
match_maps
--Fields--
id
map_name
match_id
This is so that all the maps that are posted will go into their OWN entry but they will all share the SAME match_id for each post...I think that will make it easier...I don't know how to put multiple selections into one field yet.
-
Aug 13, 2005, 08:50 #43
- Join Date
- May 2005
- Location
- S.W. France
- Posts
- 2,496
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
--Table--
match_maps
--Fields--
id
map_name
match_idA Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
-
Aug 13, 2005, 09:04 #44
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Since the games dropdown box is outputs the games' id...the id will come from $games.
-
Aug 13, 2005, 12:55 #45
- Join Date
- May 2005
- Location
- S.W. France
- Posts
- 2,496
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
No sorry I don't understand, I was going to suggest that you just make a lookup table to ref match_id and map_id, that way you'd only keep one copy of maps to worry about keeping updated and current, but I'm not sure of what you want to achive when the user enters data. I'm a programmer, not a gamer, as you're probably realising.
A Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
-
Aug 13, 2005, 17:06 #46
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
actually...on second thought...match_id needs to be mysql_last_id()...That way it matches the ID of the the last field that was entered when I post...Here is the way I want it to work.
Table-matches
fields
id
date
opponent
game_type
game_played ( name from dropdown )
maps_played
comments
score
result
Table-match_maps
id
map_name
match_id ( this will use mysql_last_id() to place a value in there...It will populate to match the last entry...That way when I do a search I can match the MAPS with the matches id #. This is in case there are multiple maps selected. )
And then I will be displaying the results of that database on a webpage.
-
Aug 14, 2005, 04:33 #47
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
All I need to know...is what functions should I put in a for loop for my INSERT query//
PHP Code:foreach ($whathere as $value){
$sql = "INSERT INTO match_maps (id,map_name,match_id) VALUES('NULL', '$value','LAST_INSERT_ID()')";
$query = mysql_query($sql);
-
Aug 14, 2005, 06:25 #48
- Join Date
- May 2005
- Location
- S.W. France
- Posts
- 2,496
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
You need to change the function that makes the dropbox to
PHP Code:// your function to make maps dropbox
function ListMenuForm () {
echo '<select name="boards[]" size="5" multiple >';
echo '<option value="null">Select Game First</option>';
echo '</select>';
}
PHP Code:foreach ($boards as $value){
$sql = "INSERT INTO match_maps (id,map_name,match_id) VALUES('NULL', '$value','LAST_INSERT_ID()')";
$query = mysql_query($sql);
}
Edit:
Also: your LAST_INSERT_ID, you should really save this to a variable, IMMEDIATELY after you write the information in the table, the further away from that point this command is put the more opportunity for another table insert to happen, and you'd then get the wrong ref returned.Edit:
A Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
-
Aug 14, 2005, 06:28 #49
- Join Date
- Jun 2005
- Posts
- 294
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yah thanks Mandes...I also had to change the java2 variable..
PHP Code:$java2 = 'var temp=document.formname.elements[\'boards[]\']
-
Aug 14, 2005, 06:41 #50
- Join Date
- May 2005
- Location
- S.W. France
- Posts
- 2,496
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by Mav3n
A Little Knowledge Is A Very Dangerous Thing.......
That Makes Me A Lethal Weapon !!!!!!!!
Contract PHP Programming
Bookmarks