Jump to content

Barand

Moderators
  • Posts

    24,606
  • Joined

  • Last visited

  • Days Won

    831

Everything posted by Barand

  1. They are updated - it's just that the qty value hasn't changed in all of them if the sales were fulfilled by earlier stock records.
  2. Now it looks like you read my post. Have you tried it?
  3. Forget the above. I just noticed you have updated the subquery as I told you! That could be the problem.
  4. Working OK my end (unless I missed something), perhaps it's your data. Send dumps of stock, sales and basket that you are testing with.
  5. You can't join to the stock table in the subquery for the total sales. If you have, say, 3 records for an item then you will treble the sales total for that item. Something like this.. SELECT item_id , sum(quantity) as sold FROM sales sl JOIN basket b ON b.basket_id = sl.basket_id AND b.sale_time > (SELECT MAX(updated_date) FROM stock) GROUP BY item_id
  6. I do it by just showing buttons for first and last and a few either side of the current page +------+ +------+ +------+ +------+ +------+ +------+ +------+ +------+ +------+ +------+ | Prev | | 1 | . . | 97 | | 98 | | 99 | 100 | 101 | | 102 | | 103 | . . | 261 | | Next | +------+ +------+ +------+ +------+ +------+ +------+ +------+ +------+ +------+ +------+
  7. Of course you can. Just process those sales where basket.sale_time > latest stock.updated_date. PS this assumes that that the updated_date is only updated when the stock levels are updated and not when a purchase is added.
  8. The error message tells you the query failed. Try adding a space after "LIMIT" $getQuery = "SELECT * FROM games LIMIT $initial_page, $limit";
  9. Taking a look at just item_id #1. Starting stock : 100 First run sales : 2 Stock now : 98 Second run sales : 12 (2 + 10) Stock now : 86 Third run sales : 17 (2 + 10 + 5) Stock now : 69. Each time you run it you are subtracting sales that have already been subtracted. Each run needs to process only sales since the last stock update. I woud have done this in the query but your sales data contains no date info to make it possible.
  10. That is done in the query. My query can only be run once for a set of sales data as each time it reduces the stock and updates the stock table (as you requested). Not the best method as it means storing derived data. I only did it as an intellectual exercise, picking up the gauntlet that you threw down. As your select query only reads data it can be run as often you want. Using your purchase order table as a stock table is not one of your best ideas. Maintain that table and the sales table then query the two, as you have done, to get the current stock position.
  11. I have recreated your attendance table and have run your code. I now know what you don't want. (109 columns labelled "31-May") Perhaps you could tell us what you do want?
  12. try INSERT INTO stock (stock_id, qty) SELECT stock_id , newqty FROM ( SELECT stock_id , @sales := IF(@prev = k.item_id, @sales, sold) as sales , IF(qty <= @sales, 0, qty - @sales) as newqty , @sales := IF(@sales >= qty, @sales - qty, 0) , @prev := k.item_id as item FROM stock k JOIN ( SELECT item_id , sum(quantity) as sold FROM sales GROUP BY item_id ) s ON k.item_id = s.item_id AND qty_type = 'a' JOIN (SELECT @prev:=null, @sales:=0) init ORDER BY k.item_id, stock_id ) calc ON DUPLICATE KEY UPDATE qty = VALUES(qty);
  13. Why have you contrived a stock table with multiple rows per item? What is the significance of qty_type?
  14. Your create table doesn't show whether they are InnoDb or not. They need to be, MyISAM won't work.
  15. Show us the CREATE TABLE code for those two tbles.
  16. select catid , count(*) as total from table group by catid
  17. Bad SQL syntax, not uncommon when using concatenated segments. If I provide variable values then echo your SQL $Surname = 'Smith'; $Maidenname = 'Jones'; $Firstname = 'Mary'; $sql="SELECT * FROM 1984 WHERE Surname LIKE $Surname AND Maidenname LIKE '%".$Maidenname."%' AND Firstname LIKE '%".$Firstname."%'"; echo $sql; giving SELECT * FROM 1984 WHERE Surname LIKE Smith AND Maidenname LIKE '%Jones%' AND Firstname LIKE '%Mary%' ^^^^^ Don't use SELECT *, specify the columns you need. 1984 table name implies you have separate tables for the people for different years (of birth?). Why not put them in one table and add year column to the data. As G said, use prepared statements, then the query becomes SELECT * FROM 1984 WHERE Surname LIKE ? AND Maidenname LIKE ? AND Firstname LIKE ? ; Provide the data values when you execute the query.
  18. See reply to your first topic (There are many product review sites out there, this is not one.)
  19. Put each image/text pair in a div. Position with a grid layout or with left float.
  20. I showed you exactly how to do it in your previous topic. How do you still manage to keep screwing it up?
  21. Here's a simple_html_dom/simplexml hybrid solution (the one you can't do !) $html = '<html> <body> <div class="entry-content"> <h2>hi tags?</h2> <ul> <li>some text</li> <li>sometext</li> <li>sometext</li> <li>sometext</li> </ul> <h2>hi tags2 ?</h2> <ul> <li>some text</li> <li>sometext</li> <li>To ometext</li> <li>Theometext</li> </ul> </div> </body> </html>'; $dom = new simple_html_dom(); $dom->load($html); $div = $dom->find('div[class="entry-content"]')[0]->__toString(); $xml = simplexml_load_string($div); $tags = (array) $xml->xpath("//ul")[0]->li; echo '<pre>' . print_r($tags, 1) . '</pre>';
  22. like this $html = '<html> <body> <div class="entry-content"> <h2>hi tags?</h2> <ul> <li>some text</li> <li>sometext</li> <li>sometext</li> <li>sometext</li> </ul> <h2>hi tags2 ?</h2> <ul> <li>some text</li> <li>sometext</li> <li>To ometext</li> <li>Theometext</li> </ul> </div> </body> </html>'; $xml = simplexml_load_string($html); $tags = (array) $xml->xpath("//div[@class='entry-content']/ul")[0]->li; echo '<pre>$tags= ' . print_r($tags, 1) . '</pre>';
  23. In this instance ther is only one order - it's items from a shopping cart
  24. The do.. while is required in the case. the data is basically +----------+--------+ | customer | item 1 | | customer | item 2 | | customer | item 3 | +----------+--------+ We read the first row and output the customer data as the order header. In our loop we now need to output the 3 items. We still have the first row in our buffer. If we use a while loop we lose item 1 and only output items 2 and 3. The do while lets us output item 1 then loop throuugh 2 and 3 to output those also
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.