-
Posts
24,566 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Mail issue leads to need for complex str_replace?
Barand replied to sleepyw's topic in PHP Coding Help
$recipient is a string containing a single email. You need to implode the array "$exploded_new_recipients" -
INSERT statements don't have WHERE clauses. If you don't want to allow duplicate titles, add a UNIQUE constraint to the title column
- 1 reply
-
- 1
-
We have told you how you should be tackling the problem and you have ignored those suggestions and decided to take this approach. You can go on forever trying to adjust the query to work for each particular situation as it arises. The correct approach is a proper data structure and queries that work for all eventualities.
-
PHP concatenation operator is "." and not "+"
-
Sorry, arithmetic on a NULL value produces null result SELECT i.`quantidade` - IFNULL(SUM(r.`quant`),0) AS total FROM `item` AS i LEFT JOIN `requisicoes` AS r ON (r.`id_item` = i.`id_itens`) AND r.`startDate` = "2015-11-22 11:30" AND r.`endDate` = "2015-11-23 11:20 WHERE i.`id_itens` = 8
-
The simple answer is "No". If you want to select all, don't specify the IN() condition
-
One or two things wrong with that query. 1. Your calculation - If you had two loans, each of 10 books, then you would expect a result of 10 remaining. Yours would give (30-10) + (30-10) = 40. You need i.`quantidade` - SUM(r.`quant`) AS total 2. Your join - INNER JOIN retrieves records only when there is a matching record in both tables. If one table has no record then no results. You need FROM `item` AS i LEFT JOIN `requisicoes` AS r ON (r.`id_item` = i.`id_itens`) so that you select the item record even if there are no req records. Having changed to a LEFT join you need to change the WHERE clause so it doesn't contain conditions on the req data. Those need to go in the join condition. So the query now becomes SELECT i.`quantidade` - SUM(r.`quant`) AS total FROM `item` AS i LEFT JOIN `requisicoes` AS r ON (r.`id_item` = i.`id_itens`) AND r.`startDate` = "2015-11-22 11:30" AND r.`endDate` = "2015-11-23 11:20 WHERE i.`id_itens` = 8
-
you could use something like this SELECT a.user , group_concat(b.user) as guests , count(b.guestof) as total FROM userlist a LEFT JOIN userlist b ON b.guestof = a.user GROUP BY a.user ; +-------+-----------+-------+ | user | guests | total | +-------+-----------+-------+ | Bill | Jason | 1 | | Frank | NULL | 0 | | Gwen | NULL | 0 | | Jack | Gwen,Matt | 2 | | Jason | Jill,Jack | 2 | | Jill | Frank,Stu | 2 | | Matt | NULL | 0 | | Stu | NULL | 0 | +-------+-----------+-------+
-
In addition, your SQL query syntax is wrong. String values need to be in single quotes INSERT INTO student_register_test10 (name, address, topic1) values ('$name', '$address', '$topic1' )
-
How does that work? There doesn't appear to be anything to say books have been returned, or not
-
Was I correct in my dates assumption. So if they are not yet returned then the endDate is NULL?
-
Is "startDate" the date it was borrowed and "endDate" the date of return? What happens if, say, they borrow 2 but only return 1? You have only one quantity column. From what you have shown us so far I am not convinced your data structure can support your requirements.
-
Your understanding is correct. However, that refers to the MySql TIMESTAMP type which has the same format as DATETIME type (but a smaller date range). In my comment above I stated "unix timestamp" which is an INT (eg 1447148711).
-
Do it all in the query SELECT ..., COUNT(*) as total FROM ... WHERE status='Done' GROUP BY student_email
-
Optaining the clicked value from a table in an input
Barand replied to zazu's topic in Javascript Help
I'd make use of data attributes to get the data in one place when clicked. Here's an example using a couple of your rows <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Primes & Factors</title> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript"> $().ready(function() { $(".old-price, .orange-price").click(function() { var vol = $(this).data('vol'); var price = $(this).html(); $("#vol").val(vol); $("#price").val(price); }) }) </script> <style type="text/css"> .old-price, .orange-price { cursor: pointer; } caption { font-size: 14pt; font-weight: 600; } </style> </head> <body> <table id="myTable" class="demo"> <caption> Sisteme de cosuri fum TONA <span class="orange-price">- 15% REDUCERE</span> </caption> <thead> <tr> <th> Inaltime / Dimensiune </th> <th>Ø 14</th> <th>Ø 16</th> <th>Ø 18</th> <th>Ø 20</th> <th>Ø 25</th> </tr> </thead> <tbody> <tr> <td>5 ml <br> </td> <td><span data-vol='5' class="old-price">583 EUR</span> <br> <span data-vol='5' class="orange-price">496 EUR</span> </td> <td><span data-vol='5' class="old-price">630 EUR</span> <br> <span data-vol='5' class="orange-price">536 EUR</span> </td> <td><span data-vol='5' class="old-price">661 EUR</span> <br> <span data-vol='5' class="orange-price">562 EUR</span> </td> <td><span data-vol='5' class="old-price">704 EUR</span> <br> <span data-vol='5' class="orange-price">598 EUR</span> </td> <td><span data-vol='5' class="old-price">1125 EUR</span> <br> <span data-vol='5' class="orange-price">956 EUR</span> </td> </tr> <tr> <td>5.5 ml</td> <td><span data-vol='5.5' class="old-price">608 EUR</span> <br> <span data-vol='5.5' class="orange-price">517 EUR</span> </td> <td><span data-vol='5.5' class="old-price">659 EUR</span> <br> <span data-vol='5.5' class="orange-price">560 EUR</span> </td> <td><span data-vol='5.5' class="old-price">692 EUR</span> <br> <span data-vol='5.5' class="orange-price">588 EUR</span> </td> <td><span data-vol='5.5' class="old-price">737 EUR</span> <br> <span data-vol='5.5' class="orange-price">626 EUR</span> </td> <td><span data-vol='5.5' class="old-price">1187 EUR</span> <br> <span data-vol='5.5' class="orange-price">1009 EUR</span> </td> </tr> </tbody> </table> <br> Chosen volume <input type="text" name="vol" id="vol" size="5"> Chosen price <input type="text" name="price" id="price" size="8"> </body> </html>- 3 replies
-
- table
- javascript
-
(and 1 more)
Tagged with:
-
MySQL Workbench ENUM() Given data type contains error
Barand replied to ronc0011's topic in MySQL Help
I'm using workbench (6.3.3) and the only time it threw an error for me was when there really was an error. I just now entered another ENUM column and it let me tab quite happily to the next column name. Only had to "apply" after all changes were done. -
MySQL Workbench ENUM() Given data type contains error
Barand replied to ronc0011's topic in MySQL Help
Yes. Notepad is using non-standard single quotes. This should work ENUM('Ford','GMC','Chevrolet','Chrysler','Dodge','Buick','Toyota','Volvo','International','Kenworth','Peterbilt','Mack','Freightliner','Isuzu') -
IMHO a unix timestamp is not a good option. If when you need to browse your data in the table it makes it almost impossible to know what the actual date/time value is and needs conversion to DATE/TIME type before you can use the majority of datetime SQL functions.
-
You define it only when $_POST['submit'] is set - ie when data has been posted to the form. You try to use whether data is posted or not
-
If you have "syntax error, unexpected xxx" then the error is just before the xxx. That is what makes it "unexpected"
-
Cumulative sum in MySQL View (calculating running profit/loss)
Barand replied to DariusB's topic in MySQL Help
Correction: I forgot you had separate date and time fields. The ORDER BY clauses in my query need to include the date too. -
MySQL Workbench ENUM() Given data type contains error
Barand replied to ronc0011's topic in MySQL Help
As Benanemen said, put the makes in a separate table, each with a unique id and store the appropriate id in the car table carMake +--------+-------------------+ | makeId | make | +--------+-------------------+ | 1 | Ford | | 2 | GMC | | 3 | Chevorlet | | 4 | Chrysler | | 5 | Dodge | | 6 | Buick | | 7 | Toyota | | 8 | Volvo | | 9 | International | | 10 | Kenworth | | 11 | Peterbilt | | 12 | Mack | | 13 | Freightliner | | 14 | Isuzu | +--------+-------------------+ | | +-----------------+ | car | +-------+--------+----------+------+--------+ | carId | makeId | plate | year | colour | +-------+--------+----------+------+--------+ | 1 | 2 | AB10XYZ | 2010 | Red | | 2 | 14 | M55DEF | 2005 | Blue | | 3 | 8 | DT15AAA | 2015 | Silver | +-------+--------+----------+------+--------+ To retrieve the make use a query with a JOIN between the two tables, matching on the makeId. -
Cumulative sum in MySQL View (calculating running profit/loss)
Barand replied to DariusB's topic in MySQL Help
I that case you have a problem as views don't like subqueries or @variables. Basically, don't store derived values, run the query when you want the cumulatives -
You would join the table to itself on data_id/parent_id Example SELECT p.item_id as parent_item , p.alias as parent_alias , p.type as parent_type , c.alias as child_alias , c.type as child_type , c.name as child_name FROM item p LEFT JOIN item c ON p.data_id = c.parent_id WHERE p.parent_id = 0 ORDER BY parent_item; When you process the results, check for a change in the parent_item value. When it changes, close off the previous table and start a new one for the new item. Example $db = new mysqli(HOST, USERNAME, PASSWORD, 'darius'); $sql = "SELECT p.item_id as parent_item , p.alias as parent_alias , p.type as parent_type , c.alias as child_alias , c.type as child_type , c.name as child_name FROM item p LEFT JOIN item c ON p.data_id = c.parent_id WHERE p.parent_id = 0 ORDER BY parent_item"; $currItem = 0; $res = $db->query($sql); while (list($parent_item,$parent_alias,$parent_type,$child_alias,$child_type,$child_name) = $res->fetch_row()) { if ($parent_item != $currItem) { // has value changed? if ($currItem) { echo "</table>\n"; // close table (if we have one) } echo "<table border='1'><caption>$parent_alias</caption>\n"; $currItem = $parent_item; // reset current item value } echo "<tr><td>$child_alias</td><td>$child_type</td><td>$child_name</td></tr>\n"; } echo "</table>\n"; // close final table
-
You would have a single Emp table but connect to it twice in the same query giving each instance a different table alias. In which case you would group by form and select SUM(scoring)