-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
"php charts without javascript"
-
A couple of minutes Googling came up with this contender... https://jpgraph.net/ Or you could always just code your own charts.
-
According to that phpinfo() output, you do have the extension pdo_mysql (In your extension folder there should be the file php_pdo_mysql.dll)
-
Check the output from phpinfo(); This will tell you two things relevant to this which php.ini file is currently in use and which you should be editting whether PDO is already installed, for example
-
It could be the sheer quantity of data, in which case a cron job would be a good move. On the other hand you may be using a really inefficient method for processing the data, in which case optimization could be the answer. We have no way of knowing.
-
That above section of code is totally FUBAR You test the value of $cat['category'] and afterwards decide to see if it is set! Then having found it isn't set, you allocate this non-existant variable value to $_SESSION['category'].
-
Come back if you get stuck.
-
I didn't give you any code. I told you to use json_decode() on the results. What I gave you was the output you will get after using json_decode();
-
use json_decode( ) on the returned results to get an array like Array ( [everearn] => Array ( [usd] => 1.868E-5 [usd_market_cap] => 0 [usd_24h_vol] => 839.09151161664 [usd_24h_change] => 1.5959917379693 ) ) then you can pick off the values you want with their keys.
-
Someone has wanted the net_unit_cost and net_unit_price stored in the records. If, as you said, you subtract the 10 and the 1 from the quantities in the purchase records, how will you know which sales were sold from each purchase batch. When the sales department wants a report showing the profit on each sale, how do you intend producing it? The answer is to do the processing as part of the sales input process and add a "purchase_id" column to the sales. When you decide 10 are sold from purchase record #1, write a sales record with qty = 10 and prchase_id = 1. Then write another sales record with qty = 1 and purchase_id = 2. Now you know from which batch of purchases each sale was made. And no need to update the purchase records to reduce the quantities. +---------------------+ +---------------------+ | purchase | | sale | +---------------------+ +---------------------+ | purchase_id |-------+ | sale_id | | product_id | | | product_id | | qty | | | qty | | net_unit_cost | | | net_unit_price | | created_at | +-------<| purchase_id | +---------------------+ | created_at | +---------------------+ To get the available quantities for the next sale (from each purchase, what was sold?) SELECT p.purchase_id , p.qty - coalesce(s.qty, 0) as qty FROM purchase p LEFT JOIN ( SELECT purchase_id , sum(qty) as qty FROM sale GROUP BY purchase_id ) s ON p.purchase_id = s.purchase_id WHERE p.product_id = 1 AND p.qty - coalesce(s.qty, 0) > 0 ORDER BY created_at; For today's sales (for each sale, what batch was it from?) SELECT s.product_id , s.qty , p.net_unit_cost , s.net_unit_price , s.net_unit_price - p.net_unit_cost as net_unit_profit , s.qty * (s.net_unit_price - p.net_unit_cost) as profit , s.created_at as date_sold FROM sale s JOIN purchase p USING (purchase_id) WHERE s.created_at = CURDATE() ORDER BY product_id; The process for determining how many from each purchase batch is simple maths. foreach purchase record how many of the sales qty can I sell from this record? write sales record for that qty with purchase id reduce sales qty by that amount end for each
-
Try function getBeritsCandies(array $candies): array { $quota = floor(count($candies)/2); // Berit's share $k = array_count_values($candies); $berit = []; arsort($k); // start with ones we have most of foreach ($k as $t => &$n) { if ($n > 1 ) { // if we have multiple, Berit can can have all but 1 $m = $n - 1; // until she has her quota for ($i=0; $i<$m; $i++) { if (count($berit) == $quota) break; $berit[] = $t; --$n; } } elseif (count($berit) < $quota) { $berit[] = $t; --$n; } } return $berit; } Results Berits candies: 1, 2 Berits candies: 1, 2 Berits candies: 1, 2, 5, 3 Berits candies: 1, 1, 1, 5, 5
-
I don't see array_unique() anywhere - what is your current code?
-
if (!$stmt->execute(['fname']=>$fname)) X if (!$stmt->execute(['fname'=>$fname])) ok Compare those two and spot the difference.
-
Because you can't see far enough.
-
Yes, but his is a "we'll help you with your code" forum, not a "we'll write it and do your job for you" forum.
-
What have you tried so far?
-
They are both the same date so why not take all 11 items from the one with 20 in stock? FIFO hardly applies in your example.
-
That's what I would advise. Forget mysqli exists - PDO is a much simpler interface to use.
-
You have created a dataase connection called "$link" but you are using one called "$pdo" However just changing $pdo to $link won't work as your statement syntax and execute call are PDO only.
-
Effectively replace the old mysql_result without drastic changes.
Barand replied to samet5's topic in PHP Coding Help
Replace with $row = $result->fetch_assoc(); return $row['time']; That second piece of code is beyond help with that query. -
Unable to get two PHP_SELF working on the same page
Barand replied to anandi's topic in PHP Coding Help
Have a look at the page source and see if the userid value is there. You may need either <?= $userid ?> or <?php echo $userid ?> Also, you don't need those PHP_SELFs. Jus omit the action attribute completely from the form tag. (The default action is "self") -
You should ensure they are not undefined before attempting to use them. In the case of $_SESSION, call session_start() at the head of any script requiring $_SESSION. In the case of $_POST, check if data was posted to the script if ($_SERVER['REQUEST_METHOD'] == 'POST' ) { // safe to use $_POST here }
-
Variables inside single quotes are treated as string literals.Try $opendb = NEW PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
-
You are missing a closing quote in line 28. Look at the text colors in your posted code.