-
Posts
24,602 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
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');
-
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
-
Selecting elements from multidimensional array
Barand replied to Turgeon_P's topic in PHP Coding Help
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 -
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
-
this worked ok for me $x= ' '; if (empty(trim($x))) { echo 'empty'; }
-
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.
-
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?
-
try if(empty(trim($_POST['formName'])))
-
Take a VB script, add a few $ prefixed variables. Yes, that'll do it
-
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)
-
Mysql column to array with batches what am I doing wrong?
Barand replied to cobusbo's topic in PHP Coding Help
LOL join is exactly the same function as implode() -
Stacking function within ternary initial expression
Barand replied to rwhite35's topic in PHP Coding Help
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. -
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 | +-----------+---------+-------+
-
Mysql column to array with batches what am I doing wrong?
Barand replied to cobusbo's topic in PHP Coding Help
jcbones, check out array_chunk cobusbo, Shouldn't you be sending $list in the send__message and not $batches -
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
-
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?
-
What are you table structures. SELECT * obscures everything as well as being inefficient
-
In that case you need ... GROUP BY site_id
-
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.
-
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'
-
how to handle errors in mysqli prepared statements efficiently
Barand replied to ajoo's topic in PHP Coding Help
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 } -
how to handle errors in mysqli prepared statements efficiently
Barand replied to ajoo's topic in PHP Coding Help
In production you would turn off error display and turn on error logging instead. -
Use SQL function SUM(). Can't tell you much more from what you've given us.
-
how to handle errors in mysqli prepared statements efficiently
Barand replied to ajoo's topic in PHP Coding Help
Is the concept of "testing" alien to you?