By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,890 Members | 1,039 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,890 IT Pros & Developers. It's quick & easy.

need help, next record problem

P: 8
Dear all..
I try to make an inventory control, with FIFO(first in first out) base, but I have a problem with the next record.
this is the code i make :


[PHP]$db = new clsDBMassimo;
$product_id = $Stock->product_id->GetValue();
$AmOrdered = $Stock->stock_out_unit->GetValue();
//check if the stock is enough
$sql = "SELECT SUM(stock_in_unit) as Total FROM stock_level WHERE product_id = $product_id";
$db->query($sql);
$result = $db->next_record();
if($result) ($Total = $db->f("Total"));
//if stock not enough, then cancel insert and give error message, but i still have an error
if($Total < $AmOrdered){
$Stock->Errors->addError("Stock Not Enough");=>in this part also have problem.event
$db->close(); though I already add an error, but stock out still inserted on table.any suggestion?
}else{ //if the stock is enough then select from table stock_level
$sql = "SELECT * FROM stock_level WHERE product_id = $product_id ORDER BY in_date";
$db->query($sql);
$result= $db->next_record();
$IDnya = $db->f("stock_level_id");
$AmOnHand = $db->f("stock_in_unit");

while($db->next_record()){
//loop as long as amount ordered > 0
while ($AmOrdered > 0){
if($AmOrdered < $AmOnHand){
$Res = $AmOnHand - $AmOrdered;
$update = "UPDATE stock_level SET stock_in_unit = $Res where stock_level_id = $IDnya";
$db->query($update);
$AmOrdered = 0;
}else{
$AmOrdered = $AmOrdered - $AmOnHand;
$update = "UPDATE stock_level SET stock_in_unit = 0 where stock_level_id = $IDnya";
$db->query($update);
//here should be move to the next record to get the next stock, but can not move to next record
}
}
}
$db->close();
} [/PHP]

Please give any suggestions, for the error I got or for the code structure. any helps are appreciated.
Thanks a lot
Aug 16 '08 #1
Share this Question
Share on Google+
4 Replies


dlite922
Expert 100+
P: 1,584
Let's see your next record function.

does it correctly? ie each time the while loop calls it, it returns the next record until empty?

try to put "echo" or "die('message'" statement to try to see how the code is executing (tracing the logic)

Let us know...



Dan
Aug 16 '08 #2

P: 8
Hi
thanks for reply. I forget to attach the function. Here's the function :
[PHP]function next_record() {
if (!$this->Query_ID)
return 0;

$this->Record = @mysql_fetch_array($this->Query_ID);
$this->Row += 1;
$this->Errno = mysql_errno();
$this->Error = mysql_error();

$stat = is_array($this->Record);
if (!$stat && $this->Auto_Free) {
$this->free_result();
}
return $stat;
}[/PHP]
Aug 16 '08 #3

dlite922
Expert 100+
P: 1,584
I think the problem lies in your db class and or in the way you are using it.

Did you write that class yourself?

you're initializing $result twice, with the same thing function call. In this case, next_record(). This function returns a boolean if the next record exists.

For example if you have only one record, the second time you call it, it will return false.

I wish I could help you more, but you must debug this yourself. I'm not too sure of the problem your having either, you didn't describe the issue well enough.



Dan
Aug 17 '08 #4

P: 8
Hi Dan..
Thank you for your reply. You're right, the problem is the way I use my class.
After few day stuck, finally i did it :)
Thank you
Aug 17 '08 #5

Post your reply

Sign in to post your reply or Sign up for a free account.