-
Posts
24,565 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
PHP Version 5.6.40, internal error for connect mysql
Barand replied to nitiphone2021's topic in PHP Coding Help
Syntax for host and port is host:port try $conn = mysqli_connect("$servername:$db_port", $username, $password,$db_database); -
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 | +---------+-----------------------------+
-
Wht the connection class to call a connection class? Why not just... $db = new PDO( .... ); Job done.
-
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)
-
Delete hierarchical parent and child category and update child as parent
Barand replied to thara's topic in MySQL Help
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 = ?; -
Delete hierarchical parent and child category and update child as parent
Barand replied to thara's topic in MySQL Help
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. -
What do want to update if there is a duplicate key?
-
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; });
- 1 reply
-
- 2
-
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)
-
Delete hierarchical parent and child category and update child as parent
Barand replied to thara's topic in MySQL Help
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.. -
Delete hierarchical parent and child category and update child as parent
Barand replied to thara's topic in MySQL Help
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) -
how to check if multiple arrays exist inside an array or not
Barand replied to AquariaXI's topic in PHP Coding Help
foreach() and is_array() might be useful -
To check if the query failed or not. If query() fails it returns false.
-
Try removing the "?>" from the end of dbconfig.php
-
Array from comma separated string containing multiple array{s} ?
Barand replied to AquariaXI's topic in PHP Coding Help
For the benefit of those others looking for a solution to a similar problem, why not post your solution. -
The way to get to know it is to use it.
-
or a database
-
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.
-
Split array every 3 commas & return as string?
Barand replied to AquariaXI's topic in PHP Coding Help
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 -
On this page it clearly states
-
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
-
I make it 3 if include the correction to your SQL syntax
-
Unsure why I cannot see the table i'm doing a join on
Barand replied to Fishcakes's topic in MySQL Help
You could, but using * in a select is rarely a good idea. -
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) )
-
Unsure why I cannot see the table i'm doing a join on
Barand replied to Fishcakes's topic in MySQL Help
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).