Jump to content

looking for a better idea ....array


Jay2391

Recommended Posts

I am looking for a better way to do this ...
$games_to_be_played  is the amount of maximun games a player will play in a tournament
so if the maximun games to be played is "x" number then I should get the same number of "x"
$scorX variable to imput scores...

or is this even correct....


$games_to_be_played  = 3;

$query = "SELECT * FROM $table ";
$result = mysql_query($query2, $tc); 
  while($row = mysql_fetch_array($result)){

  if($t_name == $row['t_name'] and $game == $row['game']){
        $result_id = $row['result_id'];
        $player = $row['user_name'];
        $win = $row['win'];
        $loss = $row['loss'];;
        $tie = $row['tie'];;
        $rank = $row['rank'];;
        $scor1 = $row['scor1'];
        $scor2 = $row['scor2'];
        $scor3 = $row['scor3'];
        $scor4 = $row['scor4'];
        $scor5 = $row['scor5'];

   
      print "<p><h4$playerbr></h4></p>";
   
      if ($games_to_be_played == 3){
              print '<h4><form action = "samepage.php" method="post"><p>';
              print Score Round 1: <input type="text" name="scor1" size"50" value="' . $_POST['scor1'] . '"/><br />'
              print '<br><input type="submit" name="submit" size"20" value="Enter Score"/><br /></h4>';

              print '<h4><form action = "samepage.php" method="post"><p>';
              print Score Round 2: <input type="text" name="scor2" size"50" value="' . $_POST['scor2'] . '"/><br />'
              print '<br><input type="submit" name="submit" size"20" value="Enter Score"/><br /></h4>';

              print '<h4><form action = "samepage.php" method="post"><p>';
              print Score Round 3: <input type="text" name="scor3" size"50" value="' . $_POST['scor3'] . '"/><br />' print '<br><input type="submit" name="submit" size"20" value="Enter Score"/><br /></h4>';      
      }

      if ($games_to_be_played == 4){
             
              print '<h4><form action = "samepage.php" method="post"><p>';
              print Score Round 1: <input type="text" name="scor1" size"50" value="' . $_POST['scor1'] . '"/><br />'
              print '<br><input type="submit" name="submit" size"20" value="Enter Score"/><br /></h4>';

              print '<h4><form action = "samepage.php" method="post"><p>';
              print Score Round 2: <input type="text" name="scor2" size"50" value="' . $_POST['scor2'] . '"/><br />'
              print '<br><input type="submit" name="submit" size"20" value="Enter Score"/><br /></h4>';

              print '<h4><form action = "samepage.php" method="post"><p>';
              print Score Round 3: <input type="text" name="scor3" size"50" value="' . $_POST['scor3'] . '"/><br />' print '<br><input type="submit" name="submit" size"20" value="Enter Score"/><br /></h4>';

              print '<h4><form action = "samepage.php" method="post"><p>';
              print Score Round 4: <input type="text" name="scor4" size"50" value="' . $_POST['scor4'] . '"/><br />'
              print '<br><input type="submit" name="submit" size"20" value="Enter Score"/><br /></h4>';

              print '<h4><form action = "samepage.php" method="post"><p>';
              print Score Round 5: <input type="text" name="scor5" size"50" value="' . $_POST['scor5'] . '"/><br />' print '<br><input type="submit" name="submit" size"20" value="Enter Score"/><br /></h4>';
      }
          print '<br><input type="submit" name="submit" size"20" value="Enter Score"/><br /></h4>';
Link to comment
Share on other sites

By the way this is the way the lines should look like I was type it in before so I am missing some '' marks and stuff


if ($games_to_be_played == 2){
    print '<p><h4><form action = "tourney_admin.php" method="post"></p>';
                              print '<p>Score Round 1: <input type="text" name="scor1" size"10" value="' . $_POST['scor1'] . '"/>';
                              print '<input type="submit" name="submit" size"20" value="Enter Score"/></h4></p>';

                              print '<p><h4><form action = "tourney_admin.php" method="post"></p>';
                              print '<p>Score Round 2: <input type="text" name="scor2" size"10" value="' . $_POST['scor2'] . '"/>';
                              print '<input type="submit" name="submit" size"20" value="Enter Score"/></h4></p>';

}
Link to comment
Share on other sites

My question is if there is a better WAY!!!! to create that code I did above....

mybe things that will help are ....

can I insert a variable in here ...red area

print '<p>Score Round 1: <input type="text" name="scor1" size"5" value="' . $_POST[[color=red]'scor1'[/color]] . '"/>';

the issue is that i can print the boxes but they are all id the same way so I need the input boxes to be unique assing to that player

player 1 has 2 input boxes
player 2 has 2 input boxes
player 3 has 2 input boxes
player 4 has 2 input boxes

[color=red][font=Verdana]but the boxes are name "scor1 and scor2" in all the lines so when you update scor1 it will update "scor1" in the database for all of the one call "scor1"[/font][/color]
so I am trying to figure out a better WAY ....


Sorry about the CODE # THING


Link to comment
Share on other sites

i think this is what you want to do:
[code]
<?php
$games_to_be_played  = 3;

$query = "SELECT * FROM your_table";
$result = mysql_query($query, $tc);                             

$i = 1;
while($row = mysql_fetch_array($result)){
if($t_name == $row['t_name'] && $game == $row['game']){
        echo "<p><h4>". $row['user_name'] ."<br></h4></p>\n";             

if($games_to_be_played == 3){
print "<h4><form action=\"". $_SERVER['php_self'] ."\" method=\"post\"><p>\n";
print "Score Round ". $i .": <input type=\"text\" name=\"scor". $i ."\" size\"50\" value=\"". $_POST[scor$i] ."">\n";
print "<input type="submit" name="submit" size"20" value="Enter Score">\n";
print "</form></h4>\n";
}
}
?>
[/code]
Link to comment
Share on other sites

the code is missing something I tough it was a '  \  ' in this area...

value=\"". $_POST[scor$i] ."\">\n";

but i get a

Parse error: parse error, unexpected T_VARIABLE, expecting ']' in C:\XAMPP\xampp\htdocs\MDO\tourney_admin.php on line 235
[code]
if($games_to_be_played == 3){
print "<h4><form action=\"". $_SERVER['php_self'] ."\" method=\"post\"><p>\n";
print "Score Round ". $i .": <input type=\"text\" name=\"scor". $i ."\" size\"50\" value=\"". $_POST[scor$i] ."\">\n";
print "<input type="submit" name="submit" size"20" value="Enter Score">n";
print "</form></h4>n";
}[/code]
Link to comment
Share on other sites

sorry, try this instead:
[code]
<?php
$games_to_be_played  = 3;

$query = "SELECT * FROM your_table";
$result = mysql_query($query, $tc);                             

$i = 1;
while($row = mysql_fetch_array($result)){
if($t_name == $row['t_name'] && $game == $row['game']){
        echo "<p><h4>". $row['user_name'] ."<br></h4></p>\n";             

if($games_to_be_played == 3){
print "<h4><form action=\"". $_SERVER['php_self'] ."\" method=\"post\"><p>\n";
print "Score Round ". $i .": <input type=\"text\" name=\"scor". $i ."\" size=\"50\" value=\"". $_POST[scor$i] ."\">\n";
print "<input type=\"submit\" name=\"submit\" size=\"20\" value=\"Enter Score\">\n";
print "</form></h4>\n";
}
}
$i++;
}
?>
[/code]
Link to comment
Share on other sites

Parse error: parse error, unexpected T_VARIABLE, expecting ']' in C:\XAMPP\xampp\htdocs\MDO\test.php on line 235

[code]
<?php
$games_to_be_played  = 3;

$query = "SELECT * FROM your_table";
$result = mysql_query($query, $tc);                             

$i = 1;
while($row = mysql_fetch_array($result)){
if($t_name == $row['t_name'] && $game == $row['game']){
        echo "<p><h4>". $row['user_name'] ."<br></h4></p>\n";             

if($games_to_be_played == 3){
print "<h4><form action=\"". $_SERVER['php_self'] ."\" method=\"post\"><p>\n";
[color=red]for me is this line----->[/color]
print "Score Round ". $i .": <input type=\"text\" name=\"scor". $i ."\" size=\"50\" value=\"". $_POST[scor$i] ."\">\n";

print "<input type=\"submit\" name=\"submit\" size=\"20\" value=\"Enter Score\">\n";
print "</form></h4>\n";
}
}
$i++;
}
?>

[/code]
Link to comment
Share on other sites

Well that didn't work so i decided to change I am trying to get drop down menus....

but I am having similar issues here is my drop down menu code but it dosen't select the item...


the munu box shows up and i can select and click but it dosen't store the values... ??? ??? ???

[code]  
$query_list = "SELECT * FROM $tabler WHERE (tourney_name=\"$tourney_name\")";
$result_list = mysql_query($query_list, $tc);
 
 
print '<h4><form action = "tourney_admin.php" method="post"><p>':
print '<p><label>Player: <select name="player_list">
         
<option value="">- - -Chose an player - -</option>';  
                                       
while($row_list = mysql_fetch_array($result_list)){
$player_list = $row_list['user_name'];
               
print "<option value=\"$player_list\">$player_list<br></option>";
       
}
 
print "</select></p>\n";       
 
print '<p><input type="submit" name="change" value="Submit Change" /></label></p>                      </form>';
  [/code]
Link to comment
Share on other sites

the selected value will be stored in a variable called[code]$_POST['player_list'][/code]

so, somewhere at the top of tourney_admin.php, write[code]echo $_POST['player_list'] ."<br />\n";[/code]
and it will print the value of the selected option in the dropdown menu.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.