Jump to content

Notice: Undefined variable


Go to solution Solved by 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";

}
  • Solution
$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:

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.