Jump to content


Photo

Division By Zero


  • Please log in to reply
4 replies to this topic

#1 Iryk

Iryk
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 18 March 2006 - 11:58 PM

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

<?
$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>";
}
}
}
?>

What am I doing wrong?

#2 theverychap

theverychap
  • Staff Alumni
  • Advanced Member
  • 78 posts
  • LocationDevon, England

Posted 19 March 2006 - 12:03 AM

$filename = layouts/$theme/news_template.php;

should be

$filename = 'layouts/' .$theme .'/news_template.php';


#3 Iryk

Iryk
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 19 March 2006 - 12:05 AM

It still not working :(

#4 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 19 March 2006 - 12:11 AM

What error are you getting now?

Did the last fix work on that that particular line of code?
follow me on twitter @PHPsycho

#5 Iryk

Iryk
  • Members
  • PipPip
  • Member
  • 25 posts

Posted 19 March 2006 - 12:13 AM

OMG!!! I edited the wrong page :P Sorry about that and yes it does work now :)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users