Please Help Me.
I have form=myform
like this
<form name='myform' method='post' action='update.php'>
<div id='add-new-button' style='padding:9px;'>
<input type='submit' name='pilih' value='Update' ></div>
<div class='tbl_sp'>
<table cellspacing='0' cellpadding='0' id='table-detail'><thead >
<tr>
<th>No</th>
<th>Custname</th>
</tr></thead><tbody>";
$counter = 1;
$query= mssql_query("SELECT top 10 * from Customer ");
$f=1;
while ($r=mssql_fetch_array($query))
{
if (is_float($counter/2)) {$class = "class='alt'"; } else { $class = ""; };
echo"<tr $class>
<td><input type='hidden' name='data".$f."' value='".$r['No']."' />$r[tNo]</td>
<td>$r[CustName]</td>
</tr>
"; $f++;
$counter++;
}
echo"</tbody></table><input type='hidden' name='m' value='".$f."' /></div><div class='center'>
<table cellspacing='0' cellpadding='0' id='table-detail'><thead >
<tr>
<th>Check</th>
<th>Tools</th>
</tr></thead><tbody>";
$counter = 1;
$query= mssql_query("SELECT * from tools");
$g=1;
while ($r=mssql_fetch_array($query))
{
if (is_float($counter/2)) {$class = "class='alt'"; } else { $class = ""; };
echo"<tr $class>
<td><input type='checkbox' name='id".$g."' value='".$r['tools']."' /></td>
<td>$r[tools]</td>
</tr>
"; $g++;
$counter++;
}";
</div>";
echo"</tbody></table></form><input type='hidden' name='n' value='".$g."' /> </div>";
}}
results
after form action update.php with code like this
$tools_total = 0;
$customer_total = 0;
foreach ($_POST as $key => $value) {
if (strpos($key, 'data') === 0) {
$customer_total++; //getting total number of checked customers
}
if (strpos($key, 'id') === 0) {
$tools_total++; //getting total number of tools
}
}
$k=1;
for($i=1; $i<=$customer_total; $i++)
{
($k>$tools_total)?$k=1:''; //reset tools counter
//This if statement is not necessary, since I'm guessing
//your $_POST['m'] and $_POST['n'] are giving you the total set values.
if (isset($_POST['id'.$k]) && isset($_POST['data'.$i])){
$data=$_POST['data'.$i];
$ini=$_POST['id'.$k];
echo " tools ='$ini' and customer='$data' <br>\n";
}
$k++;
}
How to code with results like this.
tools ='AB'and Customer='1'
tools ='AC'and Customer='2'
tools ='AB'and Customer='3'
Note:
$_POST['m'] = count customer
$_POST['n'] = count tools
Table customer (Count=10) Table Tools (Count=20) Description: if I Check table Tools then table customer will set to table tools that in check. example: I Check Tools AB and AC and results must be:
tools AB and customer 1
tools AC and customer 2
tools AB and customer 3
tools AC and customer 4
tools AB and customer 5
tools AC and customer 6
tools AB and customer 7
tools AC and customer 8
tools AB and customer 9
tools AC and customer 10