ianhaney50 Posted November 4, 2015 Share Posted November 4, 2015 Hi I am trying to work out how to display a specific number of characters in a echo row, the line looks like the following echo "<td>" . $row->comments . "</td>"; Thank you in advance Sorry I did look on Google but couldn't see a way to do it with the similar coding I have above Quote Link to comment Share on other sites More sharing options...
Solution Ch0cu3r Posted November 4, 2015 Solution Share Posted November 4, 2015 Use substr Example echo "<td>" . substr($row->comments, 0, 100) . "</td>"; Will only show the first 100 characters from the string stored in $row->comments Quote Link to comment Share on other sites More sharing options...
ianhaney50 Posted November 4, 2015 Author Share Posted November 4, 2015 Thank you so much, works perfect I just found another little issue when testing, the record date is being inserted into the mysql table as 00/00/0000 instead of the actual date, I am using datepicker, the INSERT query is below // insert the new record into the database if ($stmt = $mysqli->prepare("INSERT repairs (customer_name, customer_email, customer_phone, computer_make, computer_model, technician, status, exrdate, exrtime, exstdate, exstime, deltype, comments) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")) Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 4, 2015 Share Posted November 4, 2015 Most likely MySQL is unable to interpret the date being in DD/MM/YYYY format. If you have set your column as date(time) format then MySQL requires dates to be inserted in YYYY-MM-DD format. So before inserting the date you need to convert it to use that format. You can use PHP's DateTime object to do so // your date value in DD-MM-YYYY format $date = '4/10/2015'; // convert date to YYYY-MM-DD format $dt = new DateTime($date); $date = $dt->format('Y-m-d'); Quote Link to comment Share on other sites More sharing options...
ianhaney50 Posted November 4, 2015 Author Share Posted November 4, 2015 I just tried that and didn't work still, I added it directly above the insert query Quote Link to comment Share on other sites More sharing options...
ianhaney50 Posted November 4, 2015 Author Share Posted November 4, 2015 I renamed the $date to the name of $exrdate and it worked but it outputted the date as 10/4/2015 instead of 4/10/2015 and also it should be 4/11/2015 not 4/10/2015 also how do I get that to work for a second date as well as I have exrdate and exstdate Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted November 4, 2015 Share Posted November 4, 2015 Post your code. It should be outputting the date in YYYY-MM-DD Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.