-
Posts
24,607 -
Joined
-
Last visited
-
Days Won
831
Everything posted by Barand
-
Instead of value='<?= htmlentities($post['JardinConseil'],ENT_QUOTES) ?? ''?>' ^ ^ try value="<?= htmlentities($post['JardinConseil'],ENT_QUOTES) ?? ''?>" ^ ^
-
DO I need foreach for accessing specific array data here?
Barand replied to Rascalsailor's topic in PHP Coding Help
Of course you can. foreach() is for iterating through all elements in an array. In this case you don't want to do that. $arr = json_decode($jsn, 1); $elem = $arr['identifiers'][0]['device_ids']; echo $elem['application_ids']['application_id'] . '<br>'; echo $elem['dev_eui'] . '<br>'; echo $elem['device_id'] . '<br>'; However, are you certain that the "identifiers" array will only have a single element? If the number is unknown, use foreach()... $arr = json_decode($jsn, 1); foreach ( $arr['identifiers'] as $ids ) { $elem = $ids['device_ids']; echo $elem['application_ids']['application_id'] . '<br>'; echo $elem['dev_eui'] . '<br>'; echo $elem['device_id'] . '<br>'; } -
+ "the matching row of data never existed" Not getting a matching row is not a database error - in fact it may often be the desired result.
-
Selecting from duplicate values but wanting the max
Barand replied to mongoose00318's topic in MySQL Help
mysql> select * from production_data_archive; +----+----------+------------+-----------+---------------------+ | id | order_id | job_number | line_item | insert_time | +----+----------+------------+-----------+---------------------+ | 1 | 16824 | 22000412 | A | 2021-03-26 00:00:00 | | 2 | 16824 | 22000412 | A | 2021-03-30 00:00:00 | | 3 | 16824 | 22000412 | A | 2021-04-09 00:00:00 | | 4 | 16825 | 22000412 | B | 2021-03-26 00:00:00 | | 5 | 16825 | 22000412 | B | 2021-03-29 00:00:00 | | 6 | 16825 | 22000412 | B | 2021-04-06 00:00:00 | | 7 | 16825 | 22000413 | C | 2021-03-26 00:00:00 | | 8 | 16825 | 22000413 | C | 2021-03-29 00:00:00 | | 9 | 16825 | 22000413 | C | 2021-05-06 00:00:00 | | 10 | 16825 | 22000414 | C | 2021-03-26 00:00:00 | | 11 | 16825 | 22000414 | C | 2021-03-29 00:00:00 | | 12 | 16825 | 22000414 | C | 2021-05-06 00:00:00 | +----+----------+------------+-----------+---------------------+ 12 rows in set (0.00 sec) mysql> SELECT a.id -> , a.order_id -> , a.job_number -> , a.line_item -> , a.insert_time -> FROM production_data_archive a -> JOIN ( -> SELECT job_number -> FROM production_data_archive -> GROUP BY job_number -> HAVING count(distinct line_item) = 1 -> ) nodupe USING (job_number) -> LEFT JOIN -> production_data_archive b -> ON a.job_number = b.job_number -> AND a.line_item = b.line_item -> AND a.insert_time < b.insert_time -> WHERE b.job_number IS NULL; +----+----------+------------+-----------+---------------------+ | id | order_id | job_number | line_item | insert_time | +----+----------+------------+-----------+---------------------+ | 9 | 16825 | 22000413 | C | 2021-05-06 00:00:00 | | 12 | 16825 | 22000414 | C | 2021-05-06 00:00:00 | +----+----------+------------+-----------+---------------------+ 2 rows in set (0.03 sec) -
Unable to copy table data from one database to another
Barand replied to wongle's topic in PHP Coding Help
If the two tables have the same structure REPLACE INTO db2.tablename SELECT * FROM db1.tablename WHERE id = 223; -
Unable to copy table data from one database to another
Barand replied to wongle's topic in PHP Coding Help
I'd take out the try..catch stuff and let php report any errors with a meaningful message. I can't see the problem off-hand but it does seem evident that the term "data normalization" is foreign to you. That is a spreadsheet, not a relational db table. -
how to validate a date based on user input from a form
Barand replied to webdeveloper123's topic in PHP Coding Help
No. It is the expected input format that is being defined here. Consider changing the function thus function check_date($input, $format='m/d/Y') { $date = DateTime::createFromFormat($format, $input); return ($date && $date->format($format) === $input) ? $date->format('Y-m-d') : false; } It then returns "false" if the date is invalid but returns the date in Y-m-d format if valid. -
What would you want this function to do? Why "different forms"?
-
Here's an alternative using PHP to do to the date arithmetic <?php // create pdo connection here $date = $_GET['date'] ?? date('Y-m-d'); // date defaults to today if no input $days = $_GET['days'] ?? 0; // days defaults to 0 $dt = new DateTime($date); $newdate = $dt->modify("$days days")->format('Y-m-d'); $disabled = $newdate == date('Y-m-d') ? 'disabled' : ''; // if today, disable tomorrow button $res = $pdo->prepare("SELECT * FROM cercles WHERE dates = ? "); $res->execute([$newdate]); ?> <!doctype html> <html> <head> <title>Sample</title> <style type="text/css"> </style> </head> <body> <form> <button name='days' value='-1'><</button> <input type='date' name='date' value='<?=$newdate?>' > <button name='days' value='1' <?=$disabled?> >></button> </form> <table> <?php // output your data rows here ?> </table> </body> </html>
-
how to validate a date based on user input from a form
Barand replied to webdeveloper123's topic in PHP Coding Help
Adapt @kicken's code function check_date($input, $format='m/d/Y') { $date = DateTime::createFromFormat($format, $input); return ($date && $date->format($format) === $input); } if (!check_date($input) ) { $error['date'] = 'Invalid date'; } -
That is your main problem - or it will be. Database dates in that format are totally useless. Always store dates in Y-m-d format. Such dates can be sorted/compared and can be used by the inbuilt datetime function. To get today's data... SELECT * FROM cercles WHERE dates = curdate() To get yesterday's... SELECT * FROM cercles WHERE dates = curdate() - interval 1 day The above will not work with your d/m/Y dates.
-
I suspect (as I implied above) that it's because it is repeatedly receiving the same query. With the time condition it changes.
-
try adding a creation timestamp to the instruction records then query select created_time, instruction ... where created_time > :last_time_retrieved You then have a different query each time which may prevent the caching effect. It also means you won't have to delete records enabling you to maintain a history of instructions.
-
How can I anchor to a <h1 id="title1"> tag of external url?
Barand replied to eaglehopes's topic in HTML Help
If you remove "page=", does it work? -
Are you loading it your browser with a URL in the address bar? eg http://localhost/myfile.php or are you just opening the file.
-
How can I anchor to a <h1 id="title1"> tag of external url?
Barand replied to eaglehopes's topic in HTML Help
How much success? Are you getting to the page but not the heading, or are you not even getting to the page? -
How to sum columns that is in SQL, to table that use php
Barand replied to hendrikbez's topic in PHP Coding Help
Better show your code echo 1.15 + 0.03 + 0.04 + 0.01 + 0.02; gives me 1.25 mysql> select * from a_sample; +------+------+------+------+------+ | fee1 | fee2 | fee3 | fee4 | fee5 | +------+------+------+------+------+ | 1.15 | 0.03 | 0.04 | 0.01 | 0.02 | +------+------+------+------+------+ 1 row in set (0.00 sec) mysql> select fee1 -> , fee2 -> , fee3 -> , fee4 -> , fee5 -> , fee1 + fee2 + fee3 + fee4 + fee5 as total -> from a_sample; +------+------+------+------+------+-------+ | fee1 | fee2 | fee3 | fee4 | fee5 | total | +------+------+------+------+------+-------+ | 1.15 | 0.03 | 0.04 | 0.01 | 0.02 | 1.25 | +------+------+------+------+------+-------+ 1 row in set (0.03 sec) -
How to sum columns that is in SQL, to table that use php
Barand replied to hendrikbez's topic in PHP Coding Help
SUM won't work with a dog's breakfast of a table like that one - it needs normalizing. if the table were to be normalized to table : fee +--------+-----------+---------+----------+ | id (PK)| nmc_id(FK)| seq | amount | +--------+-----------+---------+----------+ | 1 | 1 | 1 | 100 | | 2 | 1 | 2 | 75 | | 3 | 1 | 3 | 150 | | 4 | 1 | 4 | 225 | | 5 | 1 | 5 | 50 | | 6 | 2 | 1 | 125 | | 7 | 2 | 2 | 85 | | 8 | 2 | 3 | 350 | | 9 | 2 | 4 | 215 | | 10 | 2 | 5 | 125 | +--------+-----------+---------+----------+ with 5 fee records for each parent nmc record then you can use SUM() SELECT nmc_id , SUM(amount) as fees FROM fees GROUP BY nmc_id -
Simple example <?php if ($_SERVER['REQUEST_METHOD']=='POST') { $errors = []; $post = array_map('trim', $_POST); if ( strlen($post['name']) < 3 || strlen($post['name']) > 18 ) { $errors['name'] = 'Must be between 3 and 18 characters'; } if (!isset($post['confirm'])) { $errors['confirm'] = 'Box must be checked'; } if (!$errors) { // update database header("Refresh: 0"); exit; } } ?> <!doctype html> <html> <head> <title>Sample</title> <style type="text/css"> .errormsg { color : red; } </style> </head> <body> <form method='post'> Name <input type='text' name='name' value='<?=$_POST['name'] ?? ''?>' > <br><span class='errormsg'><?=$errors['name'] ?? ''?></span> <br> <input type='checkbox' name='confirm' value='1'> Click this box <br><span class='errormsg'><?=$errors['confirm'] ?? ''?></span> <br> <input type='submit'> </form> </body> </html>
-
I'm like you then if it it isn't a decimal. Perhaps some kind of vector notation, but if it is I don't know what the hell to do with it
-
We (UK) use the period but mainland europe (eg Germany) use the comma.
-
Do you want $x = 5 * M_PI**2.7 - 5 * (M_PI - 1)**2.7;
-
Most of us don't accept links from strangers. Post your problem.
-
No, you really don't want to do that - use a single query which joins the two tables on the user_id. SELECT users_username FROM users u JOIN planets p ON u.users_id = p.planets_ownerid WHERE planets_galaxy = $testowanaGalaktyka AND planets_starsystem = $testowanySystem AND planets_planet = $testowanaPlaneta";
-
You don't need the SVG. I used it to skew the container but not the text. Using just html/css you can convert to by adding transform:rotate(-45deg) skewX(45deg); to its styling. It will still need some positioning adding though.