sorting data/articles by date and time
Posted: Wed Oct 16, 2013 3:02 am
Hello,
I'm newbie in PHP. I would like to ask you guys for some advices if you are willing to help.
So I have created code. In it I additionaly added new column in database called articledate and I echo time of each article.
My question is how to display the articles by date and title in a list sorted by date and how to display the article content and clicking on the title?
Any help is very welcome.
Thanks
I'm newbie in PHP. I would like to ask you guys for some advices if you are willing to help.
So I have created code. In it I additionaly added new column in database called articledate and I echo time of each article.
My question is how to display the articles by date and title in a list sorted by date and how to display the article content and clicking on the title?
Any help is very welcome.
Thanks
Code: Select all
listitems.php
<body bgcolor="#225599" text=" #ffffff">
<font size="6">
<h3 align='center'>
<?php
include "mysql.php";
echo "Maviance GmbH newsletter:\n" . "<br/>";
$query = 'SELECT * FROM blogtable';
if(!$result = $db->query($query)){
die('There was an error running the query [' . $db->error . ']');
}
// Printing results in HTML
while($row = $result->fetch_assoc()){
echo $row['title'] . '
<br />';
}
$result->free();
$db->close();
?>
<form name="newarticle" action="newarticle.php" method="post">
<input type="submit" value="New article" style="height: 60; width: 170"/>
<h3>
<a href="content.php" style="font-size: 20px; text-decoration: none; color: #FFFFFF ">Read more about us here</a>
</body>
</html>
</form>
</body>
</html>
newarticle.php
<html>
<head>
</head>
<body bgcolor="#225599" text="#ffffff">
<h3>
<form action="insert.php" method="post">
Title: <input type="text" name="title" ><br>
Summary: <textarea rows="10" cols="60" name="summary" wrap="physical">Here goes your summary!</textarea>:<br /><br>
Content: <textarea rows="20" cols="150" name="content" wrap="physical">Hey Buddy! Enter text in our blog!</textarea>:<br />
<input type="submit" value="submit" name="submit" align=right>
<?php
//connect to db
include "mysql.php";
mysqli_query($db,"INSERT INTO blogtable (title, summary, content)
VALUES ('', '',)");
mysqli_close($db);
?>
</form>
<h3>
</body>
</html>
insert.php for the newarticle.php
<?php
include "mysql.php";
$sql="INSERT INTO blogtable (title, summary, content)
VALUES
('$_POST[title]','$_POST[summary]','$_POST[content]')";
if (!mysqli_query($db,$sql))
{
die('Error: ' . mysqli_error($db));
}
echo "1 record added";
mysqli_close($db);
?>
content.php
<head>
</head>
<body bgcolor="#225599" text="#ffffff">
<h3>
<?php
//connect to db
include "mysql.php";
$query = 'SELECT * FROM blogtable';
if(!$result = $db->query($query)){
die('There was an error running the query [' . $db->error . ']');
}
// Printing results in HTML
while($row = $result->fetch_assoc()){
echo $row['title'] . '
<br /><br />';
echo $row['summary'] . '
<br /><br /><br />';
echo $row['content'] . '
<br /><br /><br />';
}
$result->free();
$db->close();
echo"radi!!!!!!";
?>
</form>
<h3>