Jump to content

Barand

Moderators
  • Posts

    24,337
  • Joined

  • Last visited

  • Days Won

    795

Everything posted by Barand

  1. Two functions you might find useful: file() array_rand() or shuffle()
  2. Quite probably. You messed up the syntax.
  3. Don't use "SELECT * ", specify the columns you need. Then apply aliases to differentiate between those with the same name. Use explicit join syntax. Example QUANTITY is used on stock_stockin_product and stock_product tables SELECT sip.quantity as quantity_sip , sp.quantity as quantity_sp , whatever_else FROM stock_stockin si INNER JOIN stock_stockin_product sip ON si.id=sip.stockin_id INNER JOIN stock_product sp ON sp.id=sip.product_id WHERE stock_date>='1488366000' AND stock_date<='1488538800' AND stock_product.brand_id='11' AND stock_product.category_id='27' AND stock_product.model LIKE '%iphone 6%' AND stock_stockin.branch LIKE '%henderson%' GROUP BY si.id
  4. No. One query to get the stored password hash for the given username. Then verify the given password against that.
  5. Your join syntax is wrong. SELECT cat_name FROM domeniu_activitate d INNER JOIN user_pers_juridica u ON d.cat_id = u.cat_id WHERE product_id = '$id' It is also better to use prepared queries. You should not be putting data ($id) directly into your queries.
  6. CREATE TABLE `status_log` ( `status_log_id` int(11) NOT NULL AUTO_INCREMENT, `item_id` int(11) DEFAULT NULL COMMENT 'id of item owning the status', `status` tinyint(4) DEFAULT NULL, `changed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, PRIMARY KEY (`status_log_id`) ) ; When the status changes, add a new record mysql> select * from status_log; +---------------+---------+--------+---------------------+ | status_log_id | item_id | status | changed | +---------------+---------+--------+---------------------+ | 1 | 1 | 1 | 2017-02-28 15:03:00 | +---------------+---------+--------+---------------------+ -- add new record mysql> INSERT INTO status_log (item_id, status) VALUES (1,2); -- now you have mysql> select * from status_log; +---------------+---------+--------+---------------------+ | status_log_id | item_id | status | changed | +---------------+---------+--------+---------------------+ | 1 | 1 | 1 | 2017-02-28 15:03:00 | | 2 | 1 | 2 | 2017-03-05 21:08:43 | +---------------+---------+--------+---------------------+
  7. A column defined as type TIMESTAMP can be configured to automatically record the current time when a ) the record is inserted, or b ) the record is updated You want the former so set its default value to CURRENT_TIMESTAMP
  8. 1 ) Not able to do what? 2 ) When you have a few more details to add, start you own topic and do not hijack someone else's.
  9. Please use code tags, or use the <> button in the toolbar, for your code.
  10. try if ( is_numeric($BowlerAverage) && $BowlerAverage > 0 && $BowlerAverage <= 300 )
  11. No, you are still checking if a boolean expression is numeric.
  12. Quite true. If I used the original unsortable date formats ... $data = array( array('percentage' => '25', 'beforedate' => '10-12-2016' ), array('percentage' => '15', 'beforedate' => '31-03-2017' ), array('percentage' => '10', 'beforedate' => '30-04-2017' ), array('percentage' => '20', 'beforedate' => '31-01-2017' ), ); ...the result is 10% as the result of sorting those dates is 10-12-2016 30-04-2017 31-01-2017 31-03-2017
  13. No matter what value have for the bowler average, your test will always fail. The expression ($bowleraverage >= 0) is Boolean and therefore not numeric. EG $bowleraverage = -1; echo (is_numeric($bowleraverage >= 0)) ? 'OK' : 'Error' . '<br>'; $bowleraverage = 0; echo (is_numeric($bowleraverage >= 0)) ? 'OK' : 'Error' . '<br>'; $bowleraverage = 50; echo (is_numeric($bowleraverage >= 0)) ? 'OK' : 'Error' . '<br>'; That code outputs Error Error Error You need to separate the is_numeric() check from the value checks as ginerjm said.
  14. Alternative solution mysql> SELECT * FROM bookingdates; +-----------------+------------+------------+ | bookingdates_id | beforedate | percentage | +-----------------+------------+------------+ | 1 | 2017-12-10 | 25 | | 2 | 2017-01-31 | 20 | | 3 | 2017-03-31 | 15 | | 4 | 2017-04-30 | 10 | +-----------------+------------+------------+ SELECT percentage FROM bookingdates WHERE beforedate = ( SELECT MIN(beforedate) FROM bookingdates WHERE beforedate >= CURDATE() ); +------------+ | percentage | +------------+ | 15 | +------------+
  15. You need to sort the array into ascending date order. Then loop through the array until you come to a date that is >= today. This is the percent that you want so you can now break out of the loop. Given the data you posted (but correcting the date format) you would have $data = array( array('percentage' => '25', 'beforedate' => '2016-12-10' ), array('percentage' => '15', 'beforedate' => '2017-03-31' ), array('percentage' => '10', 'beforedate' => '2017-04-30' ), array('percentage' => '20', 'beforedate' => '2017-01-31' ) ); // SORT BY DATE usort ($data, function($a, $b) { return strcmp($a['beforedate'], $b['beforedate']); }); // VIEW RESULTS $today = new DateTime(); $today->setTime(0,0,0); // don't want the time portion foreach ($data as $rec) { if ($today <= new DateTime($rec['beforedate'])) { $discount = $rec['percentage']; break; } } echo "Applicable discount today is {$discount}%"; //--> 15%
  16. We don't know what your input values are. We don't know what you are expecting from those values. We don't know what "not working" means. You might as well try "Alexa! What is the page value?"
  17. Firstly, you need to change those dates - they are not sortable. You need yyyy-mm-dd
  18. see http://uk1.php.net/manual/en/function.natsort.php
  19. I tried helping you with advice on writing a custom sort function and how it should return values, but you chose to totally ignore it. Therefore I am not inclined to waste any more of my time.
  20. Post your current code and I'll try to run it.
  21. see https://forums.phpfreaks.com/topic/303305-pdo-looping/?p=1543471&do=findComment&comment=1543471
  22. The times when you might want similar to that is when you want to specify the array indexes For example if ($stmt->execute()) { while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $products[ $row['user_id'] ] = $row; } } or to group results if ($stmt->execute()) { while ($row = $stmt->fetch(PDO::FETCH_ASSOC)) { $products[ $row['cat_id'] ][] = $row; } }
  23. If, say, $_POST['sourcename'] is a string and not an array then $_POST['sourcename'][$i] with be the $ith character of the string and not the $ith element of an array.
×
×
  • 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.