Jump to content

Notice: Undefined variable


FUNKAM35

Recommended Posts

$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num  FROM rental  WHERE  $where "),0) ;
$total_pages = ceil($total_results/$max_results);
if ($total_results > $max_results) {
if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page2 = $_GET['page'];
}
$from =(($page * $max_results) -  $max_results );
		}
if($page2>1)
{
	$pages="Page $page2 of $total_pages";
}

Hi, I have added the above code and it works fine except I get this error Notice: Undefined Variable $pages

I only get this error on page 1 where it doesn't show page 1 of x as I don't want it to show page 1 of x

no errors on eg page 2 of x

only on page 1 I think because the pages is empty but don't know how to fix this

Any help would be appreciated

Link to comment
https://forums.phpfreaks.com/topic/286474-notice-undefined-variable/
Share on other sites


$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM rental WHERE $where "),0) ;
$total_pages = ceil($total_results/$max_results);
if ($total_results > $max_results) {
if(!isset($_GET['page'])){
$page = 1;
} else {
$page2 = $_GET['page'];
}
$from =(($page * $max_results) - $max_results );
}
if($page2>1)
{
$pages="Page $page2 of $total_pages";
}
else
{
$pages="Page $page of $total_pages";

}
$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num  FROM rental  WHERE  $where "),0) ;
$total_pages = ceil($total_results/$max_results);
if ($total_results > $max_results) {
if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page2 = $_GET['page'];
	
	
$from =(($page * $max_results) -  $max_results );
		}

if($page>1)
{
	$pages="Page $page of $total_pages";
}
else
{
	$pages="";

}
}

Thanks Paddyfields, this didn't quite work but pointed me in the right direction and this code did work:

Archived

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

×
×
  • Create New...

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.