Jump to content


Cannot send variables to my class


2 replies to this topic

#1 The Creator

    Young Padawan

  • Members
  • Pip
  • 115 posts
  • Gender:Male
  • Location:England
  • Interests:Computers, Music, Technology, Sport

Posted 27 March 2008 - 09:31 AM

Ok, im back, and probably not for the last time. The situation i have here is that i've made a class to do pagination but what it does is irrelevant. I am trying to pass variables to it in the normal fashion but it just isn't working. Here is the code from firstly the class itself and then from where i am sending the variables.

class pagination
{

var $url; // the url of where it is being initialized so links to other pages can be made accordingly
var $username; // the username of the person viewing the page
var $page; // which page it is (1, 2, 3 etc)

$pages = new pagination;

$pages->url = 'http://www.example.com/user/section/%P/'; // %P will be replaced by numbers in the class
$pages->username = $u['username']; // this is part of an array that stores the username
$pages->page = $extra; // this is a $_GET variable saying which page it is

the class seems to have been initialized properly... it just doesn't get the variables! what an earth is wrong? help if you can, all comments appreciated.

The Creator

#2 rc69

    PHP Master PD

  • P2L Staff
  • PipPipPipPip
  • 3,827 posts
  • Gender:Male
  • Location:Here
  • Interests:Web Development

Posted 27 March 2008 - 01:11 PM

add the following at the bottom of the second block of code you posted:
die('<pre>'.htmlspecialchars(print_r($pages,1)).'</pre>');
Then paste the results here.

Also, may i ask how you know that the variables aren't being set? Could you post the function you're trying to access them in?

#3 The Creator

    Young Padawan

  • Members
  • Pip
  • 115 posts
  • Gender:Male
  • Location:England
  • Interests:Computers, Music, Technology, Sport

Posted 27 March 2008 - 03:57 PM

pagination Object
(
	[url] => http://www.box46.com/user/videos/XBP/
	[username] => The Creator
	[page] => 1
)

thats what i get from ur pre thing.

and as for knowing that the variables aren't sent...

i made a constructor function which just echoed the variables and it had no output...

the function that im using (although it isnt the only one) looks like this:

	function query($query)
	{
	

	if($this->safety() == true){
	
	$rows = $this->rows_per_page();
	
	$start = ($rows * ($this->page - 1)) + 1;
	$end = ($rows * $this->page);
	
	str_replace('XBS', $start, $query);
	str_replace('XBE', $end, $query);
	
	return $query;
	
	} else {
	
	return 'Error';
	
	}
	}

i'll explain the idea behind it...

to call it you go like this:

$page = new pagination;

$query = mysql_query($page->query("SELECT * FROM `whatever` WHERE `something` = `thing` ORDER BY `id` LIMIT XBS, XBE"));

so the function replaces the XBS and the XBE with the relevant start and end numbers which it works out from another function.

this might not be the best way of doing this, but im just doing it from my head so don't critisize it too much please :)

thanks again,

The Creator

Edit
Ok, ive come alot further with this and ive changed it now. I only have one problem left! (i hope). If you look in the query function, it seems that str_replace isn't working...

why not?! haha

EDIT: oh right no variable in front... silly me

thanks again,

The Creator

Edit again
ok its all fixed, just needed an hour of debugging :huh:

thanks for the help,

The Creator

Edited by rc69, 28 March 2008 - 02:00 PM.






1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users