my page numbering function just doesnt seem to wanne work right
anyone can spot the error quickly?
the way it basically works:
- I pass it an array of url variables with the corresponding values, the current page number and the total number of pages to be created, depending on the query/ user settings
- the url is created dynamically
- the function highlights the current active page depending on the url
- it displays the next 2 page numbers and the last 2 page numbers for each page viewed
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]
Foo wrote:The last shot shows this setting in action:
$end_key = ($total_pages);
$end_key2 = ($total_pages-1);
When you get to the penultimate page, it's both the active page and the second to last page, both of which are always echoed to the document.
Your system of bolding the current page means than both of them turn out bolded, of course.
To get around this you can check if ($page == $end_key2) and stop one of the 2 being printed.
You're already doing this check for the 'next key' page number, but not for the active page.
I know what you mean, but there is only one instance where a page number is echoed without a link attached, when I add conidtions the line, it doesnt show at all
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]
Wow, difficult code. I'd almost be suggesting re-writing the whole thing to not include wierd arrays and such... because i'm having a real hard time stepping through your code in my head. Some suggestions though:
should " && ($next_key<$total_pages) "(44) and " && ($next_key<$total_pages) "(48) be <= instead of < ? it shouldn't matter, but worth a shot i suppose.
otherwise, try debugging by appending 'curkey'/'nextkey2' etc. to all your echo's, and see which little bit is fucking with your code.
otherwise, ditch the wierd array&foreach thing, and try a more elegant for($i=0;$i<=$total_pages;$++i;)-style loop? good luck.
eugh, classes. although i'm getting into using them properly now (albeit only for my database and global functions), it's a pain in the ass when a global function has to do a mysql query, and the sql query function needs to refer to it's own variables -- it all falls down, because "$this" becomes unusable.
although i could replace all the calls to $this->link with call_user_class_variable('mysql', 'link'); or something to that effect, i'd rather not go completely overkill on my code.
Totally unrelated to your PHP, but at first glance your graphical elements are completely confusing. The vertical line next to the cover graphic makes the eye travel in trying to coorelate the info to the image. Get rid of it
glossy wrote:eugh, classes. although i'm getting into using them properly now (albeit only for my database and global functions), it's a pain in the ass when a global function has to do a mysql query, and the sql query function needs to refer to it's own variables -- it all falls down, because "$this" becomes unusable.
although i could replace all the calls to $this->link with call_user_class_variable('mysql', 'link'); or something to that effect, i'd rather not go completely overkill on my code.
....what?
You can't get at those variables from outside the class because that's part and parcel of the security model of classes.
If you need to access an item from outside a class then you need to create a method within that class to return the variable. It just means adding 3 lines of extra code into the class for each variable you want to be accessible outside the class.
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]
glossy wrote:eugh, classes. although i'm getting into using them properly now (albeit only for my database and global functions), it's a pain in the ass when a global function has to do a mysql query, and the sql query function needs to refer to it's own variables -- it all falls down, because "$this" becomes unusable.
although i could replace all the calls to $this->link with call_user_class_variable('mysql', 'link'); or something to that effect, i'd rather not go completely overkill on my code.
....what?
You can't get at those variables from outside the class because that's part and parcel of the security model of classes.
If you need to access an item from outside a class then you need to create a method within that class to return the variable. It just means adding 3 lines of extra code into the class for each variable you want to be accessible outside the class.
class mysql {
protected $link;
public function query($sql) {
if (!$this->link) // line 5, errors.
return FALSE;
return mysql_query($sql);
}
public function fetch_array($result) {
if (!$this->link) // also errors, but doesn't get a chance.
return FALSE;
return mysql_fetch_assoc($result);
}
}
class globalsettings {
public function getuser($uid) {
$result = call_user_func(array('mysql', 'query'), 'SELECT * FROM `users` WHERE `uid`='. $uid);
return call_user_func(array('mysql', 'fetch_array'), $result);
}
}
$db = new mysql;
$gs = new globalsettings;
print_r($gs->getuser(1));
running this code will result in an error on line 5 stating "$this->link" doesn't exist because the query function isn't being run in the usual context, and $link only applies inside $db.
class globalsettings
{
private $db;
function globalsettings(&$db)
{
// add error checking to make sure db is valid object
$this->db = $db;
}
function getuser($id)
{
$result = $this->db->query('SELECT * FROM `users` WHERE `uid`=' . $id);
return $this->db->fetch_array($result);
}
}
class globalsettings {
// settings
public $gzip = true;
private $db = NULL;
// constructor
public function globalsettings(&$db) {
$this->db = $db;
}
error checking shouldn't be necessary, because if the database connection fails, or if the database object is fucked anyway, it'll throw a critical error anyway (since the whole application is database-orientated it won't work at all without)
I've gotten into the habit of putting in error checking in all sort of places in my code as a way to uphold my own internal model of how the program should work. i've found this helps me greatly months later when i'm debugging and i've forgetten how i set everything up.
in the above example, i'd put a check in the constructor that would make sure i wasn't passing the class a null db. this could come back to haunt me later when i get mysterious database error messages and can't figure out why. but if i put a two line piece of code in the constructor,
if (isset($db) == false)
die ("YOU DIDN'T PASS A VALID DB OBJECT TO THE GLOBAL SETTINGS CLASS YOU FUCKING IDIOT");
then it'll be clear where exactly the problem lies. perhaps this isn't the best example, but more and more often (especially with php and it's lack of an active debugger) i've been sprinkling these vulgar die messages in my code as a way to make sure the logic that's flowing in my head while writing code will be followed ten months down the line when i've forgotten everything.
EDIT: actually, the db reference wouldn't work if you set it after the constructor call because there is no valid reference to begin with. duh
if (isset($db) == false)
die ("YOU DIDN'T PASS A VALID DB OBJECT TO THE GLOBAL SETTINGS CLASS YOU FUCKING IDIOT");
ROFL
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]
btw, thx for teh help people, will tinkle about it 2day
[i]And shepherds we shall be, for thee my Lord for thee, Power hath descended forth from thy hand, that our feet may swiftly carry out thy command, we shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine patris, et fili, et spiritus sancti.[/i]