Jump to content

select box within an array help


fulcrum2

Recommended Posts

Hello - I am trying to create a data submission form using an array of blank fields that when submitted populate entered data into a table.  I want to add a drop down select box for one of the entry fields and am having issues for the selected value to propogate to the database entry.  Please find the script below. I'd really appreciate your help!

 

THE ORIGINAL SCRIPT THAT WORKS: 

 

foreach($stats AS $stat)//Definition of each statistics row of data

{

            $stats = array( "player_id", "team", "GP", "goals", "assists", "PIM", "plusminus", "jersey_id", "team_id");

            printf ("<td><input type=text name=data[$i][$stat] value=\"\" size=4></td>"); // data from DB

        }

 

THEN THE FOLLOWING CODE WOULD SUBMIT INTO THE DB (with separate php file defining the columns)

$sql =  "INSERT INTO stats_player

(stats_player_id, year,season,league,tour_id,season_part,player_id,team,GP,goals,assists,PIM,plusminus,jersey_id,team_id)

VALUES('',";

$sql .= "'$year','$season','$league','$tour_id','$season_part',";

foreach( $_POST['data'][$id] AS $col => $value )

{

include 'stats_include_headings_tour.php';

$sql .= "'$value',";

 

THE NEW CODE THAT NEEDS HELP (it successfully displays the select box, but doesn't transfer the entered player_id value into the insert statement above. Can I not use the select code here as part of the stats array? or am I doing it wrong?):

foreach($stats AS $stat)//Definition of each statistics row of data

{

echo "<td>";

// printf ("<td><input type=text name=data[$i][$stat] value=\"\" size=4></td>"); // data from DB

 

if ($x=='0'){

$sql_player = "SELECT * FROM player WHERE draft_year=2003 ORDER BY lname";

$result_player = mysql_query($sql_player);

$myrow_player = mysql_fetch_assoc($result_player);

echo '<select name=data[$i][$stat]>';

do {

$lname = $myrow_player ["lname"];

$player_id_internal = $myrow_player ["player_id"];

//foreach ($lname as $key => $value) {

echo "<option value=\"$player_id_internal\"> $lname </option>\n";

}while ($myrow_player = mysql_fetch_assoc ($result_player));

echo '</select>';

}

else {

echo "<input type=text name=data[$i][$stat] value=\"\" size=4>";

}

Link to comment
https://forums.phpfreaks.com/topic/119351-select-box-within-an-array-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.