Forum Moderators: coopster
error:Page number is not defined!
here's the code i got that error from:
<?
if(empty($_GET['page'])) {
echo 'Page number is not defined!';
exit();
}
else if(!preg_match("/^([0-9])+$/",$_GET['page'])) {
echo 'Page is not a valid value!';
exit();
}
$num_per_page = (empty($_GET['num']))? 10 : $_GET['num'];
if(!preg_match("/^([0-9])+$/",$num_per_page)) {
echo 'Num is not a valid value!';
exit();
}
$page = $_GET['page'];
include_once($_SERVER['DOCUMENT_ROOT'] ."/assets/includes/sqlconfig.php") ; //vconnection (no problems here)
$qPage = (($page-1)*$num_per_page);
$sql = "SELECT * FROM dir WHERE approved = 'yes' ORDER BY name ASC ".$qPage.",".($num_per_page+1);
$result = mysql_query($sql);
$num = mysql_num_rows($result);
if($num == 0) {
echo 'No more results!';
exit();
}
for($i = 0; $i < $num_per_page; $i++) {
include($_SERVER['DOCUMENT_ROOT'] ."/assets/includes/fieldvars.php") ;
$row = mysql_fetch_array($result);
?>
<p><strong><?php echo $name ?></strong> <?php echo $address ?><br/>
<?php echo $description ?><br/>
<em>phone: <?php echo $phone ?> ¦ tollfree: <?php echo $tollfree ?> ¦ fax: <?php echo $fax ?> <br/>
website: <?php echo $website ?> ¦ email: <?php echo str_replace("@", "<img src=\"/assets/images/e.gif\" alt=\"\">", $email) ?></em></p>
<?php
}
mysql_close($dbh);
if($num > $num_per_page) {echo '<a href="index.php?page='.($page+1).'&num='.$num_per_page.'">Next Page</a>';}
echo '<br/>';
if($page > 1) {echo '<a href="index.php?page='.($page-1).'&num='.$num_per_page.'">Previous Page</a>';}
?>
In addition, I'd suggest that page one shouldn't require a number in the first place. You could achieve this by setting a default page in the first few lines, rather than an error:
if(empty($_GET['page'])) {
# two lines below commented out
#echo 'Page number is not defined!';
#exit();
# if no page is specified, use page 1.
$_GET['page']=1;
}
[edited by: Receptional_Andy at 8:09 pm (utc) on June 5, 2008]
but now i get these errors:
Warning: mysql_num_rows(): supplied argument is not a valid MySQL result resource in /home/gogab/public_html/full.php on line 38
No more results!
Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/gogab/public_html/full.php on line 46
here's my code
<?
if(empty($_GET['page'])) {
$_GET['page']=1;
}
else if(!preg_match("/^([0-9])+$/",$_GET['page'])) {
echo 'Page is not a valid value!';
}
$num_per_page = (empty($_GET['num']))? 10 : $_GET['num'];
if(!preg_match("/^([0-9])+$/",$num_per_page)) {
echo 'Num is not a valid value!';
}
$page = $_GET['page'];
include_once($_SERVER['DOCUMENT_ROOT'] ."/assets/includes/sqlconfig.php") ;
$qPage = (($page-1)*$num_per_page);
$sql = "SELECT * FROM dir WHERE approved = 'yes' ORDER BY name ASC ".$qPage.",".($num_per_page+1);
$result = mysql_query($sql);
$num = mysql_num_rows($result);// line 38
if($num == 0) {
echo 'No more results!';
}
for($i = 0; $i < $num_per_page; $i++) {
include($_SERVER['DOCUMENT_ROOT'] ."/assets/includes/fieldvars.php") ;
$row = mysql_fetch_array($result) ;//line 46
?>
<p><strong><?php echo $name ?></strong> <?php echo $address ?><br/>
<?php echo $description ?><br/>
<em>phone: <?php echo $phone ?> ¦ tollfree: <?php echo $tollfree ?> ¦ fax: <?php echo $fax ?> <br/>
website: <?php echo $website ?> ¦ email: <?php echo str_replace("@", "<img src=\"/assets/images/e.gif\" alt=\"\">", $email) ?></em></p>
<?php
}
mysql_close($dbh);
if($num > $num_per_page) {echo '<a href="index.php?page='.($page+1).'&num='.$num_per_page.'">Next Page</a>';}
echo '<br/>';
if($page > 1) {echo '<a href="index.php?page='.($page-1).'&num='.$num_per_page.'">Previous Page</a>';}
?>
any hwlp would be hugely appreciated thanks!
try
$sql = "SELECT * FROM dir WHERE approved = 'yes' ORDER BY name ASC LIMIT ".$qPage.",".($num_per_page+1);