Skip to content

Instantly share code, notes, and snippets.

@nklatt
nklatt / MySQL copy rows with tweaks
Created August 29, 2022 21:52
PHP code that generates a MySQL query to copy rows from a table to the same table but with some column values changed.
$table = 'some_table';
$columns = implode(',', array(
'title',
'description',
'etc...',
));
$sql = '
INSERT INTO '.$some_table.' (product_id, '.$columns.')
SELECT "'.$destId.'", '.$columns.'
FROM '.$some_table.' WHERE product_id = "'.$origId->id.'"
@nklatt
nklatt / 0 Laravel Backpack CRUD entry list filtering based on related rows
Last active June 16, 2023 21:50
Laravel Backpack CRUD entry list filtering based on related rows
Site allows members (people) to register for programs. People belong to one or
more Accounts. Programs are divided up into Seasons.
When viewing the entity list page for Accounts, we want to be able to filter the
list based on the seasons the people within each account are registered for.
E.g., we often want to show only Accounts which have People registered for
Programs within the current Season.
Pertinent database tables and columns:
accounts: id
@nklatt
nklatt / dimension-input.html
Last active February 6, 2024 16:22
HTML/JS regex pattern to match one of: whole number, float, fraction or whole number <space> fraction
<input pattern="/^(?:(\d+\/[1-9]\d*)|(\d*(?:(\s\d+\/[1-9]\d*)|\.\d+)?))$/">
<!--
(?: => non-capturing group, EITHER
(\d+\/[1-9]\d*) => any number of digits followed by a slash then any number of digits not beginning with 0 (fraction)
| => OR
(\d*(?: => zero or more digits followed by non-capturing group, EITHER
(
\s => a space
\d+ => any number of digits
\/ => a slash