Jump to content

Barand

Moderators
  • Posts

    24,566
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. foreach (array as $recno => $record) { echo "<h3>Record $recno</h3>"; foreach ($record as $field => $value) { echo "$field : $value<br>"; } }
  2. I see emails and phone numbers customers +----+------+------------+-------+ | id | name | email | phone | +----+------+------------+-------+ | 1 | aaa | [email protected] | 123 | | 2 | bbbb | [email protected] | 124 | | 3 | ccc | [email protected] | 124 | | 4 | ddd | [email protected] | 123 | | 5 | eee | [email protected] | 125 | | 6 | fff | [email protected] | 126 | | 7 | ggg | [email protected] | 127 | | 8 | hhh | [email protected] | 128 | | 9 | iii | [email protected] | 125 | | 10 | jjj | [email protected] | 129 | | 11 | kkk | [email protected] | 130 | | 12 | lll | [email protected] | 127 | | 13 | mmm | [email protected] | 131 | | 14 | nnn | [email protected] | 132 | | 15 | ooo | [email protected] | 123 | | 16 | ppp | [email protected] | 133 | +----+------+------------+-------+ query SELECT DISTINCT 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; results +----+------------+-------+ | id | email | phone | +----+------------+-------+ | 1 | [email protected] | 123 | | 2 | [email protected] | 124 | | 3 | [email protected] | 124 | | 4 | [email protected] | 123 | | 5 | [email protected] | 125 | | 7 | [email protected] | 127 | | 9 | [email protected] | 125 | | 12 | [email protected] | 127 | | 15 | [email protected] | 123 | +----+------------+-------+
  3. Use the successive keys. $value = $array[$recordNo][$fieldname]; EG $date = $array[0]['t_test_date']; // 2021-02-11
  4. 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;
  5. 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?
  6. posted in error
  7. 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;
  8. session.gc_maxlifetime = 86400
  9. Such as what?
  10. 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)
  11. 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 )
  12. 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.
  13. 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)
  14. 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.
  15. 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.
  16. 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 | +------------------------------------------------------+---------+---------+
  17. try this link https://www.php.net/manual/tr/mysqli.query.php
  18. 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.
  19. Read the manual - NotionCommotion gave you the link. Compare the examples with your code.
  20. FYI, as of php7, you could write it as usort($productions, function($a1, $a2) { return $a2['year'] <=> $a1['year']; });
  21. 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
  22. Show the rest of that query's processing code.
  23. This reply to an earlier post may be relevant to your problem
  24. 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.
  25. or make use of the defined() function
×
×
  • 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.