Jump to content

Barand

Moderators
  • Posts

    24,563
  • Joined

  • Last visited

  • Days Won

    822

Everything posted by Barand

  1. Pass $lang as an additional argument in the function call function testFunction($id, $settings, $db, $lang){
  2. Care to share?
  3. id columns are internal key links in the database and are no concern of the user. In addition, LIKE is used for wildcard string searches and not for numeric values like id fields. So why are you including the id fields in your search criteria?
  4. You want to output 4 values yet you only select 1 column value from the table. Therefore only $row[0] exists, containing the value from the ugroup column.
  5. FYI, You can use an alias in the HAVING clause, as the data has been retrieved by then and the alias allocated to the field, but you cannot use an alias in a WHERE clause condition
  6. An inner join to the appointments will select only dates where an appointment exists and is faster than left join SELECT DATE(start_time), totcalls FROM appointments a INNER JOIN ( SELECT DATE(time) as call_day , COUNT(*) as totcalls FROM calls GROUP BY call_day HAVING totcalls >= 150 ) as tot ON tot.call_day = DATE(a.start_time) GROUP BY DATE(start_time)
  7. foreach ($x as $k => $v) { $z[] = [$k,$v]; }
  8. Perhaps something like this <?php $sentences = array ( "By William Shakespeare on 30 July 2014", "By John Doe Tue Sep 23, 2014 6:33pm BST", "By Isaac Asimov on November 26th 2013, 3:47:09 pm", "By Robert Ludlum - Tue Sep 23, 2014 6:33pm BST", ); foreach ($sentences as $s) { if (strpos($s, ' on ', 0) !== false) { $split = ' on '; } elseif (strpos($s, ' - ', 0) !== false) { $split = ' - '; } else { echo $s . " (unchanged)<br>"; continue; // ignore and move on } list ($text, $date) = explode($split, $s); $d = new DateTime($date); $d2 = $d->format("Y-m-d"); echo "$text$split$d2<br>"; } ?> Which gives By William Shakespeare on 2014-07-30 By John Doe Tue Sep 23, 2014 6:33pm BST (unchanged) By Isaac Asimov on 2013-11-26 By Robert Ludlum - 2014-09-23 You should consider storing the the author and dates in separate fields.
  9. I would recommend that, when you do convert to a standard format, the format should be yyyy-mm-dd. Also, all those formats you gave will convert <?php $d1 = new DateTime("30 July 2014"); $d2 = new DateTime("November 26th 2013, 3:47:09 pm"); $d3 = new DateTime("Tue Sep 23, 2014 6:33pm BST"); echo $d1->format('Y-m-d'); //--> 2014-07-30 echo $d2->format('Y-m-d'); //--> 2013-11-26 echo $d3->format('Y-m-d'); //--> 2014-09-23 ?> That just leaves the problem of finding the dates in the sentences. That bit will probably have to be done manually. Perhaps a form with several pairs of fields. Put the sentence in the first field of each pair Copy/paste the date from the sentence to the second field of each pair. Submit the form To process, convert the date as above replace the date in the sentence with the converted date output the new sentences
  10. You mean to do the work for those too lazy to do it themselves? You already knew the solution to the problem. I see from your final code that you really were too idle to take the advice on correct code indenting to find the error yourself
  11. BTW, } else { <--------------- this currently matches with // UP TO HERE ?> <?php } <---------------- this one that you said was unmatched include 'includes/overall/footer.php'; ?>
  12. I think the purpose of his post was for us to do that for him
  13. You should never write data provided by users directly to the database without escaping it with mysqli_real_escape_string() to sanitize it. Or, better still, use prepared queries. Amongst other things, this will take care of the apostrophe problem for you.
  14. You have 2 unique keys in that table (contact_id and u_id). Your insert query provides no value for either of them therefore not duplicating a key value that already exists
  15. the comparison operator is "=="
  16. Means what? Do you get an error message? If so, what is it? What is the table structure (output from the query "SHOW CREATE TABLE database_name")?
  17. It would seem there are are only 162 records
  18. One way around the problem would be array('staff_last_login'=>date('Y-m-d H:i:s'));
  19. Do any of your columns contain null values - these are ignored by aggregation functions eg mysql> SELECT * FROM contact; +----+-------------+-------------+-------------+ | id | name | email | phone | +----+-------------+-------------+-------------+ | 1 | aaaaaaaaa | aaa@xyz.com | 12345674321 | | 2 | bbbbbbbb | b@abc.co.uk | NULL | | 3 | cccccccc | ccc@zzz.com | 01214567890 | | 4 | dddddd | dd@dd.com | NULL | | 5 | eeeeeeeeeee | eee@efg.com | NULL | | 6 | kkkkkkkkk | kkk@aaa.com | NULL | | 7 | mmmm | m@mmm.co.uk | NULL | +----+-------------+-------------+-------------+ 7 rows in set (0.00 sec) mysql> SELECT COUNT(*) FROM contact; +----------+ | COUNT(*) | +----------+ | 7 | +----------+ 1 row in set (0.00 sec) mysql> SELECT COUNT(phone) FROM contact; +--------------+ | COUNT(phone) | +--------------+ | 2 | +--------------+ 1 row in set (0.00 sec)
  20. If you know the cust_id and the prod_id and want to know if there is a notification recorded for it then query the notify table to see if there are any records for that prod/cust combination. SELECT COUNT(*) as total FROM notify WHERE prod_id = ? AND cust_id = ? If the count is > 0 then the there is already a notification in place.
  21. It often helps to echo $sql; and inspect the code that is actually being executed.
  22. The order of the function parameters also changes (refer to the manual) and the connection parameter is not optional as it is with mysql_xxx functions . Also not all functions have mysqli equivalent and mysqli has new ones.
  23. You need a structure similar to this +-------------+ +-----------+ | product | | customer | +-------------+ +------------+ +-----------+ | prod_id |----+ | notify | +-----| cust_id | | prod_name | | +------------+ | | cust_name | | stk_qty | | | cust_id |>--+ | etc | | etc | +----< | prod_id | +-----------+ +-------------+ +------------+ then you would query the tables to find those products in the customer's notify items that have stock SELECT p.prod_id , prod_name , stk_qty FROM product p INNER JOIN notify n USING (prod_id) WHERE stk_qty > 0 AND n.cust_id = ?
  24. You need to define the class and method names in an array, and not just the callback function name. eg $cleansed = array_map(array('mysqli', 'real_escape_string'), $_POST));
  25. The error message is telling you exactly what is wrong. You cannot have spaces in identifiers (table names, column names etc). If you do you need to enclose them in backticks (note: not single quotes) but it is better to avoid them completely. INSERT INTO `Damage Tickets` ...
×
×
  • 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.