-
Posts
24,604 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
Not able to increment in foreach loop to get the values of an array
Barand replied to narutofan's topic in PHP Coding Help
OK, so ff() returns an array of the user's friend ids. The next uncommented line is foreach ($update_id1 as $i => $v) { What does $update__id1 contain (there doesn't appear to be a prior reference)? -
Not able to increment in foreach loop to get the values of an array
Barand replied to narutofan's topic in PHP Coding Help
in the code foreach ($array as $i => $v) $i = index of the current element $v = value of the current element You use a function ff() as in $ids= ff($f, $project); but I can't see it defined anywhere. What does it do? Then I'll have some idea of what the data in $ids looks like. -
Not able to increment in foreach loop to get the values of an array
Barand replied to narutofan's topic in PHP Coding Help
What incrementing feature? -
Not able to increment in foreach loop to get the values of an array
Barand replied to narutofan's topic in PHP Coding Help
Please use the "code" icon for code, not the "quote" -
Not able to increment in foreach loop to get the values of an array
Barand replied to narutofan's topic in PHP Coding Help
Then tell us what the code you posted is supposed to do. -
Not able to increment in foreach loop to get the values of an array
Barand replied to narutofan's topic in PHP Coding Help
Why don't you post your actual code (that code won't execute past the first line) and tell us what you are trying to achieve, not just how you are failing to do whatever it is. -
You also need to output the value into the html from php <FORM METHOD="POST" ACTION="SCAction.php/?cmd= set&var1=<?=$SC2?>">
-
The values in the forms input fields get sent to the action php file, so put it in one. Use a hidden field if you don't want it visible.
-
New problem. All images from iphone rotate when I upload them.
Barand replied to imgrooot's topic in PHP Coding Help
Why don't you simplify things and rotate and compress in one single operation? -
He's testing for 0 or 1. 0! and 1! both equate to 1, so no need to calculate any further. Every recursive function needs a stop condition otherwise you quickly overflow the stack with an infinite recursion.
-
I was assuming that a report_filed meant they attended. But, yes, you could mysql> SELECT weekofyear(start_time) as wkno -> , SUM(is_no_show=0 AND is_cancelled=0) as attended -> , SUM(is_no_show=1) as no_shows -> , SUM(is_cancelled=1) as cancellations -> FROM heartstring -> GROUP BY wkno; +------+----------+----------+---------------+ | wkno | attended | no_shows | cancellations | +------+----------+----------+---------------+ | 40 | 2 | 0 | 0 | | 41 | 0 | 1 | 1 | | 42 | 1 | 0 | 0 | | 43 | 0 | 1 | 0 | +------+----------+----------+---------------+
-
Weird! When I ran this based on https://imgur.com/a/kYwmuO1 I got +------+----------+----------+---------------+ | wkno | attended | no_shows | cancellations | +------+----------+----------+---------------+ | 40 | 2 | 0 | 0 | | 41 | 0 | 1 | 1 | | 42 | 1 | 0 | 0 | | 43 | 0 | 1 | 0 | +------+----------+----------+---------------+
-
Oh great! I love pictures. Where? You're not giving many clues if you want help.
-
It would help to see what your db data looks like EG, is it +------------+-----------+-----------+----------+ | start_time | no_shows | cancelled | attended | +------------+-----------+-----------+----------+ | 2019-12-20 | 1 | 0 | 0 | | 2019-12-21 | 0 | 0 | 1 | | 2019-12-22 | 0 | 1 | 0 | If so, then SELECT weekofyear(start_time) as weekno , SUM(no_shows = 1) as no_shows , SUM(cancelled = 1) as cancelled , SUM(attended = 1) as attended FROM mytable WHERE start_time BETWEEN ? AND ? GROUP BY weekno;
-
So you can do it the easy way. What about the solutions not using array_reverse?
-
Very good! But the question explicitly wanted to do it without array_reverse
-
becomes... $sql_2_2 = "UPDATE analytics SET visitor_visitor_sessions = ?, visitor_visitor_pageviews = ?, visitor_visitor_pages = ? WHERE visitor_visitor_id = ? "; $stmt = $this->db->prepare($sql_2_2); $stmt->execute( [ $analytics['visitor_visitor_sessions'], $analytics['visitor_visitor_pageviews'], $analytics['visitor_visitor_pages'], $visitor_visitor_id ]);
-
The first impression I get when I see a table definition like that is "Spreadsheet!". Relation database tables are not spreadsheets and require data normalization. Do not store derived data (Year, Month, Day, Weekday, Hour are all derived from the datetime) Do not use "SELECT *". Specify the required columns. That doesn't work, only the $sql_1_1 query will be executed (thankfully as it would open up a whole new vista of SQL injection possibilities). You can update more than one column in an update query, you don't need a separate one for each. Use prepared queries, do not insert data values directly into query strings.
-
HINT: try using array_pop() and build a new array or, method 2, sort the array keys in reverse order
-
Yep, more than one way to skin a cat.
-
ctype_digit() function fact ($x) { if (!ctype_digit("$x") ) { // CAVEAT: cast $x to string type return 'Please provide an integer'; } if($x <= 1) { return 1; } else { return $x * fact($x - 1); } }
-
The code I used gives that format mysql> SELECT CASE WHEN FINISHED = 0 -> THEN '' -> ELSE DATE_FORMAT(FINISHED, '%d %M %Y') -> END as FINISHED -> FROM games -> ORDER BY FINISHED DESC -> LIMIT 5; +------------------+ | FINISHED | +------------------+ | 31 October 2016 | | 31 December 2016 | | 29 October 2018 | | 29 June 2019 | | 29 January 2017 | +------------------+ For future consistency of content you should EITHER ALTER TABLE `games` CHANGE COLUMN `FINISHED` `FINISHED` DATE NOT NULL DEFAULT '0000-00-00' ; to prevent new records having the date set to NULL OR Change those "0000-00-00" dates back to NULL