-
Posts
24,601 -
Joined
-
Last visited
-
Days Won
829
Everything posted by Barand
-
Set thumbnail to what?
-
Can someone guide what's the error in this code?
Barand replied to Cloud_Geek's topic in Other RDBMS and SQL dialects
What error is it giving? Care to share? When I run your code it outputs -
To get the records you highlighted SELECT id , tablex FROM lovetree LIMIT 9, 11; i.e. LIMIT offset, num_recs However, you probably meant LIMIT 10, 10 but I can only guess.
-
Maybe, but only if the first 10 don't exist ??? - who can tell?
-
How can that situation even be possible? @DisplayError If you tell us what you are trying to do in a clear, logical manner then we can probably help. Otherwise you're on your own.
-
It would be nice to see your solution using date_format(). Are you talking about PHP's date_format function or SQL's function?
-
Can someone guide what's the error in this code?
Barand replied to Cloud_Geek's topic in Other RDBMS and SQL dialects
What are you expecting the code to do? Why do think there is an error? -
There's a clue in the manual. TIP: try reading it occasionally, such as when you use a function and you have no idea what it does.
-
If your cUrl postfields are hard-coded with the username and password, why are you sending them from the ajax call in the POST data?
-
If we do a slightly different query SELECT pd.id , pd.enterprise , pd.as400_ship_date , pd.hold_date , ps.order_id , ps.dept_code , ps.status_id FROM production_data pd LEFT JOIN production_status ps ON ps.order_id = pd.id AND ps.dept_code = 13 AND ps.status_id = 3 WHERE pd.enterprise = "EXXON" AND pd.as400_ship_date = '2021-03-02' AND pd.hold_date = "0000-00-00"; +-------+------------+-----------------+------------+----------+-----------+-----------+ | id | enterprise | as400_ship_date | hold_date | order_id | dept_code | status_id | +-------+------------+-----------------+------------+----------+-----------+-----------+ | 15298 | EXXON | 2021-03-02 | 0000-00-00 | 15298 | 13 | 3 | | 15154 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 15156 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 15157 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 15158 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 15290 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 15291 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 15292 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 15293 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 15294 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 15296 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 15297 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 15299 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 15300 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 15301 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 15302 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 15303 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 15304 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 16589 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 16590 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 16593 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 16594 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 16597 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 16598 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 16601 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 16602 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 16605 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 16606 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 16609 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 16610 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 16613 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | | 16614 | EXXON | 2021-03-02 | 0000-00-00 | NULL | NULL | NULL | +-------+------------+-----------------+------------+----------+-----------+-----------+ 32 rows in set (0.00 sec) Becasue it uses a LEFT JOIN, we get nulls where there was no matching record meeting the join criteria. These are the ones we want to count hence the ps.order_id IS NULL
-
OK. I wanted to know if I was on the right track. SELECT pd.enterprise, COUNT(*) AS total FROM production_data pd LEFT JOIN production_status ps ON ps.order_id = pd.id AND ps.dept_code = 13 AND ps.status_id = 3 WHERE pd.enterprise = "EXXON" AND pd.as400_ship_date = '2021-03-02' AND pd.hold_date = "0000-00-00" AND ps.order_id IS NULL;
-
The query returns SELECT pd.enterprise, COUNT(*) AS total The enterprise columns are all EXXON but what should the count be? I get 31 as there are 32 records but 1 has a status where its dept_code is = 13 and it's status_id = 3, therefore excluded. Is that what you expect?
-
From that data, what are the expected results? So I know if I get it right.
-
Your query selects on as400_ship_date and hold_date. That production_data contains no date data therefore no records will be selected.
-
Are you sure? Last time I used MariaDB I had to use a LIMIT clause (with a huge number (264 - 1) to force it to write a subquery to a temp table, otherwise it wouldn't accept an ORDER BY clause. E.G. ORDER BY id LIMIT 18446744073709551615 Your query will be more efficent if you use a JOIN rather than the "NOT IN subquery". If you post a dump with test data I'll have go at rewriting it for you.
-
This would be the fastest way $local = PDO connection to database on local db server $remote = PDO connection to database on remote server // // GET DATA FROM LOCAL SERVER // $res = $local->query("SELECT user_id, user_username FROM users"); $users = []; foreach ($res as $row) { $users[] = vsprintf("(%d, '%s')", $row); } // // WRITE DATA TO REMOTE SERVER // 1,000 RECORDS AT A TIME // $chunks = array_chunk($users, 1000); $count = 0; foreach ($chunks as $data) { $count += $remote->exec("INSERT INTO users (id, username) VALUES " . join(',', $data)); } echo "$count records transferred";
-
We need to change the alias of the date column to something other than "date" otherewise it willl try to sort using the d/m/Y format, which doesn't work. We need to sort by the original date (Y-m-d) Therefore the query will become SELECT name , comment , DATE_FORMAT(date, '%d/%m/%Y') as formatted FROM image ORDER BY date DESC; (Don't forget to use your column names and where you had $row['date'] you now need $row['formatted'])
-
How to display every photo from a database? [closed]
Barand replied to veks21's topic in PHP Coding Help
Where do create the instances of your database and photo_display classes? How are you storing the images. <img src needs to be a filename (or encoded data), not var_dump output. -
Here's an example of the javascript pprocessing. (I don't know what your tables look like to give you an example of the update.) <!DOCTYPE html> <html> <head> <title>Example</title> <meta http-equiv="content-language" content="en"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <!-- link to jquery functions --> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script type='text/javascript'> $().ready( function() { $("#approved").change( function() { if ($(this).val() > '') $("#status").val("Approved") else $("#status").val("Pending") }) }) </script> </head> <body> Status<br> <input type='text' name='status' id='status' value='Pending'> <br><br> Date approved<br> <input type='date' name='approved' id='approved'> </body> </html>
-
When the admin adds an approval date, update the date and status in your tables when saved. If you want immediately to alter the status display on screen, use a javascript onchange event on the date input to change the status to Approved.
-
This is the same problem as your post in the php coding forum - don't double post.
-
Don't allow users to enter dates in any format - use a datepicker or HTML5 date input to enforce uniformity of input, and always store in yyyy-mm-dd format. Luckily you only appear to have only three formats (Y-m-d / d M Y / d-m-Y) so all is not lost. TEST DATA mysql> select * from date_example; +----+-------------+----------+ | id | date | time | +----+-------------+----------+ | 1 | 2005-05-21 | 14:00:00 | | 2 | 22 Jun 2006 | 13:00:00 | | 3 | 01-11-2009 | 12:00:00 | | 4 | 22-03-2021 | 00:05:00 | | 5 | 28 Mar 2021 | 08:00:00 | +----+-------------+----------+ QUERY SELECT * FROM ( SELECT id , date , CASE WHEN str_to_date(date, '%d %b %Y') IS NOT NULL -- eg 01 Jan 2021 THEN str_to_date(date, '%d %b %Y') WHEN str_to_date(date, '%d-%m-%Y') IS NOT NULL -- eg 10-01-2021 THEN str_to_date(date, '%d-%m-%Y') ELSE date END as newdate , time FROM date_example ) converted WHERE concat(newdate, ' ', time) < NOW() - INTERVAL 36 HOUR; RESULTS +----+-------------+------------+----------+ | id | date | newdate | time | +----+-------------+------------+----------+ | 1 | 2005-05-21 | 2005-05-21 | 14:00:00 | | 2 | 22 Jun 2006 | 2006-06-22 | 13:00:00 | | 3 | 01-11-2009 | 2009-11-01 | 12:00:00 | | 4 | 22-03-2021 | 2021-03-22 | 00:05:00 | +----+-------------+------------+----------+
-
Are you talking about HTML tables on the screen or database tables?