Jump to content

Barand

Moderators
  • Posts

    24,565
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Syntax for host and port is host:port try $conn = mysqli_connect("$servername:$db_port", $username, $password,$db_database);
  2. Having agreed with the solution that @requinix suggested, and which I showed you how to implement, why are you still persisting with your "ON DUPLICATE ... CONCAT" ? Or do you want to end up with... +---------+-----------------------------+ | user_id | flavor | +---------+-----------------------------+ | 1 | chocolate, chocolate | | 1 | vanilla | +---------+-----------------------------+
  3. Wht the connection class to call a connection class? Why not just... $db = new PDO( .... ); Job done.
  4. You seem to have missed the plot. CREATE TABLE `mytable` ( `user_id` int(11) NOT NULL, `flavor` varchar(45) NOT NULL, PRIMARY KEY (`user_id`,`flavor`) ); Add 3 records, 1 vanilla and 2 chocolate insert ignore into mytable (user_id, flavor) values (1, 'vanilla'), (1, 'chocolate'), (1, 'chocolate'); View the table mysql> select * from mytable; +---------+-----------+ | user_id | flavor | +---------+-----------+ | 1 | chocolate | | 1 | vanilla | +---------+-----------+ 2 rows in set (0.00 sec)
  5. Do you mean like this UPDATE category a JOIN category b ON a.parent = b.id JOIN product p ON p.category = a.id SET a.parent = b.parent , p.category = b.parent WHERE a.parent = ?;
  6. In that case you have broken referential integrity rules by removing the products' category Options: Change the category of those products to a new one before deleting category 16. Don't allow the category deletion in the first place Delete the products too, as that category of item is no longer sold. Set the category of those products to NULL to show they are now orphans Those lst 3 options can be set in the foreign key cascade setting.
  7. What do want to update if there is a duplicate key?
  8. Since you want to filter an array, I suggest array_filter() $times = [ '2021-06-02T19:40:00Z', '2021-06-03T02:10:00Z', '2021-06-03T01:10:00Z', '2021-06-02T23:05:00Z', '2021-06-02T23:05:00Z', '2021-06-02T23:07:00Z', '2021-06-02T23:20:00Z', '2021-06-02T18:20:00Z', '2021-06-03T00:10:00Z', '2021-06-03T00:40:00Z' ]; $d = new DateTime('23:59:59', new DateTimeZone('Z')); $newtimes = array_filter($times, function($v) use ($d) { return new DateTime($v) <= $d; });
  9. When you pass a variable to a function it passes a copy of that variable. You are changing those copies. You need to return the cleaned value and assign that returned value to the variable. $firstname = clean_name($firstname)
  10. I don't see why that should be necessary. If your product were in in category 16 before the update it remains in catgory 16. It's just that 16 has moved a different parent, but the product remains unchanged..
  11. try UPDATE category a JOIN category b ON a.parent_id = b.category_id SET a.parent_id = b.parent_id WHERE a.parent_id = 9; DELETE FROM category WHERE category_id = 9; (Moving to MySQL forum)
  12. foreach() and is_array() might be useful
  13. To check if the query failed or not. If query() fails it returns false.
  14. Try removing the "?>" from the end of dbconfig.php
  15. For the benefit of those others looking for a solution to a similar problem, why not post your solution.
  16. The way to get to know it is to use it.
  17. First step is to check if there is an easier way. For example, the UK National Lottery provides a facility to download results in a CSV file.
  18. If you just echo the contents of the file, it will all be on one line as newlines (and other whitespace) are ignored by HTML. Try echo '<pre>' . file_get_contents('myfile.txt') . '</pre>'; or open the file in an editor
  19. On this page it clearly states
  20. Something like adding a line of code inside your resetCamera() fuction eg console.log("resetting camera now") so you can see in the log that it was called OK
  21. I make it 3 if include the correction to your SQL syntax
  22. You could, but using * in a select is rarely a good idea.
  23. There are some problems with your approach. For ON DUPLICATE KEY to work, the session_id column would also have to be defined as UNIQUE Your random_number column is defined a VARCHAR(6), so if you concatenate another 6 characters, where can they go? Then INSERT INTO mytable (Session_id,Random_Number) VALUES (?, ?) ON DUPLICATE KEY UPDATE Random_Number = CONCAT(Random_number, VALUES(Random_Number) )
  24. Then add "avatar" to the list of columns you are selecting (SELECT clause). You have added it to the tables to select from (FROM clause).
×
×
  • 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.