ambo Posted May 23, 2016 Share Posted May 23, 2016 <?php $notesget = mysql_query("SELECT * FROM notes ORDER BY note_date"); // selecting data through mysql_query() $notesfill = mysql_fetch_array($notesget); $notedate = $notesfill['note_date']; $time = strtotime($notedate); $notedateformat = date("n/j g:ia", $time); // we are running a while loop to print all the rows in a table echo'<tr>'; // printing table row echo '<td id="notename" align="right">'.$notesfill['note_user'].'</td></tr><tr><td id="notedata">'.$notesfill['note_data'].'</td></tr><tr><td id="notedate" align="right">'.$notedateformat.'</td></tr>'; ?> Having trouble looping data after date formatting Quote Link to comment https://forums.phpfreaks.com/topic/301242-issue-looping-data-from-table/ Share on other sites More sharing options...
Solution ambo Posted May 23, 2016 Author Solution Share Posted May 23, 2016 never mind I figured it out Quote Link to comment https://forums.phpfreaks.com/topic/301242-issue-looping-data-from-table/#findComment-1533178 Share on other sites More sharing options...
Psycho Posted May 24, 2016 Share Posted May 24, 2016 FYI: There are a few things you should look into changing. 1. The mysql_ extentions have been deprecated for a long time now. Use mysqli_ or, better yet, PDO for DB operations. 2. Do not use "SELECT *". It may not be an issue in most cases, but it is bad form and could lead to security problems or bugs in some cases if you are not careful. It's always best to list out the fields you want. 3. There's no reason for creating all those temporary variables to get the datetime into the format you want. It's just adding unnecessary overhead. You could just do this: $notedateformat = date("n/j g:ia", strtotime($notesfill['note_date'])); or you could set the format is the SELECT parameters. Quote Link to comment https://forums.phpfreaks.com/topic/301242-issue-looping-data-from-table/#findComment-1533180 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.