leatherback wrote:you are testing for $numrows > 3 instead of <3.
I fixed that, just a stupid mistake, thanks .....
leatherback wrote:
that being said.. A lot can be tweaked on your code...
First of all.. Why do you have all the processing on your variables? Ideally you do these things before inserting the variables, so you minimize processing for displaying (Which is going to be the most frequent process).
Not sure I get you here, but please share this with me, I am always into learning and improving
leatherback wrote:
Fruthermore:
please
$num_rows = mysql_num_rows($r);
outside the while loop
Done but in the following code:
if ($r = mysql_query($query)) // Run the query.
{
$num_rows = mysql_num_rows($r);
// Retrieve and print every record.
while ($row = mysql_fetch_array($r))
{
list($id, $title, $entry, $date) = $row;
//$date = date("F d, Y");
$title = htmlspecialchars($title);
$title2 = trim(strtolower(str_replace(' ', '-', $title)));
$entry = nl2br($entry);
$cut = substr($entry, 0, 290);
$new_text = substr($cut, 0, strrpos($cut, ' '));
if ($num_rows == 0)
{
echo "<h1>There are no stories in this category</h1><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br />";
}
else
if ($num_rows == 1)
{
echo "<h1>{$title}</h1>{$date}<br />
<p>{$new_text}<br /><a href=\"" . $rooturl . "$title2.html\">View full story</a></p><br /><br />
<br />\n<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br />";
}
else
if ($num_rows == 2)
{
echo "<h1>{$title}</h1>{$date}<br />
<p>{$new_text}<br /><a href=\"" . $rooturl . "$title2.html\">View full story</a></p><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />";
}
else
if ($num_rows <= 3)
{
echo "<h1>{$title}</h1>{$date}<br />
<p>{$new_text}<br /><a href=\"" . $rooturl .
"$title2.html\">View full story</a></p><br />";
}
else
{
echo "<h1>{$title}</h1>{$date}<br />
<p>{$new_text}<br /><a href=\"" . $rooturl .
"$title2.html\">View full story</a></p><br />";
}
}
echo '<a href="' . $rooturl . 'categoryarchive.php?catid=' . $cid->id .
'">View all News in this category</a>';
}
if a category does not have any articles in it, according to this code, it should return the first IF statement, that is not working, but the rest is
example 1 story > http://www.mikesimonds.com/parenting/ (working per code)
example 3 stories > http://www.mikesimonds.com/people/ (working per code)
example no stories > http://www.mikesimonds.com/techincal/ (not working)
thanks so much for the help, i appreciate it!