Jump to content

[SOLVED] Fatal error: Using $this when not in object context


bbunlock

Recommended Posts

I have a pagination function that I use and im currently re-designing my site and im using "xampp" on my windows pc to do all the work and testing localy instead of on an actual server

 

So far I have only come acrosss 1 error and thats with the pagination function, the xampp installed on my pc is using php 5 where my server is using pho 4, it works fine on 4 but not on 5.

 

the full error message is "Fatal error: Using $this when not in object context in C:\xampp\htdocs\cellmind\functions.php on line 314" and the code for the function is as follows

 

function specs_num($params, $itemFound, $imagesPerPage, $pg)
{
	$ntotal = $itemFound;
	$page_max = $imagesPerPage;
	$tp = 1 + (int)(($ntotal - 1) / $page_max);
	$page_ncur = 5; 
	$page_nlim = 2;

	$numofpages = ceil($ntotal / $page_max);

    if ($tp < 2) return;
    echo "<div class='pages_num' align=center>";
    $j = $pg - 1;

    echo "<span class='total_pages'>$numofpages Pages</span> ";
    
    if($pg==1);

    else{
    
    echo "<A href='{$params}".($pg != 1 ? $pg - 1 : $pg),"/'>Prev</A> ";
    
    }
        
    $i = max($pg - ($page_ncur - 1), 1);
    $p = min($pg + ($page_ncur - 1), $tp);
    for ($j = 1; $j <= $page_nlim && $j < $i; $j++)
      echo ($pg != $j ? "<A href='{$params}{$j}/'>{$j}</A> " : "<B>{$j}</B> ");
    if ($i > $page_nlim) echo ".. ";
    for (; $i <= $p; $i++)
      echo ($pg != $i ? "<A href='{$params}{$i}/'>{$i}</A> " : "<B>{$i}</B> ");
    if ($tp - $this->page_nlim > $p) echo ".. ";
    for ($j = max($p, $tp - $this->page_nlim) + 1; $j <= $tp; $j++)
      echo ($pg != $j ? "<A href='{$params}{$j}/'>{$j}</A> " : "<B>{$j}</B> ");
    echo "</SPAN>";
    
    $j = $pg + 1;
    
    if($pg==$numofpages);

    else{
    
    echo "<A href='{$params}".($pg != ceil($itemFound/$imagesPerPage) ? $pg + 1 : $pg)."/'>Next</A>";
    
    }
    echo "</div>";
    
}

 

I could still get this working ok by just uploading the files to the actual server for testing but that isnt going to help me when the server actualy goes to php 5.

 

I know very little about php and can get away with using it in a limited way but this is just beyond me, I have no idea whats wrong and how to solve this so if anyone can help me out that would be great.

 

thanks for your time and help

 

regards

 

wayne

Link to comment
Share on other sites

under first guess... i'd look at this

 

    if ($tp - $this->page_nlim > $p) echo ".. ";
    for ($j = max($p, $tp - $this->page_nlim) + 1; $j <= $tp; $j++)

 

i would think that should be

 

    if ($tp - $page_nlim > $p) echo ".. ";
    for ($j = max($p, $tp - $page_nlim) + 1; $j <= $tp; $j++)

Link to comment
Share on other sites

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.