TrippedStackers
TrippedStackers

Reputation: 423

Timestamp php style

I have the spans for how I want the date to show for CSS:

.date {
float:left;
position:relative;
margin-right:10px;
padding:45px 5px 0;

}

.date .month{
text-transform:uppercase;
font-size:25px;

}

.date .day{
font-size:35px;
line-height:45px;
position:absolute;
left:5px;top:0;

}

.date .year{
display:block;
position:absolute;
right:-5px;
top:15px;
-webkit-transform:rotate(-90deg);
-moz-transform:rotate(-90deg);
-ms-transform:rotate(-90deg);
-o-transform:rotate(-90deg)

}

which will eventually look like this, on the output of PHP : http://puu.sh/1uqZ2

and I as of now, have my CMS (news system) set up, but how would I go about making it look like the timestamp shown in that image? would I have to set each tag per line, like $day $month $year?

This is my current "addarticle.php" page:

<?php

$submit = $_POST['submit'];
$remove = $_POST['remove'];
$news_content = $_POST['newscontent'];
$news_title = mysql_real_escape_string($_POST['newstitle']);
$news_author = mysql_real_escape_string($_POST['newsauthor']);
$news_date = date("l, F jS Y");

if ($submit)
{

$namecheck = mysql_query("SELECT news_title FROM articles WHERE    news_title='$news_title'");
$count = mysql_num_rows($namecheck);

if ($count!=0)
{
    die ('<div class="red" style="margin-bottom: 0;">Article    <strong>'.$news_title.'</strong> already exists!</div>
    <meta http-equiv="REFRESH" content="2;url=index">
    ');
}

if ($news_title&&$news_content&&$news_author)
{

$query = mysql_query("

                 INSERT INTO articles VALUES  ('','$news_title','$news_content','$news_date','$news_author')

");
echo "<div class='green'>You have posted <strong>$news_title</strong> !</div>";

}else {

 echo '<div class="red">You must fill in all fields!</div>';
} 
}

?>

<form action="" method="POST">

Article Title :
<br />
<input name="newstitle" type="text" class="userpass" />
<br /><br />
Article Author :
<br />
<input name="newsauthor" type="text" class="userpass" value="<?php echo $_SESSION['username'] ?>" />
<br /><br />
Article Content :
<br />
<textarea id="elm1" name="newscontent" rows="7" cols="30" style="width: 100%">    </textarea>
<br />
<input name="submit" type="submit" class="button" value="Post News" />
<a href="viewarticle"><input name="edit" type="button" class="button" value="Edit Article" /></a>

</form>

Upvotes: 0

Views: 373

Answers (1)

danijar
danijar

Reputation: 34175

I assume that there is a data variable $date containing the article's date. In combination with your stylecheet the following code should output the date as shown in you example.

$day   = date('d', $date);
$month = date('m', $date);
$year  = date('Y', $date);

echo '<div class="date">'
         . '<span class="month"' . $month . '</span>'
         . '<span class="day">'  . $day   . '</span>'
         . '<span class="year">' . $year  . '</span>'
     . '</div>';

My code has nothing to do with SQL and assumes that you already have the date of the article. For a better answer you should remove all unnecessary code and provide us an minimal example.

I can't find a part in your code fetching the date from the database. Usually there is a id column in you database which is you primary key. If so, you could fetch the date of an article with this SQL query.

SELECT news_date FROM articles WHERE id = ...

Upvotes: 1

Related Questions