i am trying to use forloop as a method to send in multiple data, however, the number that i want to loop is not the one i want to sent in. For example, when i allocated 1 - 5, it only stores in the data 1 - 2. And everytime no matter how many different amount i allocate, it only stores in 2 data, instead of the amount i required. I believe is the method of me looping got error. Please help. @allocate.php
<td width="1%">
<?php
$mysqli = new mysqli(spf, dbuser, dbpw, db);
$sql="Select cardno from tvoucher where lol='' order by cardno asc";
$result = $mysqli->query($sql);
if ($result->num_rows > 0) {
echo "<select name='cardfrom'>";
while($row = $result->fetch_assoc()) {
echo "<option value='" . $row['cardno'] . "'>" . $row['cardno'] . "</option>";
}
echo "</select>";
}
$mysqli->close();
?>
</td>
<td width="1%">
<?php
$mysqli = new mysqli(spf, dbuser, dbpw, db);
$sql="Select cardno from tvoucher where lol=''order by cardno asc";
$result = $mysqli->query($sql);
if ($result->num_rows > 0) {
echo "<select name='cardto'>";
while($row = $result->fetch_assoc()) {
echo "<option value='" . $row['cardno'] . "'>" . $row['cardno'] . "</option>";
}
echo "</select>";
}
$mysqli->close();
?>
@processallocate.php
for ($cardfrom=$cardfrom;$cardfrom<=$cardto;$cardfrom++)
{
if ($cardfrom && $staff_name && $session && $allocation_id && $staff_id && $admin_id && $lol && $request_id && $requestnoleft && $requestnoleft>-1)
{
$mysqli = new mysqli(spf, dbuser, dbpw, db);
$stmt = $mysqli->prepare("INSERT INTO allocation
(cardfrom, staff_name, session, allocation_id, staff_id, admin_id)
VALUES (?,?,?,?,?,?)");
$stmt->bind_param("ssssss", $cardfrom, $staff_name, $session, $allocation_id, $staff_id, $admin_id);
$result = $stmt->execute();
if ($cardfrom && $lol){
$mysqli = new mysqli(spf, dbuser, dbpw, db);
$stmt = $mysqli->prepare("update tvoucher set lol = '$lol' where cardno='$cardfrom'");
$stmt->bind_param("s", $lol);
$result=$stmt->execute();
if ($requestnoleft && $request_id){
$mysqli = new mysqli(spf, dbuser, dbpw, db);
$stmt = $mysqli->prepare("update request set requestno = '$requestnoleft' where request_id='$request_id'");
$stmt->bind_param("s", $requestno);
$result=$stmt->execute();
if ($result == true && $stmt->affected_rows>0)
{
echo "<b>". $check . "</b><br>";
echo "<script>window.location = 'http://mp14.mybitmp.org/spf/allocation.php'</script>";
}
else {
echo '<p>Taxi Voucher has already been allocated</p>';
echo '<p>Please <a href="allocation.php">Click Here</a> to return</p>';
break;
}
$stmt->close();
$mysqli->close();
}
}
}
else
{
echo '<p>Error</p>';
echo '<p>Please <a href="allocation.php">Click Here</a> to resubmit</p>';
}
}
?>
</div>
Aucun commentaire:
Enregistrer un commentaire