-
Posts
24,429 -
Joined
-
Last visited
-
Days Won
807
Posts posted by Barand
-
-
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)?
-
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.
-
10 minutes ago, narutofan said:
i'm using the foreach loop's incrementing feature
What incrementing feature?
-
Please use the "code" icon for code, not the "quote"
-
Then tell us what the code you posted is supposed to do.
-
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.
-
Why don't you simplify things and rotate and compress in one single operation?
-
On 12/20/2019 at 9:37 PM, benanamen said:
Based on OP's code, he expects there could be a negative int, otherwise he wouldn't be checking for it.
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.
- 1
-
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 | +------+----------+----------+---------------+
- 1
-
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.
13 minutes ago, Heartstrings said:that SELECT statement is giving me null
Where? You're not giving many clues if you want help.
-
26 minutes ago, Barand said:
It would help to see what your db data looks like
-
Just now, Heartstrings said:
It would help to see what your db data looks like
-
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;
- 1
-
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
4 hours ago, Saggi said:Need help in solving this task using PHP built in function : array_reverse() and without it.
-
On 12/22/2019 at 9:15 AM, Fratozzi said:
$sql_2_2 = "UPDATE analytics SET " . "visitor_visitor_sessions" . "='" . $analytics["visitor_visitor_sessions"] . "' WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "'";
$sql_2_3 = "UPDATE analytics SET " . "visitor_visitor_pageviews" . "='" . $analytics["visitor_visitor_pageviews"] . "' WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "'";
$sql_2_4 = "UPDATE analytics SET " . "visitor_visitor_pages" . "='" . $analytics["visitor_visitor_pages"] . "' WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "'";
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 ]);
- 1
-
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.
5 hours ago, Fratozzi said:$sql_1_1 = "UPDATE analytics SET " . "visitor_visitor_last_page" . "='" . "" . "' WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "'";
$sql_1_2 = "UPDATE analytics SET " . "visitor_session_last_page" . "='" . "" . "' WHERE " . "visitor_session_id" . "='" . $visitor_session_id . "'";$sql_1 = $sql_1_1."; ".$sql_1_2.";";
$this->_db->exec($sql_1);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).
5 hours ago, Fratozzi said:$sql_2_2 = "UPDATE analytics SET " . "visitor_visitor_sessions" . "='" . $analytics["visitor_visitor_sessions"] . "' WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "'";
$sql_2_3 = "UPDATE analytics SET " . "visitor_visitor_pageviews" . "='" . $analytics["visitor_visitor_pageviews"] . "' WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "'";
$sql_2_4 = "UPDATE analytics SET " . "visitor_visitor_pages" . "='" . $analytics["visitor_visitor_pages"] . "' WHERE " . "visitor_visitor_id" . "='" . $visitor_visitor_id . "'";
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.
-
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); } }
- 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
Not able to increment in foreach loop to get the values of an array
in PHP Coding Help
Posted · Edited by Barand
As I obviously cannot run the script to see for myself, perhaps you would be kind enough to give me an example of the data being passed.
My main concern is the structure of your code. You are running a query to get an array of ids and then looping through that resulting array to run queries based on those ids.
Running queries within loops is extremely inefficient. You should be running a single query which joins the tables on those ids to get the data you require.