Jump to content

Barand

Moderators
  • Posts

    24,572
  • Joined

  • Last visited

  • Days Won

    823

Barand last won the day on January 16

Barand had the most liked content!

About Barand

Profile Information

Recent Profile Visitors

103,351 profile views

Barand's Achievements

Prolific Member

Prolific Member (5/5)

2.1k

Reputation

494

Community Answers

  1. The syntax you want is foreach (get_holidays($year) as $holiday_name => $holiday) { . . . }
  2. Earlier in this thread you said that this ... +----+-----------+-----------+ | id | slug | tag_check | +----+-----------+-----------+ | 1 | hugh-jass | 1 | | 2 | hugh-jass | 2 | +----+-----------+-----------+ ... was acceptable. Your "solution" would not permit this. Secondly, you are using a "dependent subquery" which means for every record inserted you must query all the existing lookig for a duplicate. This can be extremely slow and should be avoided when writing queries. Changing your unique key to ... UNIQUE INDEX `unq_name` (`name`) USING BTREE, ... and using this query would have same result ... INSERT IGNORE into wp_terms (name,slug) SELECT concat(nameFirst,' ',nameLast) , lower(concat(nameFirst,'-',nameLast)) FROM a_players ;
  3. Is it necessary to include the tag_check in the unique key? Would this be acceptable... +----+-----------+-----------+ | id | slug | tag_check | +----+-----------+-----------+ | 1 | hugh-jass | 1 | | 2 | hugh-jass | 2 | +----+-----------+-----------+ or can there be only one "hugh-jass" in the table?
  4. Your UNIQUE key is the combination of (slug, tag_check). NULL values are ignored and your insert query always writes NULL to tag_check column. CREATE TABLE `dupe_test` ( `id` int(11) NOT NULL AUTO_INCREMENT, `slug` varchar(50) NOT NULL DEFAULT '', `tag_check` tinyint(4) DEFAULT NULL, PRIMARY KEY (`id`), UNIQUE KEY `player_tag_check` (`slug`,`tag_check`) ) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci; select * from dupe_test; +----+-----------+-----------+ | id | slug | tag_check | +----+-----------+-----------+ | 1 | hugh-jass | NULL | | 2 | hugh-jass | NULL | | 3 | hugh-jass | NULL | | 4 | hugh-jass | 1 | +----+-----------+-----------+ Add another... MariaDB [test]> insert into dupe_test (slug) values ('hugh-jass'); Query OK, 1 row affected (0.051 sec) MariaDB [test]> select * from dupe_test; +----+-----------+-----------+ | id | slug | tag_check | +----+-----------+-----------+ | 1 | hugh-jass | NULL | | 2 | hugh-jass | NULL | | 3 | hugh-jass | NULL | | 6 | hugh-jass | NULL | << NEW | 4 | hugh-jass | 1 | +----+-----------+-----------+ 5 rows in set (0.000 sec) Now try adding again but with tag_check = 1 then 2... MariaDB [test]> insert into dupe_test (slug, tag_check) values ('hugh-jass', 1); ERROR 1062 (23000): Duplicate entry 'hugh-jass-1' for key 'player_tag_check' MariaDB [test]> insert into dupe_test (slug, tag_check) values ('hugh-jass', 2); Query OK, 1 row affected (0.073 sec) MariaDB [test]> select * from dupe_test; +----+-----------+-----------+ | id | slug | tag_check | +----+-----------+-----------+ | 1 | hugh-jass | NULL | | 2 | hugh-jass | NULL | | 3 | hugh-jass | NULL | | 6 | hugh-jass | NULL | | 4 | hugh-jass | 1 | | 8 | hugh-jass | 2 | +----+-----------+-----------+ 6 rows in set (0.000 sec) So either insert a tag_check value too, or exclude tag_check from the UNIQUE key
  5. post outout from this query... SHOW CREATE TABLE wp_terms
  6. For "ON DUPLICATE KEY" to work, mysql needs to know what column(s) values must be unique. You do this by defining a UNIQUE KEY on that/those columns
  7. Not a lot. "It doesn't work" tells us nothing. What is ir doing that it shouldn't or what is it not doing that it should? If element_5 contains a price, why not call it "price". Same goes for element_6 (option_id). I can't see what do_query() is doing but as you're passing an array of parameters I assume you are trying to use a prepared statement - but you have no placeholders in the query string for those parameters. If $filter_keyword contains a column name that could be the cause - you can only pass values as parameter. If any of your joins match more than 1 row in any of the tables, the resultant sum would be multiplied by the number of rows. If you need more help, a dump of the structures and data for those tables would enable me to recreate the problem at my end a get you a working query.
  8. You need to unserialise the data. $dbdata = 'a:5:{s:16:"WPFormsDB_status";s:6:"unread";s:4:"Name";s:13:"Lional Hewitt";s:14:"Contact Number";s:10:"0763229844";s:5:"Email";s:22:"[email protected]";s:18:"Comment or Message";s:5:"test2";}'; $data = unserialize($dbdata); echo "Name : {$data['Name']}<br>"; echo "Contact : {$data['Contact Number']}<br>"; // etc Alternatively $dbdata = 'a:5:{s:16:"WPFormsDB_status";s:6:"unread";s:4:"Name";s:13:"Lional Hewitt";s:14:"Contact Number";s:10:"0763229844";s:5:"Email";s:22:"[email protected]";s:18:"Comment or Message";s:5:"test2";}'; $data = unserialize($dbdata); foreach ($data as $key => $value) { echo "<b>$key</b> : $value<br>"; }
  9. I have no idea, insufficient information. You need to show the code that executes that query and checks for the number of rows returned
  10. mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); Add the above line just before the line that creates your db connection. Make sure error reporting is on.
  11. Post the full version of the code that isn't working.
  12. My database connection code is not present in the code I posted.. Hava you added your pdo connection code at the top of the script?
  13. Is "index.php" defined as the default document name?
  14. Thanks for letting us know.
×
×
  • 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.