-
Posts
24,606 -
Joined
-
Last visited
-
Days Won
831
Everything posted by Barand
-
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
-
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 | +------+ +------+ +------+ +------+ +------+ +------+ +------+ +------+ +------+ +------+
-
The error message tells you the query failed. Try adding a space after "LIMIT" $getQuery = "SELECT * FROM games LIMIT $initial_page, $limit";
-
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.
-
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.
-
Pivot Table or Cross Tab in PHP using MYSQLI for attendance
Barand replied to Zinn's topic in MySQL Help
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? -
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);
-
Your create table doesn't show whether they are InnoDb or not. They need to be, MyISAM won't work.
-
Show us the CREATE TABLE code for those two tbles.
-
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.
-
See reply to your first topic (There are many product review sites out there, this is not one.)
-
Put each image/text pair in a div. Position with a grid layout or with left float.
-
using foreach to loop over resultset from fetch_assoc();
Barand replied to webdeveloper123's topic in PHP Coding Help
I showed you exactly how to do it in your previous topic. How do you still manage to keep screwing it up? -
Can't scrape/find 3 html tags in php simple html dom perser
Barand replied to shaadamin44's topic in PHP Coding Help
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>';- 13 replies
-
Can't scrape/find 3 html tags in php simple html dom perser
Barand replied to shaadamin44's topic in PHP Coding Help
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>';- 13 replies
-
- 1
-
-
Can't scrape/find 3 html tags in php simple html dom perser
Barand replied to shaadamin44's topic in PHP Coding Help
I was offering an alternative- 13 replies
-
using foreach to loop over resultset from fetch_assoc();
Barand replied to webdeveloper123's topic in PHP Coding Help
In this instance ther is only one order - it's items from a shopping cart -
using foreach to loop over resultset from fetch_assoc();
Barand replied to webdeveloper123's topic in PHP Coding Help
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