-
Posts
24,603 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
You could put them all in a single ini file EG contacts.ini ;; ;; constants definitions ;; [contactstate] 0 = Unactioned 1 = Actioned [contacttype] 1 = Query 2 = Suggestion 3 = Compliment code $constants = parse_ini_file('constants.ini', 1); echo $constants['contactstate'][1]; // Actioned echo $constants['contacttype'][3]; // Compliment You can use that ini file to create dropdown menu options too. Something that is a PITA with enum values/meanings. If you are using a database, put each of those ini sections in separate tables instead of the ini file method.
-
Don't worry about my suggestion not working - you shouldn't ever have a table designed like that. It should look like this, one value per row... userid | feed_id | attr_id | attr_value What does the CSV data look like?
-
Check your server's date/time settings. Looks like your default timezone is "Europe/Paris" or somewhere along that longitude. If you don't have control over the server settings then check your cPanel options for timezone settings. Failing that, set a default in your db connection procedure.
-
Your insert query needs to look like this INSERT INTO stock (userid, feed_id, c0, c1, c2, c3, c4, c5, c6, c7, c8, c9, c10) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) Your values to be inserted would be NULL (if not required) or the desired csv value. Also, do not prepare and bind i every iteration of the loop. Do those before the loop. Inside the loop you should just update the variables and execute.
-
What does this query give? SELECT @@session.time_zone as tzone, TIMEDIFF(NOW(), UTC_TIMESTAMP) as tdiff; As a fellow Brit I would expect to see ... +--------+----------+ | tzone | tdiff | +--------+----------+ | SYSTEM | 01:00:00 | +--------+----------+ ... meaning it is using your servers system time settings and currently British Summer Time
-
Your Norwegian characters worked for me... CREATE TABLE `user` ( `id` int(11) NOT NULL AUTO_INCREMENT, `firstname` varchar(20) DEFAULT NULL, `lastname` varchar(20) DEFAULT NULL, `user_name` varchar(30) DEFAULT NULL, `password` varchar(150) DEFAULT NULL, PRIMARY KEY (`id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; $pwd = 'Ææ, Øø, Åå'; // HASH AND STORE THE PASSWORD $stmt = $pdo->prepare("update user set password = ? where id = 2"); $stmt->execute([ password_hash($pwd, PASSWORD_DEFAULT) ]); // NOW CHECK THE PASSWORD STORED OK $res = $pdo->query("select password from user where id = 2"); $hash = $res->fetchColumn(); echo password_verify($pwd, $hash) ? 'VALID' : 'Oops!'; //==> VALID
-
Do your database , table and db connection all share the same utf8 encoding?
-
Why? Any keyboard characters, be they alphanumeric or spaces or punctuation, should be permitted (and encouraged) in passwords.
-
Ajax log on handler wrapping redirected to page in response content
Barand replied to Adamhumbug's topic in Javascript Help
When you send an ajax request to a page, all output then goes into the response that is returned. (ie what you would see if you called that page in your browser is the reponse (which you can use to your advantage to test ajax responders). Remove the location header from the responder code and do the redirect in the calling page when you receive a succesful response. -
Calculating "time since" is giving me a negative (CLOSEME)
Barand replied to Adamhumbug's topic in PHP Coding Help
Suggestions: 1. function timeDifference($datetime) { $periods = ['yrs', 'mths', 'days', 'hrs', 'mins', 'secs']; $dt1 = new DateTime($datetime); $dt2 = new DateTime(); $d = $dt1->diff($dt2); $diffs = array_filter(array_combine($periods, [ $d->y, $d->m, $d->d, $d->h, $d->i, $d->s ] )); $res = $d->invert ? '-' : ''; foreach ($diffs as $k => $v) { $res .= "$v $k "; } return $res; } echo "Now: " . date('Y-m-d H:i:s') . '<br>'; // Now: 2023-09-04 18:54:22 echo timeDifference('2023-09-04 19:00:00.000000'); // -5 mins 37 secs 2. You can also utilise SQL functions SELECT now() as Now , timestampdiff(SECOND, now(), '2023-09-04 19:00:00.000000') as Diff; +---------------------+------+ | Now | Diff | +---------------------+------+ | 2023-09-04 19:03:34 | -214 | +---------------------+------+ SELECT now() as Now , timediff('2023-09-04 19:00:00.000000', now()) as diff; +---------------------+------------------+ | Now | diff | +---------------------+------------------+ | 2023-09-04 19:08:39 | -00:08:39.000000 | +---------------------+------------------+ -
password_hash() and password_verify()
-
Duplicating Mysql Table rows but also updating some content
Barand replied to Adamhumbug's topic in PHP Coding Help
example... $client = 15; $res = $pdo->prepare("SELECT q.id , q.version FROM quote q JOIN ( SELECT client_id , max(version) as version FROM quote WHERE client_id = ? ) latest USING (client_id, version) "); $res->execute([ $client ]); list($quote, $version) = $res->fetch(PDO::FETCH_NUM); if ($quote) { try { $pdo->beginTransaction(); $stmt = $pdo->prepare("INSERT INTO quote (client_id, total_value, job_id, version, name, currency, kit_delivery, kit_return, quote_status_id) SELECT client_id, total_value, job_id, ?, name, currency, kit_delivery, kit_return, quote_status_id FROM quote WHERE id = ? "); $stmt->execute([ ++$version, $quote ]); $newquote = $pdo->lastInsertId(); $stmt = $pdo->exec("INSERT INTO quote_items (quote_id, item_id, quantity, start_date, end_date, notes, amount_charged_each, original_price_each, chargable_units) SELECT $newquote, item_id, quantity, start_date, end_date, notes, amount_charged_each, original_price_each, chargable_units FROM quote_items WHERE quote_id = $quote "); $pdo->commit(); } catch (PDOException $e) { $pdo->rollBack(); throw $e; } } else { echo "Client quotes not found"; } -
short the data on multiple line to single line
Barand replied to Senthilkumar's topic in Microsoft SQL - MSSQL
Check your SQL reference manual for correct syntax (I'm used to mysql - I haven't used MSSQL since 2010) although I wouldn't be surprised if MSSQL's pathetic function library doesn't contain it. It's fairly simple to do it in PHP though. Create an array of names for each number the join() them. PS Looks like the mssql equivalent is STRING_AGG() -
Ajax appended table colour change based on the conditon
Barand replied to Senthilkumar's topic in Javascript Help
Then your data is not the same as mine. The data you posted had a "Month" key. -
short the data on multiple line to single line
Barand replied to Senthilkumar's topic in Microsoft SQL - MSSQL
Use GROUP_CONCAT(M.Name SEPARATOR ', ') as name and GROUP BY P.Number -
Duplicating Mysql Table rows but also updating some content
Barand replied to Adamhumbug's topic in PHP Coding Help
Start with SELECT q.id , q.version FROM quote q JOIN ( SELECT client_id , max(version) as version FROM quote WHERE client_id = 15 ) latest USING (client_id, version); +----+---------+ | id | version | +----+---------+ | 71 | 6 | +----+---------+ Now you know that for client #15 the latest quote has id = 71 and its version is 6. Duplicate quote #71, giving the dupe a verion of 7, and duplicate the items for #71 with the quote_id of the new duped quote. -
You beat me to it.
-
You can't embed a function call in a string. You need to concatenate EG echo "Today is " . date('l'); not echo "Today is date('l')";
-
When you view the page source, what have you got where you expect the options of the select?
-
It's useful if you give us something we can test with. The less time we have to spend on your problem, the more chance there is of a good response. We aren't paid by the hour! Ideally, a data export dump of the relevant tables with test data so it can be reloaded at our end and the query tested. That way we can see your results and problem first hand. As with code, pictures of data are as much use as a chocolate teapot.
-
Do you have any data with j.id = 15? There aren't any in the useless pictures of your data.
-
Do not double-post topics. Post in the correct forum (Moving this from Introductions to Javascript forum)
-
Everything echo'd in response to a fetch or ajax request goes into the response that is returned to your handler function. They do not go to the screen for you to read. Use your browser developer tools network tab to view the response.
-
Something like this? ... SELECT j.id as job_id , j.name , count(q.id) as quotes FROM job j LEFT JOIN quote q ON j.id = q.job_id GROUP BY j.id
-
Ajax appended table colour change based on the conditon
Barand replied to Senthilkumar's topic in Javascript Help
What don't you understand? I commented it for you.