
chrisidas
Members-
Posts
53 -
Joined
-
Last visited
Never
Everything posted by chrisidas
-
I've tried both of the above and still no closer to figuring it out. Is it actually possible to get values, with the way that my <select> and <option> are created? I think the reason they are created like that is because i use JavaScript to show and hide them on the page.
-
Cheers guys, will give it a go
-
What do you mean? How would i go about changing it so i could get the values in my script?
-
Hey, I have a form which includes drop down boxes that show a list of options from my database. The problem i have is, i use a function to create my <options>, and they all have the same <select> name, so i have no idea how to fetch them in my form script. Here's my code to make the options, thanks to Nightslyr <?php function makeSelects($dbResult) { mysql_data_seek($dbResult, 0); while($row = mysql_fetch_assoc($dbResult)) { echo "<option value='{$row['playername']}'>{$row['playername']}</option>"; } } function homeScorers($dbResult) { echo '<select name="homeScorers[]" class="hidden-home" >'; makeSelects($dbResult); echo '</select>'; } function awayScorers($dbResult) { echo '<select name="awayScorers[]" class="hidden-away" >'; makeSelects($dbResult); echo '</select>'; } function homeYellowCards($dbResult) { echo '<select name="homeYellowCards[]" class="hidden-home" >'; makeSelects($dbResult); echo '</select>'; } function awayYellowcards($dbResult) { echo '<select name="awayYellowCards[]" class="hidden-away" >'; makeSelects($dbResult); echo '</select>'; } function homeRedCards($dbResult) { echo '<select name="homeRedCards[]" class="hidden-home" >'; makeSelects($dbResult); echo '</select>'; } function awayRedCards($dbResult) { echo '<select name="awayRedCards[]" class="hidden-away" >'; makeSelects($dbResult); echo '</select>'; } $homeQuery = "SELECT * FROM players WHERE teamname = '$hometeam'"; $homeResult = mysql_query($homeQuery); $awayQuery = "SELECT * FROM players WHERE teamname = '$awayteam'"; $awayResult = mysql_query($awayQuery); ?> and here's the code for the form <form action="result-script.php" method="post" name="myForm"> <table class="post-result" border="0" cellspacing="0" cellpadding="10"> <tr> <td class="post-result-home"><?php echo $hometeam ?> <input type="hidden" name="hometeam" value="<?php echo $hometeam ?>"> </td> <td class="post-result-away"><?php echo $awayteam ?> <input type="hidden" name="awayteam" value="<?php echo $awayteam ?>"> </td> </tr> <tr> <td class="post-result-home">Home Goals <select name="homescore" id="homescore"> <?php for($a = 0; $a < 11; ++$a) { echo "<option value='$a'>$a</option>"; } ?> </select> </td> <td class="post-result-away"> <select name="awayscore" id="awayscore"> <?php for($a = 0; $a < 11; ++$a) { echo "<option value='$a'>$a</option>"; } ?> </select> Away Goals</td> </tr> <tr> <td class="post-result-home"> <?php for($i = 0; $i < 10; ++$i) { homeScorers($homeResult); } ?></td> <td class="post-result-away"> <?php for($i = 0; $i < 10; ++$i) { awayScorers($awayResult); } ?> </td> </tr> <tr> <td class="post-result-home">Home Yellow Cards <select name="homeyellowcards" id="homeyellowcards"> <?php for($a = 0; $a < 11; ++$a) { echo "<option value='$a'>$a</option>"; } ?> </select></td> <td class="post-result-away"><select name="awayyellowcards" id="awayyellowcards"> <?php for($a = 0; $a < 11; ++$a) { echo "<option value='$a'>$a</option>"; } ?> </select> Away Yellow Cards</td> </tr> <tr> <td class="post-result-home"> <?php for($i = 0; $i < 10; ++$i) { homeYellowCards($homeResult); } ?></td> <td class="post-result-away"> <?php for($i = 0; $i < 10; ++$i) { awayYellowCards($awayResult); } ?> </td> </tr> <tr> <td class="post-result-home">Home Red Cards <select name="homeredcards" id="homeredcards"> <?php for($a = 0; $a < 11; ++$a) { echo "<option value='$a'>$a</option>"; } ?> </select></td> <td class="post-result-away"><select name="awayredcards" id="awayredcards"> <?php for($a = 0; $a < 11; ++$a) { echo "<option value='$a'>$a</option>"; } ?> </select> Away Red Cards</td> </tr> <tr> <td class="post-result-home"> <?php for($i = 0; $i < 10; ++$i) { homeRedCards($homeResult); } ?></td> <td class="post-result-away"> <?php for($i = 0; $i < 10; ++$i) { awayRedCards($awayResult); } ?> I've tried various ways of getting the result in my script but they all return errors. How would i make it so if two options are selected for say"homeScorers", i can set them as different variables in my form script. Cheers
-
<?php function makeSelects($dbResult) { while($row = mysql_fetch_assoc($dbResult)) { echo "<option value='{$row['playername']}'>{$row['playername']}</option>"; } } function homeScorers($dbResult) { echo '<select name="homeScorer[]" class="goalscorers" >'; makeSelects($dbResult); echo '</select>'; } function awayScorers($dbResult) { echo '<select name="awayScorer[]" class="goalscorers" >'; makeSelects($dbResult); echo '</select>'; } $homeQuery = "SELECT * FROM players WHERE teamname = '$hometeam'"; $homeResult = mysql_query($homeQuery); $awayQuery = "SELECT * FROM players WHERE teamname = '$awayteam'"; $awayResult = mysql_query($awayQuery); ?> <form action="result-script.php" method="post" id="myForm"> <table class="post-result" border="0" cellspacing="0" cellpadding="10"> <tr> <td class="post-result-home"><?php echo $hometeam ?> <input type="hidden" name="hometeam" value="<?php echo $hometeam ?>"> </td> <td class="post-result-away"><?php echo $awayteam ?> <input type="hidden" name="awayteam" value="<?php echo $awayteam ?>"> </td> </tr> <tr> <td class="post-result-home">Home Goals <select name="homescore" id="homescore"> <option value="0" selected="selected">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> </td> <td class="post-result-away"><select name="awayscore" id="awayscore"> <option value="0" selected="selected">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> <option value="6">6</option> <option value="7">7</option> <option value="8">8</option> <option value="9">9</option> <option value="10">10</option> </select> Away Goals</td> </tr> <tr> <td class="post-result-home"> <p>Goal Scorers</p> <?php for($i = 0; $i < 10; ++$i) { homeScorers($homeResult); } ?></td> <td class="post-result-away"> <p>Goal Scorers<p> <?php for($i = 0; $i < 10; ++$i) { awayScorers($awayResult); } ?></td> </tr> <tr> <td colspan="2" class="post-result-submit"><input type="submit" value="Submit" /></td> </tr> </table> </form> <script> var homeScore = document.getElementById('homescore'); var awayScore = document.getElementById('awayscore'); homeScore.onchange = function() { var homeScorers = document.forms["myForm"].elements["homeScorer[]"]; var homeLength = homeScorers.length; for(var i = 0; i < homeLength; ++i) { homeScorers[i].display = "none"; } var score = this.value; for(var j = 0; j < score; ++j) { homeScorers[j].display = "block"; } } awayScore.onchange = function() { var awayScorers = document.forms["myForm"].elements["awayScorer[]"]; var awayLength = awayScorers.length; for(var i = 0; i < awayLength; ++i) { awayScorers[i].display = "none"; } var score = this.value; for(var j = 0; j < score; ++j) { awayScorers[j].display = "block"; } } </script>
-
That works to add more yeah, and to hide them. The problem i know have is the 1st drop down box shows all the players, then the next 9 dont have anything in :-\ Also, i cant seem to get it to change the number it shows when i change the score in the form. I've tried tweaking little bits in the script but not sure what needs changing tbh.
-
Thats worked now yeah Now i have this <?php function makeSelects($dbResult) { while($row = mysql_fetch_assoc($dbResult)) { echo "<option value='{$row['playername']}'>{$row['playername']}</option>"; } } function homeScorers($dbResult) { echo '<select name="homeScorer[]" >'; makeSelects($dbResult); } function awayScorers($dbResult) { echo '<select name="awayScorer[]" >'; makeSelects($dbResult); } $homeQuery = "SELECT * FROM players WHERE teamname = '$hometeam'"; $homeResult = mysql_query($homeQuery); $awayQuery = "SELECT * FROM players WHERE teamname = '$awayteam'"; $awayResult = mysql_query($awayQuery); ?> Then to display my drop down boxes in my form i use <tr> <td class="post-result-home"> <?php echo homeScorers($homeResult); ?> </td> <td class="post-result-away"> <?php echo awayScorers($awayResult); ?> </td> </tr> It now shows 1 drop down box for the home scorers, and one drop down box for the away scorers. So now i need to make it so it shows say, 10 drop down boxers for both home and away, then hide them with CSS? I tried doing this, but not sure how to do it. I added more of these <?php echo homeScorers($homeResult); ?> but nothing happened. I also added more of these echo "<option value='{$row['playername']}'>{$row['playername']}</option>"; but that didnt change anything either. Stuck again
-
Ok, so i think i'm starting to get my head around this now i've read it through properly and taken my time. This is the code i now have before my HTML <?php function makeSelects($dbResult) { while($row = mysql_fetch_assoc($dbResult)) { // make select OPTIONS, not the select tag $homeplayername = $row['playername']; ?> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <?php } while($row = mysql_fetch_assoc($dbResult)) { $awayplayername = $row['playername']; ?> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <?php } } function homeScorers($dbResult) { echo '<select name="homeScorer[]" >'; makeSelects($dbResult); } function awayScorers($dbResult) { echo '<select name="awayScorer[]" >'; makeSelects($dbResult); } $homeQuery = "SELECT * FROM players WHERE teamname = '$hometeam'"; $homeResult = mysql_query($homeQuery); $awayQuery = "SELECT * FROM players WHERE teamname = '$awayteam'"; $awayResult = mysql_query($awayQuery); ?> Is this correct? One thing i still dont understand is $dbResult. Do i need to change this to $homeResult and $awayResult? If that isnt the case, how would i associate the select options with the select tags?
-
in function makeSelects($dbResult) should it look like this? <?php function makeSelects($dbResult) { while($row = mysql_fetch_assoc($dbResult) { homeScorers($homeResult); } } ?> and be placed where i want the drop down boxes to appear? Or would it look like this function makeSelects($dbResult) { while($row = mysql_fetch_assoc($dbResult) { ?> <option value="<?php echo $homeResult; ?>"><?php echo $homeResult; ?></option> <?php } } ?> Or am I way off again? Really am struggling to get my head around this lol
-
This is the code i have so far <script type="text/javascript"> <!-- var homescore = document.getElementById('homescore'); var awayscore = document.getElementById('awayscore'); homescore.onchange = function() { <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$hometeam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="homescorers" id="homescorers"> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <? }?> <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$hometeam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="homescorers" id="homescorers"> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <? }?> <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$hometeam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="homescorers" id="homescorers"> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <? }?> <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$hometeam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="homescorers" id="homescorers"> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <? }?> <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$hometeam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="homescorers" id="homescorers"> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <? }?> <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$hometeam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="homescorers" id="homescorers"> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <? }?> <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$hometeam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="homescorers" id="homescorers"> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <? }?> <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$hometeam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="homescorers" id="homescorers"> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <? }?> <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$hometeam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="homescorers" id="homescorers"> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <? }?> <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$hometeam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="homescorers" id="homescorers"> <option value="<?php echo $homeplayername; ?>"><?php echo $homeplayername; ?></option> <? }?> // unhide the number of child drop downs equal to this.value } awayscore.onchange = function() { // do the same thing here <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$awayteam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="awayscorers" id="awayscorers"> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <? } ?> <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$awayteam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="awayscorers" id="awayscorers"> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <? } ?> <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$awayteam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="awayscorers" id="awayscorers"> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <? } ?> <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$awayteam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="awayscorers" id="awayscorers"> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <? } ?> <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$awayteam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="awayscorers" id="awayscorers"> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <? } ?> <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$awayteam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="awayscorers" id="awayscorers"> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <? } ?> <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$awayteam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="awayscorers" id="awayscorers"> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <? } ?> <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$awayteam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="awayscorers" id="awayscorers"> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <? } ?> <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$awayteam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="awayscorers" id="awayscorers"> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <? } ?> <? $sql = mysql_query("SELECT * FROM players WHERE teamname='$awayteam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $homeplayername = $row['playername']; ?> <form method="post" action="result-script.php"> <select name="awayscorers" id="awayscorers"> <option value="<?php echo $awayplayername; ?>"><?php echo $awayplayername; ?></option> <? } ?> } //--> </script> Not sure if that's in anyway correct, but what would i have to add to it so that it shows the hidden options. Also, how would i call the code?
-
Hey, I've been trying to learn JavaScrip over the last few days, specifically for this one function. Still not sure how to do it though. I have a form on one of my pages to submit a result from a football match. The options in the form are 'homegoals' and 'awaygoals' I would like to use javascript so when the user clicks 'Add Goalscorers' it adds a drop down box for each goal, e.g. if 'homegoals' is 3 and 'awaygoals' is 2, it adds 3 select options for 'homegoalscorers' and 2 select options for 'awaygoalscorers'. I would also like to use the same script for yellow cards and red cards, but im sure i'll be able to work that out myself once i have a general idea of what to do Cheers
-
How would i do this? Is it even possible? (Form help)
chrisidas replied to chrisidas's topic in PHP Coding Help
Nice one mate, gonna have a look into that later -
How would i do this? Is it even possible? (Form help)
chrisidas replied to chrisidas's topic in PHP Coding Help
Will give the JavaScript option a go then. Never used it before though, would this be a pretty simple thing to do, or take quite a bit of studying? -
How would i do this? Is it even possible? (Form help)
chrisidas replied to chrisidas's topic in PHP Coding Help
Ah right. I wouldnt mind the page reloading if there was a way to do that? -
No worries
-
I think you need a SET after $tbl_name
-
I have a form on my website to submit results from a football match. The current options i have in my form are 'home goals' and 'away goals', which just have drop down menus so the user can select the number of goals scored. Is it possible to have another option underneath so that the user can click to add a goal scorer. For example. If the score is 2-0, the user cliks 'add goalscorer', then a drop down box appears with all the players in the team. When they have selected the goal scorer, they have an option to add another scorer. The code i use on another page which displays a drop down box of players in the team is <?php $sql = mysql_query("SELECT * FROM players WHERE teamname='$userTeam'"); echo '<select name="playername" id="playername">'; while($row = mysql_fetch_array($sql)){ $playername = $row['playername']; ?> I dont want to have like 10 boxes on each side, i only want them to appear when the user asks them to. Is it possible to do this in PHP or would i need to use JavaScript?
-
I posted on the phpBB forum but got no replies, and you lot here are much more helpful anyway I want it so my users login information is the same for both my forum and mainsite. I plan to use the forum registration for the user to create their account. I was wondering, what file or files do i need to edit in order for the registration form for the forum to insert rows into the "phpbb_users" table as well as the users table i have for my mainsite. All my tables are in the same database so no problems there. I just find it really confusing and cant seem to find what i'm looking for. Also, how would i make it so when the user submits the registration form it redirects to my mainsite home page instead. Cheers
-
How to make form box not show when logged in
chrisidas replied to chrisidas's topic in PHP Coding Help
Awesome, that works thanks! Cheers for the reply as well Kustom_Vegas. I did manually edit it yeah to change it to <?php from <?