Jump to content

Barand

Moderators
  • Posts

    24,603
  • Joined

  • Last visited

  • Days Won

    830

Everything posted by Barand

  1. Your model table should be four tables.. +------------+ | category | +------------+ | id |----+ | cat_name | | +------------+ | | | +---------------+ | | subcategory | | +---------------+ | | id |------+ +----<| category_id | | | subcat_name | | +---------------+ | | | | +------------+ | | model | | +------------+ | | id | | | model_name | +------<| subcat_id | +-----------<| brand_id | | +------------+ | +------------+ | | brand | | +------------+ | | id |----+ | brand_name | +------------+
  2. By far the best the best way is to fix whatever they are warning you about.
  3. Last time I tried to do that you ignored it...
  4. You should not be storing totals. Your data should be correctly designed (normalized). Come back when it is and I'll be glad to help.
  5. P.S. Instead of runnning 3 queries you could do something like this SELECT string , SUM(CASE WHEN date > NOW() - interval 1 HOUR THEN 1 ELSE 0 END) as lastHour , SUM(CASE WHEN date > NOW() - interval 1 DAY THEN 1 ELSE 0 END) as lastDay , SUM(CASE WHEN date > NOW() - interval 7 DAY THEN 1 ELSE 0 END) as lastWeek FROM queries GROUP BY string; giving
  6. You do realise that id and date values returned by that query could be from any arbitrary record in the group and therefore meaningless, don't you? Define "working".
  7. By using a "title" attribute?
  8. Example code (data from tutorial in my sig) <?php $res = $pdo->query("SELECT concat(fname, ' ', lname) as name , group_concat(subject separator '<br>') as subjects FROM pupil p JOIN choice c USING (pupilID) JOIN subject s USING (subjectID) WHERE houseID = 1 GROUP BY p.pupilID; "); $tdata = ''; foreach ($res as $row) { $tdata .= "<tr><td>{$row['name']}</td> <td>{$row['subjects']}</td> </tr>"; } ?> <!DOCTYPE html> <html lang='en'> <head> <meta charset='utf-8'> <title>Example</title> <style type='text/css'> body { font-family: verdana; } table { border-collapse: collapse; width: 500px; margin: 50px auto; } td { padding: 4px 16px; } </style> </head> <body> <table border='1'> <?= $tdata ?> </table> </body> </html> output
  9. Have you got "display_startup_errors" turned on in your php.ini file?
  10. Because you exit before anything can be output?
  11. If you use prepared queries correctly, with placeholders for user-supplied data, you don't need that code - the values will not be embedded in the SQL code.
  12. To check for rooms booke between dates A and B you need to compare their departureDate against A, and arrivalDate against B Your query above has ... * * * * * The <br> won't kick in until you you output to an HTML page.
  13. By the way, your query will not output the rooms that you want. Check the date join conditions between room and room_booking in your query against the query I gave you in your previous post. Also, the only join that may or may not find a matching record is room->room_booking, so that needs to be a LEFT JOIN. All the other joins only need to be simple JOINs (which are much faster than LEFT JOINS) SELECT rs.description , rs.sleeps , rs.image , rs.price , GROUP_CONCAT(DISTINCT f.description SEPARATOR '<br>') AS rmfac , rt.description as rmtype , r.room_id , r.room_number FROM room as r JOIN roomtype as rt ON r.roomtype_id = rt.roomtype_id JOIN roomsize as rs ON r.size_id = rs.size_id JOIN room_facility as rf ON rf.size_id = rs.size_id JOIN facility as f ON rf.facility_id = f.facility_id LEFT JOIN room_booking as rb ON r.room_id = rb.room_id AND rb.departureDate > :arrival AND rb.arrivalDate <= :departure WHERE rb.room_id IS NULL ORDER BY room_id
  14. Perhaps because your separator is "\n" and HTML treats all whitespace as a space. Try "<br>";
  15. When you use an agregation function (like SUM() or GROUP_CONCAT() ) without a GROUP BY clause, you get a single aggregation for the whole table.
  16. Looks OK, but you are missing the charset setting. eg $pdo = new PDO("mysql:host=".HOST.";dbname=$dbname;charset=utf8",USERNAME,PASSWORD); ^^^^^^^^^^^^ but you should've got the same error I did when I ran your code
  17. P.S. Looks like you need to set another PDO option on connecting... $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  18. You have omitted item_id from your query. I created your table and ran a test...
  19. Can you show us the output from this query? show create table consumable_price;
  20. Sorry. VALUES(minQty) and maxQty should be min_qty and max_qty (to match your column names)
  21. Try setting the cpId value to either 0 or NULL for new items. It would appear that you are not setting the EMULATE_PREPARES option to "false" in your connection code on leaving it as "true" (default). Set it to false so prepared queries are truly prepared. Note that with true prepares you will not be able to use execute array elements multiple times (eg ":minQty" appears twice in the query but only once in the array). Rewrite the query as INSERT INTO consumable_price (id, min_qty, max_qty, GBP, USD, CAD, EUR) VALUES (:cpId, :minQty, :maxQty, :GBP, :USD, :CAD, :EUR) ON DUPLICATE KEY UPDATE min_qty = VALUES(minQty) , max_qty = VALUES(maxQty) , GBP = VALUES(GBP) , USD = VALUES(USD) , CAD = VALUES(CAD) , EUR = VALUES(EUR); to re-use the values.
  22. Another option is to use the null coalesce operator (??), so if ($_GET["nsfw_options"] == "true") { $sfw = 1; setcookie("nsfw", "true"); $_COOKIE["nsfw"] = "true"; } if ($_GET["nsfw_options"] == "false") { $sfw = 0; setcookie("nsfw", "false"); $_COOKIE["nsfw"] = "false"; } becomes $nsfw = $_GET['nsfw_options'] ?? "false"; // if isset() use its value otherwise set default value ("false") $sfw = $nsfw == "true" ? 1 : 0; setcookie("nsfw", $nsfw); $_COOKIE["nsfw"] = $nsfw;
  23. Yes, positively evil. You can easily display them like that on output but don't store them like that. For example... mysql> select * from project; +----+---------------+-----------+------------+ | id | project_name | client_id | start_date | +----+---------------+-----------+------------+ | 1 | Project Alpha | 4 | 2022-12-01 | | 2 | Proect Beta | 2 | 2023-01-15 | | 3 | Project Gamma | 4 | 2023-03-01 | | 4 | Project Delta | 1 | 2023-03-20 | +----+---------------+-----------+------------+ mysql> select client_id -> , group_concat(project_name separator ', ') as projects -> from project -> group by client_id; +-----------+------------------------------+ | client_id | projects | +-----------+------------------------------+ | 1 | Project Delta | | 2 | Proect Beta | | 4 | Project Alpha, Project Gamma | +-----------+------------------------------+
  24. ... AND Month = (SELECT max(Month) FROM equipment_population)
  25. My understanding is that REPLACE will always create a new record (and therefore setting default values). INSERT .. ON DUPLICATE KEY will insert only when the record does not exist and update specified fields when it does. I'd go for the latter in this case. Experimentation is good. Try out a test.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.