-
Posts
24,572 -
Joined
-
Last visited
-
Days Won
823
Everything posted by Barand
-
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
-
select <whatever> from <tablename> order by date_created limit 20
-
Is this any use to you? <!DOCTYPE html> <html lang="en"> <head> <title>Wordle Assist</title> <meta charset="utf-8"> <script src="https://code.jquery.com/jquery-3.6.4.min.js"></script> <style type='text/css'> @media print { .printme { visibility: visible; display: block; } .noprint { visibility: hidden; } } #print { font-family: "times new roman", serif; font-size: 20pt; } #address { margin: 50px; line-height: 40px; } </style> <script type='text/javascript'> $(function() { if ($("#address").text() != '') { print() } }) </script> </head> <body> <div id='address' class='printme'> <?= nl2br($_GET['addy'] ?? '') ?> </div> <header class='noprint'> <h1>Address Labels</h1> </header> <form class='noprint'> Address:<br><br> <textarea cols='60' rows='5' name='addy'></textarea> <br><br> <button id=btnPrint'>Print</button> </form> </body> </html>
-
Hvae you looked at the page's html source code?
-
Php and Laravel prevent duplicate entries help please
Barand replied to PNewCode's topic in PHP Coding Help
No hablo Laravelese. Sorry, I've never used it. -
You only need one query. For example TABLE : product +----+-------------+--------------+--------+ | id | productName | category | status | +----+-------------+--------------+--------+ | 1 | Room 1 | Guestroom | Active | | 2 | Room 2 | Guestroom | Active | | 3 | Room 3 | Guestroom | Active | | 4 | Room 4 | Guestroom | Active | | 5 | Function 1 | Functionroom | NULL | +----+-------------+--------------+--------+ code $sql = "SELECT SUM(status='Pending')as pending , SUM(status='Active') as active FROM product"; $result = mysqli_query($con, $sql); $row = mysqli_fetch_assoc($result); echo "Pending : <input type=\"button\" class=\"button\" value=\"{$row['pending']}\"> Active : <input type=\"button\" class=\"button\" value=\"{$row['active']}\"> "; output