promenne odeslane _POSTem

Zdravim! Potreboval bych poradit:

Delam si aplikaci na hromadny edit databaze. Funguje to proste tak, ze si zvolim databazi a tabulku a nacte se mi velky formular, kde je vypis vsech zaznamu zobrazen v textovejch polickach. (abych to proste nemusel editovat radek po radku).

Ted tvorim skript, kterej vygeneruje SQL dotaz, kterej bude upravovat dle odeslanych hodnot jednotlive radky tabulky.

Jelikoz to ma byt univerzalni, potrebuji nejak vygenerovat SQL dotaz.
Ta stranka s formularem odesila promenne:
db = zvolena databaze
table = zvolena tabulka

a potom jednotlive promenne, ktere jsou stejnojmenne, jako sloupce ve vybrane tabulce.
Takze napriklad:

ID (array)
Nadpis (array)
obsah (array)

Nasel jsem si skript, kterej vycucne vsechny promenne, ktere byly odeslany na stranku.
function promenne($data)
{
Reset($data);
while(Current($data))
{
if(Key($data) != "db" AND Key($data) != "table") echo Key($data)." = ". Current($data);
next($data);
}
}
promenne($_POST);

A potreboval bych, aby to vytvorilo neco podobneho:

UPDATE $table SET nadpsis = '".$nadpis[$i]."', obsah = '".$obsah[$i]."' Where id = '".$id[$i]."';

Ale nevim jak na to...
Predem moc dekuji za help!
Neni uplně triviální. Postupně:
vygenerovat formulář
- vylistovat soupečky
- vypsat fromulář (inputy pojmenovat podle sloupečků (pole)

po zmene přijmout data (tak jak to mas v tom skriptu, to uz je stejne.

Tak. Co napřed?
Ale ja uz to vsechno vytvorene mam.
Tady mam na ukazku vygenerovany jeden formular.
Nevim jak z neho zpracovat ty data.
Je to popsano v 1.dotazu.
<TABLE border="0" cellpadding="1" cellspacing="0" bgcolor="#EDF1F3" width="100%">
<TR>
<TD class="hlavicka" nowrap><B>ID</B></TD>
<TD class="hlavicka" nowrap><B>DATUM</B></TD>
<TD class="hlavicka" nowrap><B>ZACATEK</B></TD>
<TD class="hlavicka" nowrap><B>KONEC</B></TD>
<TD class="hlavicka" nowrap><B>CJ</B></TD>
<TD class="hlavicka" nowrap><B>STAV</B></TD>
<TD class="hlavicka" nowrap><B>TYP</B></TD>
<TD class="hlavicka" nowrap><B>POZNAMKA</B></TD>
<TD class="hlavicka" nowrap><B>OZNACENI</B></TD>
<TD class="hlavicka" align="center" nowrap><B>::D::</B></TD>
</TR>
<TR>
<TD nowrap class="zapati" align="right">1<INPUT type="hidden" name="id[0]" value="1"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="datum[0]" value="2003-11-05" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="zacatek[0]" value="10:30:22" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="konec[0]" value="10:55:11" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="cj[0]" value="0300116799" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="stav[0]" value="O.K." class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="typ[0]" value="denní" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="poznamka[0]" value="" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="oznaceni[0]" value="2B" class="inpttext" style="width: 100%"></TD>
<TD class="zapati" nowrap><INPUT type="checkbox" name="del[0]" value="Y"><B>DEL</B></TD>
</TR>
<TR>
<TD nowrap class="zapati" align="right">2<INPUT type="hidden" name="id[1]" value="2"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="datum[1]" value="2003-11-03" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="zacatek[1]" value="10:30:22" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="konec[1]" value="10:55:11" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="cj[1]" value="0300116799" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="stav[1]" value="chyba pásky" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="typ[1]" value="denní" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="poznamka[1]" value="" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="oznaceni[1]" value="1B" class="inpttext" style="width: 100%"></TD>
<TD class="zapati" nowrap><INPUT type="checkbox" name="del[1]" value="Y"><B>DEL</B></TD>
</TR>
<TR>
<TD nowrap class="zapati" align="right">3<INPUT type="hidden" name="id[2]" value="3"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="datum[2]" value="2003-11-04" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="zacatek[2]" value="10:30:22" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="konec[2]" value="10:55:11" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="cj[2]" value="0300116799" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="stav[2]" value="O.K." class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="typ[2]" value="meziarchivace" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="poznamka[2]" value="" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="oznaceni[2]" value="M" class="inpttext" style="width: 100%"></TD>
<TD class="zapati" nowrap><INPUT type="checkbox" name="del[2]" value="Y"><B>DEL</B></TD>
</TR>
<TR>
<TD nowrap class="zapati" align="right">4<INPUT type="hidden" name="id[3]" value="4"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="datum[3]" value="2003-10-31" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="zacatek[3]" value="10:30:22" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="konec[3]" value="10:55:11" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="cj[3]" value="0300116799" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="stav[3]" value="O.K." class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="typ[3]" value="meziarchivace" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="poznamka[3]" value="" class="inpttext" style="width: 100%"></TD>
<TD nowrap class="bunka"><INPUT type="text" name="oznaceni[3]" value="M" class="inpttext" style="width: 100%"></TD>
<TD class="zapati" nowrap><INPUT type="checkbox" name="del[3]" value="Y"><B>DEL</B></TD>
</TR>
</TABLE>
pokud znas nazvy sloupecku, tak je to jednoduche, ne?
for ($i=0; $i < sizeof($_POST['sloupecek']); $i++ ) {
$update = 'update tabulka set sloupecek='. $_POST['sloupecek'][$i].', jiny_sloupecek=\''.$_POST['jiny_sloupecek'][$i].'\'';
mysql_query($update);
}

plus osetreni chyb, atd...
Jasne, nazvy sloupecku znam.
Viz ten ukazkovej vygenerovanej formular.
Ja to zkusim az se dostanu k apachi a pak se ozvu.
Jeste bych se chtel zeptat, jak to je s vicerozmernym polem.
Jaky mam dat nazev INPUTu ve formulari.
Treba: name="radek[1][Sloupec1]" value="blabla"
Je to spravne?
Áno
Zdravim! Tak uz to mam hotove! Udelal jsem to stejne trosku jinak.
Tady jsou zdrojove kody, kdyby nekdo chtel...
<!-- form.php -->
<TABLE border="0" cellspacing="0" cellpadding="0" width="100%" background="style.jpg">
<TR>
<TD height="60" STYLE="filter:glow(color=#7F9DB9,strenght=90)"><BR><H1>  Batch.Edit.DB</H1></TD>
</TR>
<TR>
<TD bgcolor="#c6d6e1" colspan="3" height="10">
<TABLE cellspacing="0" width="100%" height="10">
<TR>
<TD width="5%" class="menu" nowrap >
<FORM method="post" style="margin: 0px; border: 0px;">
Výběr databáze:
<SELECT name="db_tb" size="1" class="button">
<?
if($db_tb == "") echo " <OPTION><-- Zvolit databázi --></OPTION>\n";
if($db_tb <> "") echo " <OPTION><B>". $db_tb ."</B></OPTION>\n";
if($db_tb <> "") echo " <OPTION></OPTION>\n";
mysql_connect($host, $user, $pass);
$db_list = mysql_list_dbs();
for ($i = 0; $i < mysql_num_rows($db_list); $i++)
{

$db_tables = mysql_list_tables(mysql_tablename($db_list, $i));
for ($j = 0; $j < mysql_num_rows($db_tables); $j++)
{
echo " <OPTION>";
echo mysql_tablename($db_list, $i);
echo ": ";
echo mysql_tablename($db_tables, $j);
echo "</OPTION>\n";
}
}
mysql_close();
?>
</SELECT>
<INPUT type="submit" value=" OK " class="button2">
</FORM>
</TD>
</TR>
</TABLE>
</TD>
<TR>
</TABLE>

<!-- globals.php -->
<?
$host = "localhost";
$user = "*";
$pass = "
*";
?>

<style type="text/css">
BODY { font-family: "Verdana","Arial CE","Helvetica CE", Helvetica, Arial; color:#04283D; font-size:12px; scrollbar-track-color: #EDF1F3; scrollbar-face-color: #C6D6E1; scrollbar-highlight-color: #C6D6E1; scrollbar-3dlight-color: #e6f6ff; scrollbar-darkshadow-color: #a6b6c1; scrollbar-shadow-color: #C6D6E1; scrollbar-arrow-color: #04283D; cursor: url('hand.cur'); }
TD { font-family: "Verdana","Arial CE","Helvetica CE", Helvetica, Arial; color:#04283D; font-size:12px; }
.zapati { background-color:#C6D6E1; color:black; font-weight:bold; border-bottom:1px solid #a6b6c1; border-right:1px solid #a6b6c1; border-top:1px solid #e6f6ff; border-left:1px solid #e6f6ff; }
.hlavicka { background-color:#A23A4D; color:white; font-weight:bold; border-bottom:1px solid #720a1d; border-right:1px solid #720a1d; border-top:1px solid #d26a7d; border-left:1px solid #d26a7d; }
.bunka { background-color:#edf1f3; font-size:11px; border-bottom:1px solid #cdd1d3; border-right:1px solid #cdd1d3; }
.bunkatlusta { background-color:#edf1f3; font-size:11px; border-bottom:1px solid #cdd1d3; border-right:1px solid #cdd1d3; padding-left:5; padding-right:5; padding-top:1; padding-bottom:1; font-weight:bold; }
.nadpis { background-color:#237BAD; font-size:13px; color:white; padding-left:5px; }
.inpttext { border: 1px solid #7F9DB9; }
H1 { color:#C6D6E1 }
.menu { font-family: "Verdana","Arial CE","Helvetica CE", Helvetica, Arial; color:#04283D; font-size:10px; }
A { color:#04283D; text-decoration:none; cursor: url('ruka.cur')}
A:hover.up { background-color:black;color:white;text-decoration:none; }
A:hover.edit { color:red; text-decoration:none; }
A:hover { text-decoration:underline }
A.al { text-decoration:underline;color:black }
A:hover.al { text-decoration:underline;color:red }
.sort { color: white; text-decoration:none; }
.sort:hover.up { background-color: black; color: white; text-decoration:none; }
.sort:hover.edit { color:red; text-decoration:none; }
.sort:hover { text-decoration:underline }
.sort.al { text-decoration:underline;color:black }
.sort:hover.al { text-decoration:underline;color:red }
.button { background: url('ok2.gif'); cursor : hand; border:3px solid #C6D6E1; cursor: url('ruka.cur'); }
.button2 { border: 1px solid #7F9DB9; background: url('ok2.gif'); cursor : hand; cursor: url('ruka.cur'); }
</STYLE>

<!-- script.php -->
<?
require "globals.php";
$array=explode(": ",$db_tb);
$db = $array[0];
$table = $array[1];

mysql_Connect($host,$user,$pass);
mysql_select_db($db);

$result = mysql_query("SELECT * FROM ". $table);
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
for ($j = 0; $j < mysql_num_fields($result); $j++)
{
$jmenosloupce[] = mysql_field_name($result,$j);
$tempnazev = $jmenosloupce[$j];
$changequery[$i] = $changequery[$i] ." ". $jmenosloupce[$j] ." = '". $_REQUEST[$tempnazev][$i] ."',";
}

$podminka = mysql_fetch_row($result);
$changequery[$i] = "UPDATE ". $table ." SET". substr($changequery[$i], 0, -1). " Where ". mysql_field_name($result,0) ." = '". $podminka[0] ."'";
echo "Aktualizuji radek c.: ". $i ."... ";
$uprava = mysql_query($changequery[$i]);
if ($result == 0) echo("<B>Error " . mysql_errno() . ": " . mysql_error() . "</B>");

echo "<B>OK</B><BR>\n";
}
mysql_Close();
?>

<!-- index.php -->
<? require("globals.php"); ?>

<HEAD>
<SCRIPT language="javascript">
<!--
defaultStatus="Batch.Edit.DB - Hromadný editor DB :: by hoppik@centrum.cz ::";
document.oncontextmenu = function(){return false}
if(document.layers){
window.captureEvents(Event.MOUSEDOWN);
window.onmousedown = function(e){ if(e.target==document)return false; }} else {document.onmousedown = function(){return false}}
// -->
</SCRIPT>
<META http-equiv="Content-Language" content="cs">
<META http-equiv="Content-Type" content="text/html; charset=windows-1250">
<META http-equiv="pragma" content="no-cache">
<META http-equiv="cache-control" content="no-cache">
<META http-equiv="expires" content="Sat 21 Jun 2003 20:04:00">
<TITLE>Batch.Edit.DB</TITLE>
<LINK rel="stylesheet" type="text/css" href="main.css">
</HEAD>
<BODY background="images/back.jpg" topmargin="0" leftmargin="0">
<TABLE cellspacing="0" cellpadding="0" width="100%"><TR><TD>
<?
include ("form.php");

$array=explode(": ",$db_tb);
$db = $array[0];
$table = $array[1];

if($table == "" OR $db == "") exit;

mysql_connect($host,$user,$pass);
mysql_select_db($db);

$query = "SELECT * FROM ". $table;
$result = mysql_query($query);
$sloupce = mysql_num_fields($result) + 1;
echo "<FORM action=\"script.php\" method=\"post\">\n";
echo "<INPUT type=\"hidden\" name=\"db_tb\" value=\"". $db_tb ."\">\n";
echo "<TABLE border=\"0\" cellpadding=\"1\" cellspacing=\"0\" bgcolor=\"#EDF1F3\" width=\"100%\">\n";
echo " <TR>\n";

for ($i = 0; $i < mysql_num_fields($result); $i++)
{
echo(" <TD class=\"hlavicka\" nowrap><B>" . StrToUpper(mysql_field_name($result,$i)) . "</B></TD>\n");
}
echo " <TD class=\"hlavicka\" align=\"center\" nowrap><B>::D::</B></TD>\n";
echo " </TR>\n";
for ($i = 0; $i < mysql_num_rows($result); $i++)
{
echo(" <TR>\n");
$row_array = mysql_fetch_row($result);
for ($j = 0; $j < mysql_num_fields($result); $j++)
{
if(mysql_field_name($result, $j) <> "id")
{
echo(" <TD nowrap class=\"bunka\">");
echo("<INPUT type=\"text\" name=\"". mysql_field_name($result, $j) ."[". $i ."]\" value=\"" . $row_array[$j] . "\" class=\"inpttext\" style=\"width: 100%\">");
}
if(mysql_field_name($result, $j) == "id")
{
echo " <TD nowrap class=\"zapati\" align=\"right\">";
echo $row_array[$j];
echo "<INPUT type=\"hidden\" name=\"id[".$i."]\" value=\"". $row_array[$j] ."\">";
}
echo("</TD>\n");
}
echo " <TD class=\"zapati\" nowrap><INPUT type=\"checkbox\" name=\"del[".$i."]\" value=\"Y\"><B>DEL</B></TD>\n";
echo " </TR>\n";
}
echo " <TR>\n";
echo " <TD class=\"zapati\" colspan=\"" . $sloupce . "\">";
echo " V tabulce je celkem: ";
echo mysql_num_rows($result);
echo " záznamů.";
echo "</TD>\n";
echo " </TR>\n";
echo " <TR>\n";
echo " <TD class=\"bunka\" colspan=\"" . $sloupce . "\" align=\"center\">";
echo "<INPUT type=\"reset\" value=\" Původní hodnoty \" class=\"button\">";
echo "<INPUT type=\"submit\" value=\" Provést změny \" class=\"button\">";
echo "</TD>\n";
echo " </TR>\n";
echo "</TABLE>\n";
echo "</FORM>";
mysql_close();
?>
<BR>
<CENTER>
<HR size="1" width="70%">
<SMALL>© <A href="mailto:hoppik@centrum.cz">Tomáš Skočdopole</A></SMALL>
</CENTER>
</TD></TR></TABLE>
</BODY>