0

I getting this error and not sure how to fix it. Line 162 is the first line in the php code. I looked at some of the related questions and all my quote marks seem to be in the right place

Per page:
<input type=text name=per_page value="<?php echo $en['per_page']; ?>" size=6> 
Go to page:
<select name=page size=1>

<?php 
$pages = ceil(sql_num_rows($result)/$en['per_page']); 
for ($k=1;$k<=$pages;$k++) 
   echo '<option value='.$k.($en[page] == $k ? ' selected':'').'>'.
     $k.'</option>';

echo '</select>';   
if ($en[page]<$pages) 
   echo '<input type=submit name=next value="Next page">';
?>

6 Answers 6

3

Try to echo $en['per_page'] and make sure it's got the correct value. (I bet it doesnt).

Unrelated: $en[page] Should probably be $en['page'] (assuming page is really not a constant)

Sign up to request clarification or add additional context in comments.

1 Comment

something like this would fix the problem... $pages = ceil(sql_num_rows($result)/($en['per_page'] == '0' ? '20' : $en['per_page']));
3

What's the value of $en['per_page'] (I'm guessing zero)

Comments

2

Because you cannot have a denominator value of 0.

Check the value of $en['per_page'] > 0 prior to applying it to a division.

Comments

2

Any time you divide by a variable, if the variable is 0 you will get that error.

The way to prevent it would be to check to ensure that $en['per_page'] is not zero, since that appears to be your only division and is probably where your problem is.

Comments

1

If you're getting a divide by zero error, then $en['per_page'] may not be correct. It's probably a zero value.


Also, all your HTML attributes need to be in quotes. For example:

<input type=text name=per_page

Should be:

<input type="text" name="per_page"

Your array indexes should be quoted too.

$en[page]

Should be:

$en['page']

2 Comments

They don't need to be in quotes ;) XHTML says they must be, HTML says they can be - HTML spec
@Rudu: Ah, didn't realize that. I've used XHTML for so long, that I got used to quoting all attributes.
0

Here is the solution:

Per page:

<input type=text name=per_page value="<?php echo $en['per_page']; ?>" size=6> 

Go to page:

<?php 
$pages = @ceil(sql_num_rows($result)/$en['per_page']); 
for ($k=1;$k<=$pages;$k++) 
   echo '<option value='.$k.($en[page] == $k ? ' selected':'').'>'.
     $k.'</option>';

echo '</select>';   
if ($en[page]<$pages) 
   echo '<input type=submit name=next value="Next page">';
?>

Just used @ before ceil / division.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.