-
Posts
24,602 -
Joined
-
Last visited
-
Days Won
830
Everything posted by Barand
-
From what I have been given, I came up with this ... SELECT b.boardID , b.title , t.threadID , t.topic , t.userID , t.username , FROM_UNIXTIME(t.time) AS time , FROM_UNIXTIME(t.lastPostTime) AS lastPostTime FROM wbb1_1_board b JOIN wbb1_1_thread t USING (boardid) JOIN wbb1_1_board_last_post l USING (boardid, threadid) ORDER BY boardID, threadid, time; Hovever, it seems to me that there should be a "post" table containing the post details, including the time_posted. Then you could just extract the posts containing the latest timestamp for each thread.
-
Posting the structures of the three tables would help. Better still a dump of tose tables (if there isn't too much data)
-
You could experiment quite safely without any danger of causing a global catastrophe
-
The ability to use strings as array keys (associative keys) has always been a feature of PHP. The drawbacks are the same as when using string columns as keys in DB tables... they tend to be longer and therefore less efficient great care has to taken to ensure consistency of case, puctuation and spelling
-
The last 2 lines of your query are ... where you are joining options and filters tables. Your option_id column contains values between 1 and 12. select * from ap_element_options LIMIT 15; +--------+---------+------------+-----------+----------+---------------+-------------------+------------------+------+ | aeo_id | form_id | element_id | option_id | position | option | option_is_default | option_is_hidden | live | +--------+---------+------------+-----------+----------+---------------+-------------------+------------------+------+ | 431 | 10556 | 1 | 4 | 1 | MCSO | 0 | 0 | 1 | | 432 | 10556 | 1 | 5 | 2 | CCSO | 0 | 0 | 1 | | 433 | 10556 | 1 | 6 | 3 | LCSO | 0 | 0 | 1 | | 434 | 10556 | 1 | 7 | 4 | DPD | 0 | 0 | 1 | | 435 | 10556 | 1 | 8 | 5 | FPHM | 0 | 0 | 1 | | 436 | 10556 | 1 | 9 | 6 | FHPC | 0 | 0 | 1 | | 437 | 10556 | 1 | 10 | 7 | FHPL | 0 | 0 | 1 | | 438 | 10556 | 1 | 11 | 8 | AUTO CLUB | 0 | 0 | 1 | | 439 | 10556 | 1 | 12 | 9 | OWNER | 0 | 0 | 1 | | 446 | 10556 | 2 | 4 | 1 | F550 | 0 | 0 | 1 | | 447 | 10556 | 2 | 5 | 2 | F350 | 0 | 0 | 1 | | 448 | 10556 | 2 | 6 | 3 | International | 0 | 0 | 1 | | 449 | 10556 | 2 | 7 | 4 | Ranger | 0 | 0 | 1 | | 453 | 10556 | 4 | 1 | 1 | Credit Card | 0 | 0 | 1 | | 454 | 10556 | 4 | 2 | 2 | Cash | 0 | 0 | 1 | +--------+---------+------------+-----------+----------+---------------+-------------------+------------------+------+ Which of these values are you expecting to match the filter_keyword Tow ? select * from ap_form_filters; +--------+---------+---------+--------------------+--------------+------------------+----------------+ | aff_id | form_id | user_id | incomplete_entries | element_name | filter_condition | filter_keyword | +--------+---------+---------+--------------------+--------------+------------------+----------------+ | 312 | 10556 | 3 | 0 | element_6 | is | Tow | +--------+---------+---------+--------------------+--------------+------------------+----------------+ I suggest you rethink your design and come back when you have something that could work.
-
The syntax you want is foreach (get_holidays($year) as $holiday_name => $holiday) { . . . }
-
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 ;
-
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?
-
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
-
post outout from this query... SHOW CREATE TABLE wp_terms
-
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
-
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.
-
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>"; }
-
I have no idea, insufficient information. You need to show the code that executes that query and checks for the number of rows returned
-
How to ECHO which item was found/matched after running "foreach"
Barand replied to myphp's topic in PHP Coding Help
-
Help Needed with Fetching and Updating Vehicle Data Using API
Barand replied to GaneshNaiknavre's topic in PHP Coding Help
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. -
Post the full version of the code that isn't working.
-
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?
-
php if else not working with main root / only working for index.php
Barand replied to ianhaney10's topic in PHP Coding Help
Is "index.php" defined as the default document name? -
Examples of php scripting projects without laravel?
Barand replied to oslon's topic in PHP Coding Help
Thanks for letting us know. -
Here's an example. As you enter more letters of the name it narrows down the resulting list. (first and last names are searched) <?php # # HANDLE AJAX REQUESTS # if (isset($_GET['ajax'])) { if ($_GET['ajax'] == 'names') { $res = $pdo->prepare("SELECT id , concat(fname, ' ', lname) as name FROM person WHERE fname LIKE ? OR lname LIKE ? ORDER BY fname, lname "); $res->execute([ $_GET['search'], $_GET['search'] ]); $results = $res->fetchAll(); exit(json_encode($results)); } } ?> <!DOCTYPE html> <html lang="en"> <head> <title>Example</title> <meta charset="utf-8"> <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script> <style type='text/css'> </style> <script type='text/javascript'> $(function() { $("#search").on("input",function() { let srch = $(this).val() + "%" $.get( "", {"ajax":"names", "search":srch}, function(resp) { $("#person").html("") $.each(resp, function(k,v) { let opt = $("<option>", {"value":v.id, "text":v.name}); $("#person").append(opt); }) }, "JSON" ) }) }) </script> </head> <body> <form> Enter first part of name: <input type='text' id='search' > <br><br> <select name='person_id' id='person' size='20'> <!-- names returned from search go here --> </select> </form>
-
Why not have a dropdown for the persons. Then it's select person select job submit form (now has person_id and job_id from the selects)
-
Why waste your time writing JS code to replicate what the browser code already does (and compiled browser code will do the job far more efficiently than JS code)
-
1) Do you have php's error reporting ON and error level set to E_ALL? 2) Have you turned mysql's error reporting on with mysqli_report(MYSQLI_REPORT_ERROR|MYSQLI_REPORT_STRICT); immediately before your call to $con = mysqli_connect( ... )
-
But only if you can guarantee that the oldest records are always added first. If relative age is important why would you not store the date added? Having a date also has the advantage that you can have the option to DELETE FROM tablename WHERE datecol < CURDATE() - INTERVAL ? DAY so you can delete all those over N days old