Jump to content


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


[help] table form multiple rows and columns insert and retrival

Recommended Posts

given a input form,
formated as a table, with $x rows, $y columns,

1. how to collect all the data in each row and column, then insert each row[$x]column[$y] value in the table into database?

2. how to retrive it and present it in the same table format as if you are entering it?

*********** sample code ************
row across are types, column down are colours,
for each type, and each color, need to put in a number and record it into database.

echo "<table border=\"1\">\n";
echo "<tr>\n";

// Show Size Type name from selected size_type_id#
while ($row = mysql_fetch_array($query_size_name))
$size_name = $row['size_name'];
echo "<th>" . $size_name . "</th>\n";

$color1 = "#ffffff";
$color2 = "#ff0000";
$row_count = 0;

//display color selection
for ($y=0; $y<$how_many_color; $y++) // get_color_num change to user value
$row_color = ($row_count % 2) ? $color1 : $color2;
echo "<tr bgcolor=\"$row_color\">\n";
echo "<td>\n";
$sql = "SELECT color_name FROM color ORDER BY color_name";
$query = mysql_query($sql);

echo "<select name=\"color_id\">";
echo "<option value=\"\"</option>";

for ($x =0; $x<get_size_num($size_type_id); $x++)

while($c_color = mysql_fetch_array($query))

//assign variable
$color_id = $c_color['color_id'];
$color_name = $c_color['color_name'];
echo "<option value=\"". $color_id . "\">" . $color_name . "</option>";
// Define colors for the alternating rows

echo "<td><input size=\"5\" name=\"$x.$y\"></td>";

echo "</select>";
echo "</td>";
echo "</tr>\n";
echo "<tr>\n";
echo "<td><input type=\"submit\" value=\"Add All\" name=\"add_all\"></td>";
echo "</tr>\n";
echo "</form>";
echo "</table>\n";

*********** end sample code ************

Share this post

Link to post
Share on other sites


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.