Jump to content

Archived

This topic is now archived and is closed to further replies.

Iryk

Division By Zero

Recommended Posts

I just started to use this script and it gives the error of:

Warning: Division by zero in /home/magneo/public_html/news/index.php on line 41

[code]<?
$url = "index.php?page=news";
$count_news = mysql_num_rows(mysql_query("SELECT * FROM news"));

if($count_news == 0) {
echo "<center>There is no news to display.</center>";
} else {

if (isset($_GET['pageno'])) {
   $pageno = $_GET['pageno'];
} else {
   $pageno = 1;
} // if
$query = "SELECT count(*) FROM news";
$result = mysql_query($query);
$numrows = mysql_num_rows($result);
$rows_per_page = 5;
$lastpage = ceil($numrows/$rows_per_page);
$pageno = (int)$pageno;
if ($pageno < 1) {
   $pageno = 1;
} elseif ($pageno > $lastpage) {
   $pageno = $lastpage;
} // if
$limit = 'LIMIT ' .($pageno - 1) * $rows_per_page .',' .$rows_per_page;
$query_ = "SELECT * FROM news ORDER BY id DESC $limit";
$result = mysql_query($query_);

while ($ro = mysql_fetch_array($result)) {
$id = $ro['id'];
$author = $ro['author'];
$title = $ro['title'];
$content = bbcode($ro['content']);
$date = $ro['postdate'];

$com_link1 = "<a href='$url/comments&id=$id'>";
$com_link2 = "</a>";
$com_count = "SELECT * FROM comments WHERE news_id='$id'";
$com_num = mysql_num_rows(mysql_query($com_count));
$filename = layouts/$theme/news_template.php;
if (is_readable($filename)) {
   include("layouts/".$theme."/news_template.php");
} else {
include("news/default_template.php");
}

if($count_news != 1 OR 0) {
echo "<center>";
if ($pageno == 1) {
   echo "Pages:";
} else {
   echo " <a href='$url/index&pageno=1'>FIRST</a> | ";
   $prevpage = $pageno-1;
   echo " <a href='$url/index&pageno=$prevpage'>$prevpage</a> ";
} // if
echo " <b>$pageno</b> ";
if ($pageno == $lastpage) {
   echo "";
} else {
   $nextpage = $pageno+1;
   echo " <a href='$url/index&pageno=$nextpage'>$nextpage</a> | ";
   echo " <a href='$url/index&pageno=$lastpage'>LAST</a> ";
}
echo "</center>";
}
}
}
?>[/code]

What am I doing wrong?

Share this post


Link to post
Share on other sites
[code]$filename = layouts/$theme/news_template.php;[/code]

should be

[code]$filename = 'layouts/' .$theme .'/news_template.php';[/code]

Share this post


Link to post
Share on other sites
What error are you getting now?

Did the last fix work on that that particular line of code?

Share this post


Link to post
Share on other sites
OMG!!! I edited the wrong page :P Sorry about that and yes it does work now :)

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.