Jump to content

Issue looping data from table


ambo
Go to solution Solved by ambo,

Recommended Posts

<?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

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.