-
Posts
24,614 -
Joined
-
Last visited
-
Days Won
835
Everything posted by Barand
-
Use the successive keys. $value = $array[$recordNo][$fieldname]; EG $date = $array[0]['t_test_date']; // 2021-02-11
-
perhaps this, then SELECT a.id , a.email , a.phone FROM customers a JOIN customers b ON ((a.email = b.email) OR (a.phone = b.phone)) AND a.id <> b.id ORDER BY a.id;
-
OK, call me old fashioned, but why don't you just write a query instead of struggling to find the right incantations to get the db classes to do it for you?
-
posted in error
-
By "repeat customers" do you mean customers who have placed more then one order, or do you mean "duplicate" customers with more than 1 customer record? If it's the latter SELECT eamil , phone , GROUP_CONCAT(id SEPARATOR ', ') as duplicates FROM customers GROUP BY email, phone HAVING COUNT(*) > 0;
-
session.gc_maxlifetime = 86400
-
Looks like that code is giving ORDER BY l.buyout_price = 0 instead of the code I used... (which would explain the "weird ordering") ORDER BY l.buyout_price = 0, price (The ones that aren't zero need sorting by price)
-
Strange, because if I sort by that expression, I get mysql> SELECT id -> , name -> , price -> FROM test_a -> ORDER BY CASE price WHEN 0 THEN -0 ELSE price END; +----+------+-------+ | id | name | price | +----+------+-------+ | 4 | D | 0 | | 3 | C | 1 | | 5 | E | 5 | | 1 | A | 12 | | 2 | B | 200 | +----+------+-------+ However, on a similar tack, mysql> SELECT id -> , name -> , price -> FROM test_a -> ORDER BY CASE price WHEN 0 THEN 999999999 ELSE price END; +----+------+-------+ | id | name | price | +----+------+-------+ | 3 | C | 1 | | 5 | E | 5 | | 1 | A | 12 | | 2 | B | 200 | | 4 | D | 0 | +----+------+-------+ EDIT.... My apologies, I read it as a minus sign and not a bitwise inversion. Your version works fine. mysql> SELECT id -> , name -> , price -> FROM test_a -> ORDER BY CASE price WHEN 0 THEN ~0 ELSE price END; +----+------+-------+ | id | name | price | +----+------+-------+ | 3 | C | 1 | | 5 | E | 5 | | 1 | A | 12 | | 2 | B | 200 | | 4 | D | 0 | +----+------+-------+ ( ~0 evaluates to 18,446,744,073,709,551,615 )
-
I've no idea what that code of yours does. All I could do was show you how to use SQL TO order by a column ASC but with zero values last. How you accomplish that with your classes is down to you I'm afraid.
-
Do you mean something like this example? mysql> select * from test_a; +----+------+-------+ | id | name | price | +----+------+-------+ | 1 | A | 12 | | 2 | B | 200 | | 3 | C | 1 | | 4 | D | 0 | | 5 | E | 5 | +----+------+-------+ mysql> SELECT id -> , name -> , price -> FROM test_a -> ORDER BY price = 0, price; +----+------+-------+ | id | name | price | +----+------+-------+ | 3 | C | 1 | | 5 | E | 5 | | 1 | A | 12 | | 2 | B | 200 | | 4 | D | 0 | +----+------+-------+ (The value of "price = 0" will be either 1 or 0 depending on whether it is true or false)
-
The "WHERE ptsl_date = '2021-06-12' " is OK in the WHERE clause but you cannot put conditions on a LEFT JOINed subquery (or table) in a WHERE clause, they need to be in the join's ON clause.
-
I can't see your data so I don't know which rows match, but if you have a LEFT JOIN, and there is no match, then the used.* will be NULL, regardless of your uses of IFNULL() in the subquery. You need the IFNULL() in the top level select (instead of "SELECT * ") to fix.
-
LAN Web page worked PHP 5, not happy with PHP 7.
Barand replied to Geoff_2's topic in PHP Coding Help
The "null coalesce" operator was introduced in v7.0 +------------------------------------------------------+---------+---------+ | Code | v 5.x | v 7.0+ | +------------------------------------------------------+---------+---------+ | $onoff = isset($_POST['onoff']) ? 1 : 0 | Y | Y | +------------------------------------------------------+---------+---------+ | $onoff = $_POST['onoff1'] ?? 0; | - | Y | +------------------------------------------------------+---------+---------+ -
I'm having trouble listing the latest data.
Barand replied to maviyazilim's topic in PHP Coding Help
try this link https://www.php.net/manual/tr/mysqli.query.php -
I'm having trouble listing the latest data.
Barand replied to maviyazilim's topic in PHP Coding Help
Kılavuzu okuyun - NotionCommotion size bağlantıyı verdi. (https://www.php.net/manual/en/mysqli.query.php)( Örnekleri kodunuzla karşılaştırın. -
I'm having trouble listing the latest data.
Barand replied to maviyazilim's topic in PHP Coding Help
Read the manual - NotionCommotion gave you the link. Compare the examples with your code. -
FYI, as of php7, you could write it as usort($productions, function($a1, $a2) { return $a2['year'] <=> $a1['year']; });
-
Worked for me with a test table I created. $tsql = "select * from roombook ORDER BY FIELD(stat, 'Checked in', 'Booked', 'Deposit Confirmation', 'Email/phone', 'Checked out')"; $tre = mysqli_query($con, $tsql); echo "<table border='1' style='border-collapse: collapse;'>\n"; while ($trow = mysqli_fetch_array($tre)) { $co = $trow['stat']; if ($co != "Cancelled" ) { echo "<tr> <th>" . $trow['FName'] . " " . $trow['LName'] . "</th> <th>" . $trow['Email'] . "</th> <th>" . $trow['TRoom'] . "</th> <th>" . $trow['cin'] . "</th> <th>" . $trow['cout'] . "</th> <th>" . $trow['stat'] . "</th> <th><a href='roombook.php?rid=" . $trow['id'] . " ' class='btn btn-primary'>Action</a></th> </tr>"; } } echo "</table>\n"; I suggest you check your mysqli connection. Change your <th> to <td> for data rows Add "WHERE stat <> 'Cancelled'" to your query since you don't want to list them
-
Show the rest of that query's processing code.
-
LAN Web page worked PHP 5, not happy with PHP 7.
Barand replied to Geoff_2's topic in PHP Coding Help
This reply to an earlier post may be relevant to your problem -
Your select element does not have a name. Your checkbox doesn't have a value. ( I suggest "1") Only checked checkboxes are posted. You can use $checkbox = $_POST['checkbox'] ?? 0; Then $checkbox will contain 1 if checked and 0 if not.
-
or make use of the defined() function
-
Define "it's not working". Are you getting a PHP error, or a MySQL error message? Why are you ordering by stat twice? As an aside, your case statement looks weird in that you give numeric vlue to all statuses to sort on but as a default you have the string value "Cancelled". Have you considered making the stat column type ENUM? Or, perhaps ORDER BY FIELD(stat, 'Checked in', 'Booked', 'Deposit Confirmation', 'Email/phone', 'Checked Out', 'Cancelled')
-
Here's one way. When you send a payment confirmation write a record (forename, surname, email) to "confirmation" table CREATE TABLE `confirmation` ( `confirm_id` int(11) NOT NULL AUTO_INCREMENT, `forename` varchar(45) DEFAULT NULL, `surname` varchar(45) DEFAULT NULL, `email` varchar(45) DEFAULT NULL, `time_confirmed` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP, `tips_sent` datetime DEFAULT NULL, PRIMARY KEY (`confirm_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8; Set up a cron job to run every 5 minutes. This would SELECT confirm_id, forename, surname, email FROM confirmation WHERE tips_sent IS NULL AND NOW() - INTERVAL 10 MINUTE > time_confirmed; foreach record returned Send welcome tips email UPDATE confirmation SET tips_sent = NOW() WHERE confirm_id = ?