-
Posts
24,563 -
Joined
-
Last visited
-
Days Won
822
Everything posted by Barand
-
Select multiple columns from two tables for searching
Barand replied to josephbupe's topic in PHP Coding Help
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? -
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.
-
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
-
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)
-
foreach ($x as $k => $v) { $z[] = [$k,$v]; }
-
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.
-
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
-
Parse error: syntax error, unexpected end of file
Barand replied to Paul_Withers's topic in PHP Coding Help
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 -
Parse error: syntax error, unexpected end of file
Barand replied to Paul_Withers's topic in PHP Coding Help
BTW, } else { <--------------- this currently matches with // UP TO HERE ?> <?php } <---------------- this one that you said was unmatched include 'includes/overall/footer.php'; ?> -
Parse error: syntax error, unexpected end of file
Barand replied to Paul_Withers's topic in PHP Coding Help
I think the purpose of his post was for us to do that for him -
Storing characters in MYSQL Database via a form
Barand replied to OsirisElKeleni's topic in MySQL Help
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. -
Upon form submit, if record exists update it, else insert
Barand replied to kjetterman's topic in MySQL Help
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 -
Let certain usernames and Messages appear in its own color
Barand replied to cobusbo's topic in PHP Coding Help
the comparison operator is "==" -
Upon form submit, if record exists update it, else insert
Barand replied to kjetterman's topic in MySQL Help
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")? -
It would seem there are are only 162 records
-
One way around the problem would be array('staff_last_login'=>date('Y-m-d H:i:s'));
-
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)
-
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.
-
It often helps to echo $sql; and inspect the code that is actually being executed.
-
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.
-
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 = ?
-
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));
-
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` ...