Jump to content

Barand

Moderators
  • Posts

    24,602
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. You get 1938 years because you are using a unix timestamp. If you do it that way you need $dt1 = new DateTime(); $dt1->setTimestamp($expire); // SET TIMESTAMP VALUE (RTFM) $dt2=new DateTime(); // Now $dif = $dt2->diff($dt1); echo $dif->format('%y years, %m months, %d days, %h hours, %i minutes, %s seconds');
  2. 1 hour = 3600 seconds. 3600000 seconds, which you are adding, = 41 days 16 hours And there is an easier way of getting a date difference $dt1 = new DateTime('2000-01-01'); $dt2=new DateTime(); // Now $dif = $dt2->diff($dt1); echo $dif->format('%y years, %m months, %d days, %h hours, %i minutes, %s seconds'); // RESULT---> 15 years, 2 months, 2 days, 15 hours, 15 minutes, 15 seconds
  3. Given your constraints you can pick a maximum of 9 balls (5 + 2 + 1 + 1) from the four groups so shuffle the groups then pick five from the first, two from the second and one from each of the remaining two groups. Brute force method $target = 10; // max product of numbers chosen from groups $result = array(); $max = 0; // max ball count $g1 = count($balls['Group1']); $g2 = count($balls['Group2']); $g3 = count($balls['Group3']); $g4 = count($balls['Group4']); for ($a=1; $a<=$g1; $a++) { for ($b=1; $b<=$g2; $b++) { for ($c=1; $c<=$g3; $c++) { for ($d=1; $d<=$g4; $d++) { $prod = $a*$b*$c*$d; $tot = $a + $b + $c + $d; if (($prod <= $target) && ($tot > $max)) { $result = array($a,$b,$c,$d); } } } } } echo join (' + ', $result); //==> 5 + 2 + 1 + 1
  4. Numeric variables should not contain formatting characters such as commas. Same goes for values held in a db table. 4,100 is treated as 4 (only numeric digits up to the first non-numeric digit) Format the numbers on output
  5. this worked ok for me $x= ' '; if (empty(trim($x))) { echo 'empty'; }
  6. Yes, you could write a single query to do that, but why bother storing data that can be easily derived by the same query. A basic principle of db design - don't store derived data.
  7. to get that error you would be trying to assign a value to a function call EG if (trim($x)='') { So what is the real code that is giving you that error?
  8. try if(empty(trim($_POST['formName'])))
  9. Take a VB script, add a few $ prefixed variables. Yes, that'll do it
  10. Use (..) to ensure the logic you really want WHERE approved = "1" AND (item_gender="1" OR item_gender="3") otherwise the logic defaults to WHERE (approved = "1" AND item_gender="1") OR item_gender="3" Alternatively, use IN instead of multiple ORs WHERE approved = "1" AND item_gender IN (1, 3)
  11. LOL join is exactly the same function as implode()
  12. Move the "unset()" out out of the statement. It isn't trying to unset the GET variable, it is trying to unset the boolean result return by the isset() function.
  13. I am assuming you data looks something like this mysql> SELECT * FROM goal; +---------+-----------+------+-------+------+--------------+ | goal_id | season | day | month | year | goals_scored | +---------+-----------+------+-------+------+--------------+ | 1 | 2002-2003 | 1 | 8 | 2002 | 5 | | 2 | 2002-2003 | 31 | 10 | 2002 | 8 | | 3 | 2002-2003 | 1 | 11 | 2002 | 9 | | 4 | 2002-2003 | 31 | 1 | 2003 | 4 | | 5 | 2002-2003 | 1 | 2 | 2003 | 8 | | 6 | 2002-2003 | 30 | 4 | 2003 | 10 | | 7 | 2002-2003 | 1 | 5 | 2003 | 9 | | 8 | 2002-2003 | 31 | 7 | 2003 | 12 | | 9 | 2003-2004 | 10 | 8 | 2003 | 15 | | 10 | 2003-2004 | 5 | 11 | 2003 | 10 | | 11 | 2003-2004 | 1 | 7 | 2004 | 6 | +---------+-----------+------+-------+------+--------------+ Set up a second table to define which months are in each quarter mysql> SELECT * FROM quarter; +------------+---------+-------+ | quarter_id | quarter | month | +------------+---------+-------+ | 1 | Q1 | 8 | | 2 | Q1 | 9 | | 3 | Q1 | 10 | | 4 | Q2 | 11 | | 5 | Q2 | 12 | | 6 | Q2 | 1 | | 7 | Q3 | 2 | | 8 | Q3 | 3 | | 9 | Q3 | 4 | | 10 | Q4 | 5 | | 11 | Q4 | 6 | | 12 | Q4 | 7 | +------------+---------+-------+ Then you can run a query to get your quarter totals SELECT g.season , q.quarter , SUM(g.goals_scored) as goals FROM goal g INNER JOIN quarter q USING (month) GROUP BY season, quarter Giving +-----------+---------+-------+ | season | quarter | goals | +-----------+---------+-------+ | 2002-2003 | Q1 | 13 | | 2002-2003 | Q2 | 13 | | 2002-2003 | Q3 | 18 | | 2002-2003 | Q4 | 21 | | 2003-2004 | Q1 | 15 | | 2003-2004 | Q2 | 10 | | 2003-2004 | Q4 | 6 | +-----------+---------+-------+
  14. jcbones, check out array_chunk cobusbo, Shouldn't you be sending $list in the send__message and not $batches
  15. You are already inside a PHP block (shown in blue) so the red elements should not be there. You need to echo the <option> line echo "<option value='$row[0]'>$row[1] $row[2]</option>"; // assuming $row[0] is the attendee id Don't use "select * ", specify just the three columns you need
  16. Which table is which in your query? Which field identifies a site? Should you be grouping by url, perhaps? If you are joining on link_id, why is it text type in one table and int in the other?
  17. What are you table structures. SELECT * obscures everything as well as being inefficient
  18. In that case you need ... GROUP BY site_id
  19. ... and PHP's error reporting turned on to warn you when you use a variable that is undefined.
  20. The query syntax is correct but I don't believe that is what you want. COUNT(link_id) with GROUP BY link_id will give every count total = 1. But as I said, there is no way of my knowing exactly what you are trying to achieve.
  21. That single line on its own will not do what you say it does. You need to read the content into variable, increment it put the content back. It will be text but php's automatic type conversion will allow you to process it as int. What's wrong with a db table? All you need then is UPDATE mycounts SET count=count+1 WHERE button = 'A'
  22. Better to assume that if something could wrong then, at some time, it will and handle such errors gracefully in your code. if you set report_mode = MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT; then exceptions will be thrown try { $query = "SELECT Id, User, Pass, FROM $table WHERE User = ?"; $stmt = $con->prepare($query); $stmt->bind_param('s',$user); $stmt->execute(); $stmt->bind_result($db_id,$db_user,$db_pw); $stmt->fetch(); } catch (Exception $e) { // handle errors }
  23. In production you would turn off error display and turn on error logging instead.
  24. Use SQL function SUM(). Can't tell you much more from what you've given us.
  25. Is the concept of "testing" alien to you?
×
×
  • 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.