-
Posts
24,337 -
Joined
-
Last visited
-
Days Won
795
Everything posted by Barand
-
Checking if a checkbox is checked inside a foreach loop
Barand replied to NiallAA's topic in PHP Coding Help
You have the variable inside single quotes - remove them. (The value it is looking for is the literal string $-k-e-y instead of the variable's value) -
I'd separate the time check from the day check if it is a work day if it is work hour we are open else we are closed endif else we are closed endif
-
So for it to work as it did with a separate time column, are the time elements the same in the two datetime columns? When comparing a date with a datetime column you need to use only the date portion of the datetime. So if my opening assumption is true SELECT id , schedule_start , schedule_end WHERE UTC_DATE() BETWEEN DATE(schedule_start) AND DATE(schedule_end) AND EXTRACT(HOUR_MINUTE FROM UTC_TIME()) = EXTRACT(HOUR_MINUTE FROM schedule_start)
-
Note
-
No one that understands the sanity in adding two dates.
-
Foreach () takes an array and loops through it. You have the array, $dpts, from which you created the comma-delimited string $departmento.
-
Use code tags ( <> button in toolbar) when posting code. lol
-
You are getting an error on $_REQUEST['step'] So perhaps that is is the one you should be checking with isset() ?
-
If you can't remember the manual is there to jog your memory
-
Change 'options' => array_values($category_str) to 'options' => $category_str;
-
for ($i=$y+1; $i >= $y-11; $i--)
-
There are several things in this job that can lead to insanity. One of them is accepting free-form text as input. It only takes a small spelling mistake (like your "strops" above) and the whole thing collapses like a house of cards.
-
It could be they have an ancient version of PHP that doesn't support [..] array definition syntax. To verify try array( 'id' => $_GET['id']) instead of [ 'id' => $_GET['id'] ]
-
Rerunning #3, #4, #5 is a definite no-no. You could end up with completely different set of ids. That was, as previously stated, a one-off exercise. How do you create the csv at present? How many test_db records do you typically add at a time? How often do you have new whiskies?
-
You could try reading thara's post again and use the function he gave you. edit - alternatively you can do it in PHP $dtobj = new DateTime($row['date']); echo $dtobj->format('d/m/Y'); //--> 23/01/2017, for example
-
That is what that query was designed to do - just the latest record with price and date plus the average price. When you list all the results for a whisky, what do you want to show?
-
How to check if two columns match from joined tables?
Barand replied to robatojazzo's topic in PHP Coding Help
Sorry, I forgot to change it to INNER JOIN in that last version of the query. -
How to check if two columns match from joined tables?
Barand replied to robatojazzo's topic in PHP Coding Help
There is a "Donate to me" link underneath my avatar on the left. Thanks. -
url_img and whsky_id are not in the fields selected in the query.
-
You have left the id hard coded instead of " = :id ". This version below may also be more efficient SELECT w.whisky_name , price , date , avprice FROM test_db t JOIN whisky w USING (whisky_id) JOIN ( SELECT whisky_id , AVG(price) as avprice FROM test_db WHERE whisky_id = :id GROUP BY whisky_id ) avcalc USING (whisky_id) ORDER BY date DESC LIMIT 1;
-
Then SELECT w.whisky_name , price , date , avprice FROM test_db t JOIN whisky w USING (whisky_id) JOIN ( SELECT whisky_id , AVG(price) as avprice FROM test_db GROUP BY whisky_id ) avcalc USING (whisky_id) WHERE w.whisky_id = 1 ORDER BY date DESC LIMIT 1;
-
Is the average price the only thing you want to show as a result of the query on that page?
-
In records.php, for example, if you want the whisky name then you need to join the test_db table to the whisky table SELECT whisky_id , date , whisky_name as name , price FROM test_db INNER JOIN whisky USING (whisky_id) -- required to get the name WHERE t.whisky_id = :id ORDER BY date DESC
-
How to check if two columns match from joined tables?
Barand replied to robatojazzo's topic in PHP Coding Help
Change query to SELECT rEmail , eMail , c.fullname FROM realtors r LEFT JOIN customers c ON pow(clatitude-rlatitude, 2) + pow((clongitude-rlongitude)*cos(radians(rlatitude)), 2) < pow(willtotravel/69.13, 2) ORDER BY rid, id -
If you haven't already, add an index to test_db on the whisky_id column. CREATE INDEX `idx_test_db_whisky_id` ON `test_db` (whisky_id);