hello, I'm a php newb 😃
I'm having a little difficulty getting it to display the LAST row available I'm building my own blog you see
A friend of mine recommended this:
$number_of_records = mysql_num_rows($result);
$author = mysql_result($result,$number_of_records,"author");
But it's not having the desired effect 🙁
here's my full code
<html>
<body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
Enter your alias: <input type="text" name="author" />
Enter the title: <input type="title" name="title" />
<label>Type your review:<br />
<textarea name="text" rows="10" cols="40">
</textarea></label>
<input type="submit" value="Go!"/>
</form>
<?php
$dbcnx = @mysql_connect('mysql.lcn.biz', 'myusername', 'mypass');
if (!$dbcnx) {
echo 'Unable to connect to the ' .
'database server at this time.' ;
exit();
}
// Select the database
if (!@mysql_select_db('paintzone')) {
exit('<p>Unable to locate the ' .
'database at this time.</p>');
}
// Write to the fields
if (isset($_POST['text'])) {
$text = htmlentities($_POST['text']);
$author = htmlentities($_POST['author']);
$title= htmlentities($_POST['title']);
$sql = "INSERT INTO blog SET
text='$text',
author='$author',
title='$title',
date=CURDATE()";
if (@mysql_query($sql)) {
echo '<p>Your review has been added.</p>';
} else {
echo '<p>Error adding submitted review: ' .
mysql_error() . '</p>';
}
}
// Query All entries
$result = @mysql_query('SELECT * FROM blog');
if (!$result) {
exit('<p>Error performing query: ' .
mysql_error() . '</p>');
}
// Display all Entries
// $author=mysql_result($result, 0 ,"author");
//$date=mysql_result($result, 0 ,"date");
// $title=mysql_result($result, 0 ,"title");
// $text=mysql_result($result, 0 ,"text");
//Display last entry
$number_of_records = mysql_num_rows($result);
$author = mysql_result($result,$number_of_records,"author");
echo '<table><tr><td><center>' .$author .'</center></td><td><center>' .$date .'</center></td></tr><tr><td><center> ' .$title .'</center></td></tr><tr><td><center>' .$text .'</center></td></tr></table>';
?>
</body>
</html>