Dyanamic Casillas y matrices asociativas

  • JakeBurgh
  • Newbie
  • Newbie
  • No Avatar
  • Registrado: Sep 05, 2010
  • Mensajes: 5
  • Status: Offline

Nota Septiembre 5th, 2010, 7:35 am

Hey,

Estoy haciendo un simulador de fútbol de base para una obra de juego electrónico donde los usuarios presenten sus teamsheets por correo. Im la automatización del sistema de modo que puedo seleccionar los equipos en un sitio web que simula a continuación, el partido para mí y devuelve un resultado.

El hogar / los equipos visitantes se presentan en una tabla, tomada de una base de datos MySQL que casillas situadas junto a cada jugador para seleccionar a jugar en ese partido aquí:

PHP Código: [ Select ]
$p=mysql_query("SELECT * FROM fixtures WHERE fixtureid='{$_GET['match']}' LIMIT 1", $c);
$pa=mysql_fetch_array($p);
print "<b><center><font size=+1>{$pa['homename']} v {$pa['awayname']}</font><br />
Division {$pa['tournament']} fixture | Turn {$pa['turn']}<br /><br />";
if ($pa['played'] > 0)
{
print "<b>This match has already been simulated. If you have entered the incorrect team or are unhappy with the result then please continue to select the squad.<br /><br /></b>";
}
$ht=mysql_query("SELECT * FROM players WHERE teamcode={$pa['hometeam']} AND rating2 > 0 ORDER BY posorder ASC", $c);
$at=mysql_query("SELECT * FROM players WHERE teamcode={$pa['awayteam']} AND rating2 > 0 ORDER BY posorder ASC", $c);
 
print "<form action='playmatch.php?stage=B&match=". $_GET['match']. "' method=post>
<div style='position: absolute; left: 200px; top: 80px;  width: 300px; padding: 1em;'>";
 
print "<font size=-1>
<table border=0>";
while ($h=mysql_fetch_array($ht))
{
 
print "<tr><td width=2%><input type='checkbox' value='" . $h['playerid'] ."' name='home[]'></td><td>
{$h['surname']}</td>
<td>{$h['pos1']}";
 
  1. $p=mysql_query("SELECT * FROM fixtures WHERE fixtureid='{$_GET['match']}' LIMIT 1", $c);
  2. $pa=mysql_fetch_array($p);
  3. print "<b><center><font size=+1>{$pa['homename']} v {$pa['awayname']}</font><br />
  4. Division {$pa['tournament']} fixture | Turn {$pa['turn']}<br /><br />";
  5. if ($pa['played'] > 0)
  6. {
  7. print "<b>This match has already been simulated. If you have entered the incorrect team or are unhappy with the result then please continue to select the squad.<br /><br /></b>";
  8. }
  9. $ht=mysql_query("SELECT * FROM players WHERE teamcode={$pa['hometeam']} AND rating2 > 0 ORDER BY posorder ASC", $c);
  10. $at=mysql_query("SELECT * FROM players WHERE teamcode={$pa['awayteam']} AND rating2 > 0 ORDER BY posorder ASC", $c);
  11.  
  12. print "<form action='playmatch.php?stage=B&match=". $_GET['match']. "' method=post>
  13. <div style='position: absolute; left: 200px; top: 80px;  width: 300px; padding: 1em;'>";
  14.  
  15. print "<font size=-1>
  16. <table border=0>";
  17. while ($h=mysql_fetch_array($ht))
  18. {
  19.  
  20. print "<tr><td width=2%><input type='checkbox' value='" . $h['playerid'] ."' name='home[]'></td><td>
  21. {$h['surname']}</td>
  22. <td>{$h['pos1']}";
  23.  


La forma continúa y es el mismo para el equipo visitante, salvo el nombre de la casilla de verificación está lejos [].

¿Dónde estoy teniendo problemas es que no sé cómo interpretar los datos devueltos por el buscador de la página siguiente.

Necesito seleccionar todos los jugadores (que ha sido seleccionado) de la base de datos utilizando los jugadores número de identificación exclusivo del valor de:

PHP Código: [ Select ]
value='" . $h['playerid'] ."'


He intentado varias foreach / while, pero no parece que devolver nada. En el momento en que han
PHP Código: [ Select ]
print "{$_POST['home']}";
 
  1. print "{$_POST['home']}";
  2.  

En la pantalla de retorno que imprime la palabra "Array". Por lo tanto sé que la información se está enviando a través del formulario como una matriz asociativa, pero no sé cómo acceder y utilizar los valores devueltos.

Cualquier ayuda es muy apreciada, Jake

PS, sé que mi php y sql es algo anticuado / extraño, básicamente porque me enteré de todo, desde MCCode hace unos años, pero aún así, él hace el trabajo.
  • Anonymous
  • Bot
  • No Avatar
  • Registrado: 25 Feb 2008
  • Mensajes: ?
  • Loc: Ozzuland
  • Status: Online

Nota Septiembre 5th, 2010, 7:35 am

  • JakeBurgh
  • Newbie
  • Newbie
  • No Avatar
  • Registrado: Sep 05, 2010
  • Mensajes: 5
  • Status: Offline

Nota Septiembre 6th, 2010, 5:47 am

Problema resuelto.

PHP Código: [ Select ]
$home=$_POST['home'];
print "$home[0]";
print "$home[1]";
 
  1. $home=$_POST['home'];
  2. print "$home[0]";
  3. print "$home[1]";
  4.  


$ Home [0] y luego devuelve el playerid del primer jugador seleccionado, $ home [1], el segundo, etc etc
  • Bigwebmaster
  • Site Admin
  • Site Admin
  • Avatar de Usuario
  • Registrado: Dic 20, 2002
  • Mensajes: 8934
  • Loc: Seattle, WA & Phoenix, AZ
  • Status: Offline

Nota Septiembre 6th, 2010, 11:34 am

Gracias por publicar la solución, tiene sentido ya que suena como $ _POST ["casa"] es una matriz de valores. Me alegro de que fueron capaces de resolverlo por su cuenta. Así que sólo para la referencia debería ser capaz de acceder a la variable como esta así:

PHP Código: [ Select ]
print $_POST['home'][0];
print $_POST['home'][1];
  1. print $_POST['home'][0];
  2. print $_POST['home'][1];
Ozzu Hosting - Want your website on a fast server like Ozzu?
  • righteous_trespasser
  • Scuffle
  • Genius
  • Avatar de Usuario
  • Registrado: Mar 12, 2007
  • Mensajes: 6228
  • Loc: South-Africa
  • Status: Offline

Nota Septiembre 7th, 2010, 2:48 am

si no sé cuántos $ _POST ["casa" artículos] habrá en esa matriz, puede utilizar un bucle foreach para recorrer a través de ellos, según se indica:

PHP Código: [ Select ]
<?php
  foreach($_POST['home'] as $key=>$value){
    //do something here
  }
?>
  1. <?php
  2.   foreach($_POST['home'] as $key=>$value){
  3.     //do something here
  4.   }
  5. ?>
Let's leave all our *plum* where it is and go live in the jungle ...

Publicar Información

  • Total de mensajes en este tema: 4 mensajes
  • Usuarios navegando por este Foro: No hay usuarios registrados visitando el Foro y 95 invitados
  • No puede abrir nuevos temas en este Foro
  • No puede responder a temas en este Foro
  • No puede editar sus mensajes en este Foro
  • No puede borrar sus mensajes en este Foro
  • No puede enviar adjuntos en este Foro
 
 

© 2011 Unmelted, LLC. Ozzu® es una marca registrada de Unmelted, LLC