473,394 Members | 1,703 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

need help, next record problem

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
4 2307
dlite922
1,584 Expert 1GB
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
doxtor
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
1,584 Expert 1GB
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
doxtor
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

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

Similar topics

12
by: jason | last post by:
Access 2000: I have a customer-inventory table I need to loop through and compile a list of all the inventory items the customer is tracking. The problem I am finding is that a simple loop...
1
by: Rohit Raghuwanshi | last post by:
Hello all, we are running a delphi application with DB2 V8.01 which is causing deadlocks when rows are being inserted into a table. Attaching the Event Monitor Log (DEADLOCKS WITH DETAILS) here....
9
by: pankaj_wolfhunter | last post by:
Hi, I need some clearance on the following questions: 1) Does LOAD command updates indexes defined for a table? 2) Is REPLACE option in the LOAD command a logged operation? Help will be...
2
by: qsweetbee | last post by:
I have a form(fAddUsers) in my database. It is continue form for data entry. Some fields are required fields. Some are optional fields. There is 1 particular filed(TokenExpirationDate)on the form...
19
by: James Fortune | last post by:
I have a lot of respect for David Fenton and Allen Browne, but I don't understand why people who know how to write code to completely replace a front end do not write something that will automate...
0
by: Peter Newman | last post by:
vb.net 2003 Sql 2005 Ive been banging my head against a brick wall for the last day trying to figure out what im doing wrong I have a Dataset and a Form with text boxes that are bound to the...
1
by: Peter Herath | last post by:
I have created a report using sample codes taken by the forum. one problem is that the report displays the field/column names in the table in columnar format(field names display in rows.) but i want...
2
by: StevenChiasson | last post by:
For the record, not a student, just someone attempting to learn C++. Anyway, the problem I'm having right now is the member function detAddress, of object controller. This is more or less, your...
0
by: LanaR | last post by:
Hello, one sql statement is causing severe performance issue. The problem occurs only in UDB environment, the same statemnt on the mainframe is running fine. I have an explain output from the sql....
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.