Jump to content

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


zlzk

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";
$row_count++;
$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 ************
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.