i am working on a script that uses a counter in order to display some things from a data base now when i submitt from one of the two form buttons it always returns the last variables that would have been in the index and i am trying to get the variables from that specific line but when it postes it always the last varable from the loop and i cant get it to work any help would be appreciated
sorry the code is kinda long but if you want i will post just the loop and where it gets posted
session_start();
if ($_SESSION['username']) {
$date = date("m/d/y");
$ij= 0;
$i = 0;
$what2do = $_POST['what2do'];
$date4 = $_POST['date4'];
$dd = $_POST['dd'];
//==========================================================================================================
// define make data base connection
//==========================================================================================================
function connectdb()
{
$h = "localhost";
$u = "****";
$p = "****";
$d = "****";
$link = mysql_connect ($h, $u, $p) or die ("Could not connect to database, try again later");
mysql_select_db($d,$link);
}
//==========================================================================================================
// done button
//==========================================================================================================
if ($dd == "DONE") {
connectdb();
echo "DONE";
$q1 = "UPDATE things SET status='DONE' WHERE date=$date4 AND ;";
$query = mysql_query($q1);
}
//==========================================================================================================
// when search is pressed find things and put them on screen
//==========================================================================================================
if ($what2do == "SEARCH") {
$date3 = $_POST['date3'];
if ($date4) {
$DONE1 = $_POST['DONE1'];
$date3 = $date4;
}
connectdb();
$done = "DONE";
$query = "SELECT * FROM things WHERE date = '$date3' AND status != '$done'";
$result = mysql_query($query) or die(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_BOTH)){
$index[$ij] = $row[0];
$sdate[$ij] = $row[1];
$sbranch[$ij] = $row[2];
$svendor[$ij] = $row[3];
$spo[$ij] = $row[4];
$swriter[$ij] = $row[5];
$sinv2[$ij] = $row[6];
$sinvtotal[$ij] = $row[7];
$spototal[$ij] = $row[8];
$sinvduedate[$ij] = $row[9];
$varience[$ij] = $row[10];
//echo $vendor[$ij];
$ij = $ij + 1;
//echo $ij;
}
$ij = $ij - 1;
if ($svendor[0]) {
//==========================================================================================================
// make the table for all the data
//==========================================================================================================
echo "
<style>TABLE { border-collapse: collapse; }</style>
<p align='center'><table cellpadding='0' cellspacing='0' border='1' bordercolordark='#000000' width='98%' bordercolorlight='#000000'>
<tr>
<td><p align='center'>DATE</p></td>
<td><p align='center'>BRANCH</p></td>
<td><p align='center'>VENDOR</p></td>
<td><p align='center'>PO</p></td>
<td><p align='center'>WRITER</p></td>
<td><p align='center'>INV</p></td>
<td><p align='center'>INV. TOTAL</p></td>
<td><p align='center'>PO. TOTAL</p></td>
<td><p align='center'>VARIENCE</p></td>
<td><p align='center'>INV DUE DATE</p></td>
<td><p align='center'>REASON FOR VARIENCE</p></td>
<td><p align='center'>MARK AS DONE</p></td>
</tr>";
for ( $counter = 0 ; $counter <= $ij; $counter += 1) {
echo "<form name='$counter' action='lookup.php' method='POST'>";
$var[$counter] = ($sinvtotal[$counter] - $spototal[$counter]);
echo "
<tr>
<td>$sdate[$counter]</td>
<td>$sbranch[$counter]</td>
<td>$svendor[$counter]</td>
<td>$spo[$counter]</td>
<td>$swriter[$counter]</td>
<td>$sinv2[$counter]</td>
<td>$sinvtotal[$counter]</td>
<td>$spototal[$counter]</td>
<td>$var[$counter]</td>
<td>$sinvduedate[$counter]</td>
<td>$varience[$counter]</td>";
echo "<input type='hidden' name='ven' value='$index[$counter]' /><td><input type='hidden' name='what2do' value='SEARCH' /><input type='hidden' name='date3' value='$sdate[$counter]' /><input type='submit' name='dd' value='DONE' /><input type='submit' name='dd' value='COMMENT' /></td>
</tr>
";
echo "<form>";
}
echo"</table></p></br></br></br></br>";
}ELSE{
//==========================================================================================================
// if there is no data print on screen no data
//==========================================================================================================
echo "<p align='center'><b><font size='+2'>NO RESULTS</font></b></p>";
}
}
//==========================================================================================================
// if the variable is full print nothing else make the search box pop up
//==========================================================================================================
if ($svendor[0]) {
}else{
echo "<form name='input' action='".$_SERVER['php_self']."' method='POST'>";
echo "</br></br><p align='center'><table>
<tr>
<td>SEARCH</td>
<td><input name='date3' value='$date' type='text' /></td>
</tr>
</table><p align='center'><input type='submit' name='what2do' value='SEARCH' /></p></p></form></br></br></br>";
}
//==========================================================================================================
// what happenes when the comment button is pushed
//==========================================================================================================
if ($dd == "COMMENT") {
echo "<p align='center'><table cellpadding='0' cellspacing='0' border='1' bordercolordark='#000000' bordercolorlight='#000000'>
<tr>
<td><input size='70' type='text' /></td>
</tr>
<tr>
<td><p align='center'><input type='submit' value='ADD COMMENT' /></p></td>
</tr>
</table></p>";
}
}ELSE{
}