Forum Moderators: coopster
I am just three months old in scripting with PHP and am encountering some problems for which I'd like to request your help.
I have one table called 'articles' in the MySQL database whose goals is to store messages sent by visitors to my website.
Before I deleted offline some records of that table that I had myself inserted using PHP, I could see all the articles showing up on the webpage, but after I deleted some articles from that table, I can see from that table that some records are not showing up any more on the webpage this, both offline and online.
Can somebody tell me the reason why I only can retrieve a part of the recods?
The SQL query code looked like this:
// some content before the sql query (not necessary here)...
// create SQL query
$sql =" SELECT * FROM articles ORDER BY article_id DESC LIMIT 0, 30";
$result = mysql_query($sql, $darconn) or die(mysql_error());
$row = mysql_fetch_assoc($result);
if ($_GET &&!$_POST) {
if (isset($_GET['article_id']) && is_numeric($_GET['article_id'])) {
$article_id = $_GET['article_id'];
}
else {
$article_id = NULL; }
}
?>
In the body section the code retrieving the articles with option to update or delete (actually it's my admin page) the records is as follows:
<?php while($row = mysql_fetch_assoc($result)) {?>
<tr>
<td><?php echo $row['name'];?></td>
<td style="padding-left:30px;"><?php echo $row['title'];?></td>
<td style="text-align:left; padding-left:30px;"><?php
$extract = substr($row['content'], 0, 100);
$lastSpace = strrpos($extract, ' ');
if(strlen($row['content']) <= 101) {
echo $row['content'];
}
else {
echo '<p>'.substr($row['content'], 0, $lastSpace).'(<a href="article.php?article_id='.$_GET['article_id'].'">Read More...</a>)</p>';
}
?>
</td>
<td style="padding-left:30px; text-align:left;" ><a href="update_article.php?article_id=<?php echo $row['article_id'];?>">EDIT</a> </td>
<td style=" border-right: 0px ; padding-left:30px; text-align:left; border-right:1px dotted red;" ><a href="delete_article.php?article_id=<?php echo $row['article_id'];?>">DELETE</a></td>
</tr>
<?php }
?>
Any idea of what went wrong preventing me therefore from retrieving all the records?
I'll be very greatful to anybody with the right answer to this problem;
Kind regards,
Dbarasuk B.
maybe just try removing the LIMIT clause in your query
from
$sql =" SELECT * FROM articles ORDER BY article_id DESC LIMIT 0, 30";
to
$sql =" SELECT * FROM articles ORDER BY article_id DESC";
I am guessing that should do it. I imagine you didn't notice at first because there were less than 30 results
Your proposition is a bit magic because it almost solved my problem. Why do I say almost? because the last record in Mysql still does not come to the wepage.
normally, the statement "order by article_id desc" let me expect that it's indeed that last record that would come first on the webpage, however it's exactly that one to be missing.
Any more suggestion, please?
thanks,
D B.