Just a quickie, I hope. I'm making a little website for a friends band from Argentina, and have made a quick, basic php script which allows them to post stuff on a news page from a html form. Here's the php script for entering into the database:
Code:
<?php
$title = $_POST["title"];
$text = $_POST["text"];
$connection = mysql_connect("localhost","username","password") or die ("Couldn't connect to database server.");
$db = mysql_select_db("dbname" , $connection) or die("Couldn't select database.");
$sql = "insert into psychotoxic values ('$title', '$text')";
$sql_result = mysql_query($sql,$connection) or die("Couldn't execute query");
mysql_close($connection);
print "Information Accepted."
?>
This works completely fine, not a problem.
I have also made a script to extract 5 entries from the database, and place them in a html table:
Code:
<?php
include("logo.htm");
$connection = mysql_connect("localhost","usernamei","password") or die ("Couldn't connect to database server.");
$db = mysql_select_db("dbname" , $connection) or die("Couldn't select database.");
$sql = 'SELECT `title` , `text` ';
$sql .= 'FROM `psychotoxic` ';
$sql .= 'WHERE 1 LIMIT 0, 5';
$sql_result = mysql_query($sql,$connection) or die("Couldn't execute query");
echo "<br><br><table border=0 table width=700>";
while ($myrow = mysql_fetch_array($sql_result)) {
$title = $myrow["title"];
$text = $myrow["text"];
echo "
<tr>
<th>
<strong>$title</strong></th>
<tr><td><h1>
$text
</h1></td>
</tr>
";
}
echo "</TABLE>";
mysql_free_result($sql_result);
mysql_close($connection);
?>
This also works great, but I need it to extract the 5 newest entries rather than the 5 entries that were first entered into the database. I also need it to put the newest entry first, then going down the list as the entries get older.
I apologise for my English, bit tired at the moment If anyone could help me with figure out what I need to do, I'll greatly appreciate any comments/suggestions.