Hi,
This post asks the same question as my post yesterday but I wanted to start a new thread for clarity. (hopefully that's ok)
I created a form with php using counters which allows a user to raise a requisition and add rows (line items) pending how many items they want to add. The form has one requisition number and either 1, 2 or 3 items.
The user raises 2 requisitions with 3 items for each and INSERTS to db which looks like:
Req - Item - Status
abc - 1 - pending
abc - 2 - pending
abc - 3 - pending
xyz - 1 - pending
xyz - 2 - pending
xyz - 3 - pending
I SELECT these requisitions with
$reqquery = "SELECT * FROM `porders` WHERE `username` = '$username' AND `type` = 'request' ";
$userreqs = mysql_query($reqquery) or die(mysql_error());
while ($row = mysql_fetch_row($userreqs)) {
$reqno = $row[6]; $item = $row[8]; $status = $row[2];?>
<tr>
<td><?php echo $reqno;?></td>
<td><?php echo $item;?></td>
<td>><?php echo $status;?></td>
</tr>
}
This loops through and echos out all the 6 rows with the reqno, item and status shown. This was ok but it duplicates both reqno 3 times each.
So I changed <td><?php echo $reqno;?></td>
to
<td>
if ($item <= 1) {
echo $reqno;
}
</td>
This sorts it correctly and only displays the reqno on item 1.
And this is where I'm struggling:
The above SELECT has no status stipulation so it displays all the items so there is always a item 1 which makes it work.
I created another page which allows another user to change the status for each item in the db from pending to rejected.
This user changes the status of item 1 in the first requisition so the db looks like:
Req - Item - Status
abc - 1 - rejected
abc - 2 - pending
abc - 3 - pending
xyz - 1 - pending
xyz - 2 - pending
xyz - 3 - pending
Then I created another page for the original user to display all requisitions with status pending with the following:
$reqquery = "SELECT * FROM `porders` WHERE `username` = '$username' AND `type` = 'request' AND `status` = 'pending' ";
$userreqs = mysql_query($reqquery) or die(mysql_error());
And here's my problem, there's no item 1.
I've now changed
<td>
if ($item <= 1) {
echo $reqno;
}
</td>
to
<td>
if ($item == 1) {
echo $reqno;
}
elseif ($item == 2) {
echo $reqno;
}
elseif ($item == 3) {
echo $reqno;
}
</td>
And of course this echos out the reqno at every item duplicating it again.
IDEA
This idea makes sense for me to try but not sure how to construct it or if it will be valid, can't get it to work. I need to stipulate the reqno and item no in the above block like this:
<td>
if ($reqno == $reqno) & ($item == 1) {
echo $reqno;
}
elseif ($reqno == $reqno) & ($item == 2) {
echo $reqno;
}
elseif ($reqno == $reqno} & ($item == 3) {
echo $reqno;
}
</td>
All the data is in the row, the reqno, item no and status. the SELECT filters status and the above is hopefully saying
if the $reqno is the same as the $reqno (which it will be but it allows me to link the reqno with the item no) and the $item is = to 1 echo $reqno else do item 2 else do item 3
I apologise for the length of this, I did try and streamline it as much as possible but its still ended up as this.
Thanks in advance for any ideas O.