Jump to content

redbullmarky

Staff Alumni
  • Posts

    2,863
  • Joined

  • Last visited

    Never

Everything posted by redbullmarky

  1. more than likely you're missing a closing bracket } for one of your control structures. check they're all present and correct and try again. the error you're getting is because it can't determine where the error is, as php cant pinpoint where the closing bracket should go.
  2. http://www.devarticles.com/c/a/PHP/Object-Oriented-Programming-in-PHP/ is a good start to get the basics down. Further from that, the best way to learn is to get your hands dirty and look at OOP in action. I personally learnt by downloading a copy of phpBB (and other PHP packages) and looking at the code. the good thing about OOP is you can keep it as basic or make it as complex as you like. for example, the 'simpleclass' i put down a couple of posts up is a fully working class (albeit not very useful). keep it simple and move from there, as it can get messy (as i'm realising now ... :) )
  3. in php it can have a few uses. for the one you mention, you're right - it involves OOP. to keep it simple, take the class: [code] <?php class simpleclass {    function add($a, $b)    {       $result = $a + $b;       return $result;    } } ?> [/code] using the -> is a way of referencing a method (function) within a class. so: [code] $test = new simpleclass(); echo $test->add(5,10); // returns 15 [/code] from your code, all i can see is that you  maybe missing a few 'echo' statements. so: [code] <p>"<?php echo $quote->quote ?>" -- <?php echo $quote->author ?></p> <p>Quote Number <?php echo $quote->id ?></p> [/code]
  4. lol if it works and doesnt throw an error, then technically its perfectly valid syntax...i even (sadly) went and had a play around with it. i can safely say that it'll never end up in anything i ever do :)
  5. i cant think of any reason why you'd need to use ==! as the whole logic of it is a little mindblowing. this would mean $a not equal to $b: $a!==$b this would mean $a equal to not $b. so if $b is set, or true, !$b = false . if $b not set or is false, $!b = true $a==!$b
  6. fair does. it was written for PHP4 although some bits are there to take advantage of 5, so maybe that could be a reason... what i'm trying to work out is the best structure for my framework, and CI is so far the easiest to understand (apart from the above point) and well organised. the way i've thought about it is to have an object registry (singleton or function used to retrieve it from other classes). my individual modules extend the controller which extends my core. a core method, "loadLibrary" actually allows me to load classes (like template engine, db handling, etc) on the fly - like a plugin architecture, and these are available in my modules by: $this->$libraryname (eg, $this->template->draw, $this->db->query). the entire thing is kept in the registry and retrieved with Registry::Load('Core'), so that classes that arent descendents of the main structure can use the main structures bits and pieces. That probably didnt make a hell of a lot of sense, and it's possibly fair to say that i'm stepping out of my (current) depth right now, but if you grasp what i'm doing above, then by all means point out if i'm doing something terribly wrong.
  7. $choice does not appear to get a value from anywhere, effectively meaning non of these: [code] if ($choice == "allnappies") {$result = @mysql_query('SELECT * FROM stocks WHERE alphatype = "NAPPY" AND display = "yes" ORDER BY id ASC'); } elseif ($choice == "onesize") {$result = @mysql_query('SELECT * FROM stocks WHERE sizetype = "One Size" AND display = "yes" ORDER BY id ASC');} elseif ($choice == "multisize") {$result = @mysql_query('SELECT * FROM stocks WHERE sizetype = "Multi Size" AND display = "yes" ORDER BY id ASC');} [/code] will get executed and meaning that $result, which you expect to be the result of a query, will not get set,resulting in the error you've gotten here. it's worth noting that in many cases, using the error suppressor (@) can make debugging pretty tricky. as the error coming back from mysql_query will only be stuff like not being able to connect to the database, or invalid SQL, you'd be better doing a proper check elsewhere - i.e, let the mysql_query's throw errors if they have to, so you can fix them. something like: [code] <?php // first make sure we actually have a choice if ($choice) {   $query = '';   // using switch to simplify all the ifs/elses etc   switch ($choice)   {       case 'allnappies':         $query = 'SELECT * FROM stocks WHERE alphatype = "NAPPY" AND display = "yes" ORDER BY id ASC';         break;       case 'onesize':         $query = 'SELECT * FROM stocks WHERE sizetype = "One Size" AND display = "yes" ORDER BY id ASC';         break;       case 'multisize':         $query = 'SELECT * FROM stocks WHERE sizetype = "Multi Size" AND display = "yes" ORDER BY id ASC';         break;   }   // if we have a query, run it.   if ($query)   {       $result = mysql_query($query) or die('Problem with '.$query);       // rest of code here...   }   else   {       echo 'Invalid choice';       die;   } } else {   echo 'No choice specified';   die; } ?> [/code]
  8. just before you redirect to the login page, couldnt you pass the current page name (inc. params) in the URL? ie, [code] $ref = urlencode($_SERVER['PHP_SELF']  etc etc etc blahblah); header("Location: login.php?ref=$ref"); exit; [/code] if not, then setting a session var wouldnt be too tricky either and would be invisible.
  9. throw andys and jcombs posts together, and thats what i (almost) think. however i'll disagree a bit with jcombs re the logo. sure, its not a logo - more of a banner - but still, I actually think that it works and personally think it looks pretty good. you're heading into the right direction regarding the 'feel' - the whole tone is alot more 'cheery' than your last site, which is just pretty grim colour/tone wise. sure, the menus etc could do with lots of work as jcombs said, but it's encouraging that things are heading in the right direction.
  10. hmm ok makes sense. i guess i'm looking at a few different ways and seeing which i'm more comfortable with. one thing you maybe able to help me get my head around though, as it's the only thing i cant. the line i posted previously, get_instance, doesnt seem to be getting the registry at all (still talking about CodeIgniter here). each controller (for example welcome.php) extends a class called Controller, which then extends a class called CI_Base. _load_class is a function that enters an object into a registry. The CI_Base class and get_instance are in the same file (Base5.php). [code] class CI_Base {   public function CI_Base()   {       $instance =& _load_class('Instance');       $instance->set_instance($this);   } } class Instance {   public static $instance;   public function set_instance(&$object)   {       self::$instance =& $object;   }     public function &get_instance()   {       return self::$instance;   } } function &get_instance() {   $instance =& _load_class('Instance');   return $instance->get_instance(); } [/code] now - in the Controller class (which extends the CI_Base), it uses the 'get_instance' function call. from what I can follow, it seems to be trying to get an instance of the entire object, from the base downwards. But if Controller extends Base, surely Controller has access to Base and its descendents anyway? What would you say is the purpose of structuring it like this?
  11. sounds like a case of "LearntToMuchAndItsGotBoringitis". can't say you werent warned. one of the biggest things that keeps coding fun is learning new things all the time - AS YOU GO ALONG, not all in one go. and the fact that you're learning all this stuff by reading up on it instead of getting your hands dirty - no wonder you havent got anything to show for it at the end apart from a head crammed full of knowledge and thinking about what to cram in there next. why dont you set yourself a "harsh" project that will stretch you and make it fun again. Like build an entire CMS/Framework, with future projects in mind. No doubt you're gonna get involved with OOP heavily, and no doubt you're gonna learn loads - not just about PHP but your own methods and practices. And the end result? well, a CMS/Framework that you can use to develop your own site, for starters. Less talk, more action. [b]edit[/b]: i'm actually doing something similar to this at the moment myself, just to have something for the future. Download a few PHP Frameworks and examine the code/structure. I'm looking at CodeIgniter (www.codeigniter.com) at the moment and boy has it tought me a few things... What it's also helped me to do though is to have one 'home' for all my scripts and classes that i've built up over the years, and i've already re-done my company and personal site using it.
  12. certain characters are 'control characters' in regex, including the full stop. to literally mean a full stop, you need to escape it with a backslash. also, you have a single quote (') between your outer single quotes. (i'm not a regex expert so someone may need to elaborate on this): [code] "^[a-zA-Z0-9\.\'])|([:punct:])$" [/code]
  13. [quote author=Remi link=topic=110733.msg448235#msg448235 date=1160164023] What do you think of the layout? How do you immediately feel upon entering the site? How what viseral reactions do you have to the headlines? What do you think of the site overall? Where could improvements be made? [/quote] hmm it's clean enough, i guess, but due to the dominance of the gooooooooooooooogle ads, it looks more like an advert factory rather than a website with a purpose. but considering all it really is is a blog, and the default google blogspot templates look nicer, nothing really stands out as...well anything. it needs some variety in there, perhaps a nice backdrop or images or something. and seriously, lose the ads or at least cut them down. [quote author=Remi link=topic=110733.msg448235#msg448235 date=1160164023] How would you pronounce 'kokyunage'? [/quote] you really dont want to know. overall, its not awful. its just a tad bland. Cheers Mark
  14. [quote author=obsidian link=topic=110712.msg448213#msg448213 date=1160162895] U->U->F->D [/quote] is that OOP?  ??? its amazing cos i remember the time when MK first came out and how everyone said how realistic it was, etc. looking back now, it doesnt have even a tiny bit of the shock factor, and its almost funny. still, its still a classic. back on topic for a sec: oldmanice, why do you like getting wet whilst being blown?  ;D
  15. [quote author=zanus link=topic=106377.msg448136#msg448136 date=1160155368] ...anus... [/quote] i'll never be able to look at your username in the same way again ;D
  16. [quote author=obsidian link=topic=110712.msg448137#msg448137 date=1160155616] out of curiosity: what is the best fatality of all time from the MK series? i think it's hard to beat Kano from MK1 ripping the still beating heart out of his opponent's chest... that or sub-zero ripping the head and spine right out of their body... hard to top those... hehe [/quote] yeah def the head+spine one. had to go to google to jog my memory as some of them were excellent. i remember as a kid spending a fortune in the amusement arcade learning the finishing moves and feeling like a right bad-ass when i managed to do it. found this though: http://video.google.com/videoplay?docid=3944547331800598383
  17. [quote author=oldmanice link=topic=110692.msg448091#msg448091 date=1160152291] Well Mark all I can say is good for you [/quote] cheers ;)
  18. [quote author=Crayon Violent link=topic=110712.msg448115#msg448115 date=1160154135] foolish mortal! you dare compare MK to Tekken?  You will die! [/quote] FINISH HIM!!!!!
  19. haha this is possibly the most bizarre post i've seen in ages on a PHP forum. good ole Misc category, huh? :) I'd prefer standing under a heavy summer rain, with Kate Winslet blo.... you get my point.  ;)
  20. tis a tricky one to answer as i honestly dont know. I tend to keep my scripts and sites all quite simple anyway, so even if there was a dramatic increase, it wouldnt be something i'd notice as a result. It's not slowed down, which is good enough for me, and from what I've read, the performance is miles better. But you'd probably only really notice it with something quite intensive. TBH, I only upgraded mainly because of better support for OOP because it's something I'm getting to grips with and learning much more about.
  21. i've looked through these a few weeks back, and to be honest it doesnt appear like much will change thats gonna have any major impacts. many of the comments in those minutes make it very clear that they dont want to 'break' too much and most of PHP4 stuff will still be fully compatible. if you're relying on half the stuff they're getting rid of (HTTP_POST_VARS, register_globals, etc) then you really need to be avoiding these anyway, turning them off, and making your code work without them, as all they've really contributed to PHP is security issues. If PHP6 is as slow to take off as PHP5 has been (from a hosting point of view), then I really hope it makes people move up from 4 to 5 at least. I've only upgraded myself over the last few weeks and with all the new stuff there, it really surprises me why the uptake has been slow. But writing stuff on PHP5 (notably OO stuff) and trying to take care of people still on 4 is a nightmare. @hostfreak: not unless you NEED to learn the extras. I like to think of things like this as "more available if I need it" rather than "more to learn". For example, using PHP5 instead of 4 is no different to use AT ALL, unless you're doing OOP.
  22. cheers guys, just noticed!!! TBH, with the level of skill and will to help around here, it's much harder to give back even half of what you take from a community like this. I'd still be scratching my arse playing with geocities if it wasnt for this place and still continue to learn new stuff every day. So thanks for the recognition! Cheers Mark
  23. hmm makes sense. would it be fair to say though that if i was to use a function, it would be easier if (for some reason, being awkward) i changed the name of my registry class? here's an example of a line found in the constructor of a class that uses the registry in Code Igniter: [code]$this->obj =& get_instance();[/code]
  24. ok lovely. just so i understand better, can you think of any reason why they would use a function to do it instead of a straightforward Registry::getInstance() call?
  25. right then, hopefully i can explain this properly... i'm in the process of sorting out all my old scripts that i use over and over into a nice tidy framework. not just as a practical exercise but a learning one too. i've been looking through the code of the Code Igniter framework (http://www.codeigniter.com) and out of all the ones i've looked at so far, this is the most comfortable one to understand and probably what i'll base much of my own on. now the code uses what i can only describe as a registry (in system/library/codeigniter/common.php for anyone following along), only its not a registry class but a procedural registry instead. after reading about the registry pattern on phppatterns, they state that you pass the registry alone by parameter to classes that need it. however, Code Igniter uses a function called 'get_instance' which appears to do do this job. so onto my question. i do prefer this way of doing it - ie, using a function instead of passing it as a parameter. i've made a registry class, and also a function to return an instance of the registry. apart from "OOP best practice", is there anything seriously wrong with what i'm doing or any pitfalls i may find later down the line? Cheers Mark
×
×
  • 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.