データベースの値を使用してphpとhtmlを使用してテーブルを作成していますが、テーブルのフィールドはテキストフィールドです。1列目のテキストフィールドはすべて同じ名前で、2列目のテキストフィールドはすべて同じ名前です...など。
最初の5つの列の後に空の列があり、その行の最初の5つのテキストフィールドの合計を表示することになっています。すべての行は異なる形式です。私はこれを行う方法を理解していません、フォームによってテキストフィールドを選択する簡単な方法があるかどうかさえわかりません、それでどんな助けも素晴らしいでしょう。
最初の5つのテキストフィールドの合計がその空の列に表示されることになっているため、テキストボックスの値が変更されたときにjavascript関数をトリガーする必要があります。これを行う方法のアイデアとして誰かがいれば、それは素晴らしいことです。
テーブル作成コードを確認したい場合:
<?php
$arrayida=array(0);
$arrayidp=array(0);
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="3Ciclo"; // Database name
// Table name
// Connect to server and select database.
mysql_connect("$host", "$username", "$password") or die("cannot connect");
mysql_select_db("$db_name") or die("Cannot select Database.");
$queryida="SELECT * FROM areas where tipo='AE' or tipo='C'";
$resultida=mysql_query($queryida);
while($b = mysql_fetch_array($resultida))
{
$ida=$b["ida"];
if (in_array ($ida , $arrayida ))
{
}else{
$arrayida[]=$ida;
/*while($b = mysql_fetch_array($resultida))
{
?>
<td> <?php echo $ida." - ".$b['nome']; ?> </td>
<?php
}*/
}
}
sort($arrayida);
//print_r($arrayida);
foreach ($arrayida as $key => $val)
{
if($key <> 0)
{
if ($key == 5){
$prev=$val;
$queryida="SELECT * FROM areas where ida=".$val;
$resultida=mysql_query($queryida);
while($b = mysql_fetch_array($resultida))
{
$nome=$b["nome"];
$idz=$b["ida"];
?> <td style="font-size:9px"> <?php echo "$nome"; ?> </td> <td style="background-color:#FFF"> </td> <?php
}
}else
{
$queryida="SELECT * FROM areas where ida=".$val;
$resultida=mysql_query($queryida);
while($b = mysql_fetch_array($resultida))
{
$nome=$b["nome"];
$idz=$b["ida"];
?> <td style="font-size:9px"> <?php echo "$nome"; ?> </td> <?php
}
}
}
}
///////////////////////////////////////////////////////
$sql="SELECT * FROM relacoes as a inner join areas as b on a.ida=b.ida where b.tipo='AE' or b.tipo='C'";
$resultrelacoes=mysql_query($sql);
$count=mysql_num_rows($resultrelacoes) + 1;
while ($r = mysql_fetch_array($resultrelacoes))
{
$idp=$r["idp"];
$queryidp="SELECT * FROM profissoes where idp=".$idp;
$resultidp=mysql_query($queryidp);
$idacheck=$r["ida"];
if (in_array ($idp , $arrayidp ) )
{
$x=array_search($idacheck, $arrayida);
$res=$x - $xpast;
$a= 5-$xpast;
for ($i=1;$i<=$res;$i++)
{
$pos=$arrayida[$xpast + $i];
/*echo "<script type='text/javascript'>alert('{$pos}');</script>";*/
if($i <> $res )
{
?><td><input type="text" name="<?php echo $pos ?>" id="<?php echo $pos ?>" style="width:40px" /> </td> <?php
}else
{
?><td><input type="text" name="<?php echo $pos ?>" id="<?php echo $pos ?>" value="<?php echo $r["percentagem"]; ?>" style="width:40px" /> </td> <?php
}
if ($i==$a){
?><td> </td> <?php
}
}
}else{
$arrayidp[]=$idp;
while($b = mysql_fetch_array($resultidp))
{
if (array_search($idp,$arrayidp)<>1)
{
$a= 5-$xpast;
$max = sizeof($arrayida);
for ($i=1;$i<=$max - $xpast - 1;$i++)
{
$pos=$arrayida[$xpast + $i];
?> <td><input type="text" name="<?php echo $pos ?>" id="<?php echo $pos ?>" style="width:40px" /> </td> <?php
if($i==$a){
?> <td> </td> <?php
}
if($i==($max-$xpast-1)){
?> <td><input onclick="soma()" type="submit" /></td> <?php
}
}
}
?></form > </tr> <form id="1" ACTION="http://www.cs.tut.fi/cgi-bin/run/~jkorpela/echo.cgi"
METHOD="POST"> <tr> <td style="font-size:9px;"> <?php echo $b['nome']; ?> </td>
<?php
$idacheck=$r["ida"] ;
$x=array_search($idacheck, $arrayida);
for ($i=1;$i<=$x;$i++)
{
$pos=$i;
if($i <> $x)
{
if ($i==5){
?> <td><input type="text" name="<?php echo $pos ?>" id="<?php echo $pos ?>" style="width:40px" /> </td> <td></td><?php
}else{
?> <td><input type="text" name="<?php echo $pos ?>" id="<?php echo $pos ?>" style="width:40px" /> </td> <?php
}
}else
{
?><td><input type="text" name="<?php echo $pos ?>" id="<?php echo $pos ?>" value="<?php echo $r["percentagem"]; ?>" style="width:40px" /> </td> <?php
}
}
}
}
$xpast=$x;
}
$a= 5-$xpast;
$max = sizeof($arrayida);
for ($i=1;$i<=$max - $xpast - 1;$i++){
?> <td><input type="text" name="textfield" id="textfield" style="width:40px" /> </td> <?php
if($i==$a){
?> <td> </td> <?php
}
if($i==($max-$xpast-1)){
?> <td><input type="submit" /></td> <?php
}
}
//FIM DA 1ª TABELA /////////////////////////////////////////////////////// ?>`