Forums

Tracking database activity

goingtocry 12 Sep, 2012
Hi guys

I need help...

I have two tables. Stock and Tracking.
The idea is that a Form is used to indicate stock coming in or out and store it in the Stock table This works. Also it adds data to the tracking table, which also works
The tracking table shows times and dates of who was adding or subtracting stock as well as when they last did a stock take.

I can get this all to work.

What I cannot get to work is the WHERE cf_id='1' part is. I have 15 stock items, but how do I load the form to replace the cf_id='1' with the cf_id of another item?

I have tried adding:
$ID=$_POST['cf_id'];


as well as cf_id='$ID'

I receive no errors, but i just get a blank. But if I put a cf_id='1' or cf_id='2' etc etc it shows the list...



The code I have been using is below....


 <?php      
            $db =& JFactory::getDBO();


            $query = "
              SELECT id, diff, cf_id, item, activity, user_drawn, user_stock_check, time_drawn, time_stock_check, drawing, actual FROM epr1i_stock_draw_tracking WHERE cf_id='1' ORDER BY cf_id DESC";
            $db->setQuery($query);
            $rows = $db->loadObjectList();

foreach ($rows as $row) {
          

              echo "<option value=$row->cf_id>$row->time_drawn $row->time_stock_check $row->user_drawn $row->user_stock_check In/Out: $row->drawing $row->activity Counted: $row->actual Difference: $row->diff<br></option>";
        }
?> 


the_fitz 12 Sep, 2012
Hi,
Is the value of cf_id established previously in your data stream? If it is then you may be able to access it with $form-data['cf_id'].

If it is all values for cf_id then just exclude the "where" completely.

the_fitz
goingtocry 13 Sep, 2012
Hi the_fitz

Yes you are correct. The stock was created in one form written to the stock database as new stock entries.
When stock is drawn or added I used chronoconnectivity and a new form for the user to add or take stock out. In doing so I also added a second table that it must write to for certain details like count and stock balance as well as the cf_id and the stock item at the same time.

Then when it is time for stock take, another form is used to calculate losses and actual count of stock against the balance, the person in charge can see the activity on who, when are how many items they took out which is being recorded on the tracking table.
When it writes to the tracking table i am using the original cf_id as a reference for the stock. The table key is just a simple "id" if that helps.


I am not 100% sure where I must put your suggestions...

The code i showed on opening this post is in the form itself. Like I said it works if i use a "1" or "2" etc.

Hence my username... is how I feel right now... ;-)
GreyHead 13 Sep, 2012
Hi goingtocry,

I've read this a couple of times and I don't see where the value of cf_id is supposed to come from. Is it from some other form, or are you passing it in the URL???

Bob
This topic is locked and no more replies can be posted.