Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do i fetch date and time from MySQL table row
    text
    copied!<p>i found an old blog script (very old) kicking around on my PC. im having troubles with fetching the date and time from my DB to display in PHP. Can someone help me.<br> This is my MySQL DB setup.</p> <pre><code>CREATE TABLE blog_posts ( id int(11) NOT NULL auto_increment, title varchar(30) NOT NULL default '', news text NOT NULL, poster varchar(15) NOT NULL default '', date timestamp(14) NOT NULL, PRIMARY KEY (id) ) TYPE=MyISAM; </code></pre> <p><br> And this is what im using to send a post:</p> <pre><code>&lt;?php include "db.php"; $title=$_POST['title']; $news=$_POST['news']; $poster=$_POST['poster']; $query="INSERT INTO $blogposts (title, news, poster) VALUES ('$title', '$news', '$poster')"; $result=mysql_query($query) or die (mysql_error()); mysql_close(); header("Location: post.php"); ?&gt; </code></pre> <p><br> And finally this is what im using to call the date on the front-end:</p> <pre><code>&lt;?php echo "posted on: - ".$day.".".$month.".".$year." at ".$hour.":".$min; ?&gt; </code></pre> <p><br> I'm no expert (clearly) but the call for the date doesnt look right to me. Anyone have any ideas on how i could make it work, or even make it better?? <br> EDIT::</p> <pre><code>&lt;?php include "db.php"; //query $query="SELECT * FROM ".$blogposts." ORDER BY id DESC LIMIT 0,$limit "; $result=mysql_query($query) or die (mysql_error()); //loop while($row=mysql_fetch_array($result)) { $querycomment = "SELECT ID FROM ".$newscomments." WHERE newsid=".$row['id']; $resultcomment=mysql_query($querycomment) or die (mysql_error()); $num_rows = mysql_num_rows($resultcomment); ereg("^([0-9]{4})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})([0-9]{2})",$row['date'],$res); $year=$res[1]; $month=$res[2]; $day=$res[3]; $hour=$res[4]; $min=$res[5]; $sec=$res[6]; ?&gt; </code></pre> <p><br></p> <p>Thanks</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload