Jump to content

Koobi

Staff Alumni
  • Posts

    419
  • Joined

  • Last visited

    Never

Posts posted by Koobi

  1. no problem.

     

     

    mrMarcus was just joining your results together and using a pipe '|' to distinguish between the two pieces of data.

    he has a point, that method has its uses too but in my humble opinion, i thought the array method might work out better in your situation.

  2. j0n, if i'm not mistaken, i think he meant that he wanted to populate the $definedPages array based on the HTML anchor tags in a page. not the other way around.

     

     

    ok i got a question, can you take

     

    $definedPages = array('default', 'print', 'web');

     

    and make a script to polulate the array based on the links it can find on any given page.

     

    there are always ways to do things like that via regular expressions and whatnot but that's really bad practice.

     

    ideally, you could have an include at the top of the page that defines this array. but grabbing the links in a page by parsing the HTML would be a very bad idea though it can be done.

     

     

     

    anyway, if you have more questions on this, you should probably make a new thread unless the OP doesn't mind this in his thread :)

  3. it does not make sense to use that kind of setters and getters if you implement them both as they show in the example.

    Just using a public variable works...

     

    Thus using both of them in a same class just introduces useless extra lines and this should be avoided.

     

    Yeah, but nobody writes code like that anyway. It's an example that wouldn't appear in real applications.

     

    You might for instance make sort of integrity check, or you might later want to abstract it away using a strategy or you might want to use a proxy. You cannot do that if you're directly accessing your properties.

     

    i was thinking about that too...what if you decide to do some kind of processing before you set or get a method.

     

     

    i think getters and setters are good practice based on the situation.

    for example, if you're setting values to insert into a database, i think it's alright to set the values to the property directly because and processing that has to be done to a variable before entering it into the database should be dealt with in the model (if you're using the MVC pattern).

     

    that's probably the only instance where i'm on the fence about getters and setters.

     

     

    google is weird sometimes...their creativity level is awesome but the way they code some web apps just don't make sense. maybe i'm missing something because most of them are probably pretty damn smart.

  4. Hi premiso, I know what I did wrong, dont it make you feel like an idiot when its something simple.

     

    I did the Switch and its working.

     

    Thanks premiso,

    01hanstu

     

    haha i've been working with PHP since the early 4.x releases and i still make stupid mistakes that make me feel like a total idiot :)

     

     

    once little thing about your switch case...always have a 'default' catch all.

    because, what if i decide to type the URL in manually and i do:

    http://site.co.uk/index.php?page=imanidiotsometimes

     

     

     

    if you really want to make your navigation cleaner, you can do this:

    $definedPages = array('default', 'print', 'web'); 
    $myPath = 'path/to/dir/';
    
    if (in_array($_GET['page'], $definedPages)) {
        require_once $path . 'img' . $_GET['page'] . '.php';
    } else {
        require_once $path . 'imgdefault.php';
    }
    

    the url's would look like:

    http://site.co.uk/index.php?page=web

    http://site.co.uk/index.php?page=print

    http://site.co.uk/index.php?page=default

    http://site.co.uk/index.php?page=

    http://site.co.uk/index.php

     

    the last three url's would give you the same result.

     

    the only disadvantage here is that the switch/case is fractionally faster than an if condition but for a simple navigation, this wont be an issue. i'm talking about microseconds.

     

    why do i hide the 'img' part from the end user? just because it's better that the end user has no idea whats going on in your backend for security reasons.

  5. ^^ i believe what mrMarcus said about embedding HTML is true.

     

     

     

    regarding concatenating your data with a string, however, if FORUM_TOPIC happens to contain a pipe '|', you will get unexpected results. so, if you want, you could stick your results into an array and iterate through them like this:

     

    your method modified:

        public function forumTopics()
        {
            $sql = "SELECT * FROM forum_topic WHERE forum_topic.user_id='".$this->userId."' ORDER BY datetime DESC LIMIT 5";
    $result=$this->db->query($sql);
            while ($row = $result->fetch()) {
                $FTopics[] = array($row[FORUM_TOPIC], $row[FORUM_ID]);
            }
            return $FTopics;
        }
    
    

     

    now, the return value will be an array of arrays.

    if you need to visualize this to proceed, do this:

    print_r($user->forumTopics());
    

     

    or

     

    var_dump($user->forumTopics());
    

     

    feel free to warp that output with HTML <pre> tags if it makes it more pleasant to look at.

     

     

    now, you can access your data like this:

    foreach($user->forumTopics() as $index => $record) {
        echo "Record number: $index<br />";
        echo 'Topic: ' . $record[0];
        echo 'ID: ' . $record[1];
    }
    

  6. I would rather do it like this:

     

    function forumTopics() {
    	$sql = "SELECT * FROM forum_topic WHERE forum_topic.user_id='".$this->userId."' ORDER BY datetime DESC LIMIT 5";
    		$result=$this->db->query($sql);
    	$FTopics = array(); //initialize as an array
    	while ($row = $result->fetch()){
    	    //it makes no sense to use $this here	
                        $FTopics[] = $row[FORUM_TOPIC] .'<br />';
    	}
    		return $FTopics;
    	}
    

     

    this is my reasoning:

     

    * initializing

    PHP is a scripting language and like most scripting languages, it is loose typed, in that, you don't need to tell PHP a variable can only store integer or string. a variable in PHP can store any of the types.

    but, it is good practice to initialize variables according to their types. at the end of the day, it's about personal preference and how clean you want your code.

    so since $FTopics will be storing data as an array, i chose to initialize it as an array.

    this also makes the code easy to read...for some reason if i have to initialize it further up in my code, the fact that i initialized it as an array will give me a hint as to what that variable will later contain.

     

     

     

    * not using $this

    i wouldn't use $this->FTopics unless i need to use this data elsewhere in the class.

    if you need the forum topics to be returned to you and discarded, just use a regular variable.

    when you use $this, you are involving the whole class as your scope.

    if you have not designed or planned this carefully, you might have another variable called $this->FTopics which can overwrite or append the one within your forumTopics() method.

    therefore, use $this sparingly and only if you need it or things can get buggy.

     

    also, if you do end up using $this, you should be initializing it outside the methods like:

     

    MyClass
    {
        private $FTopics = array()
    
        public function forumTopics()
        {
            $sql = "SELECT * FROM forum_topic WHERE forum_topic.user_id='".$this->userId."' ORDER BY datetime DESC LIMIT 5";
    $result=$this->db->query($sql);
            while ($row = $result->fetch()) {
                $this->FTopics[] = $row[FORUM_TOPIC] .'<br />';
    }
    return $this->FTopics;
        }
    }
    

  7. vim is my choice :D

     

     

    What I really want to use is an editor with File Management capabilties, PHP function recognition, Regex Search and Replace and FTP access, then I believe I'd be a happy camper/coder.  Too bad that editor has to be Dreamweaver.  Perhaps there is another one out there that I don't know about?

     

    file management? do you mean something like Vim Project?

     

    vim has PHP function recognition, you just have to get the file from the vim site.

    regex search/replace has always existed in vim too.

     

    ftp is also supported.

    although i prefer scp via ssh

     

    every unix/linux machine out there will have vim or vi (older version) on it so if you do get used to vim, doing an urgent remote edit won't be a problem.

     

    there's tons more that vim can do.

    i'll admit it's not the most pleasant editor to get used to but once you do start using it, your productivity will shoot skywards because it's so efficient.

  8. haha yeah, i could never forget gizmola's avatar. i believe it was the picture of a baby with a sour expression on his face and the words "RTFM" in bright yellow right over his head.

  9. So... what was current PHP version when you went on hiatus?

     

    Hi ;)

    haha i think i left about 2 years ago.

    i was just browsing the forum the other day and it's almost impossible to find a thread without any answers in it.

    good going guys!

  10. Hi,

    I used to frequent PHPFreaks a lot back in the day but life took a crazy turn and I had no time to do the things I loved to. This basically means I had no time to code in PHP and sleep :)

     

    But I'm back. Started seriously coding again.

    I've seriously gone into Linux administration although I haven't worked in that position for a few months.

    I learnt some Ruby and then Rails because I really liked their philosophy.

    I revisited PHP and liked the direction it was taking with 5.2 onwards so here I am.

     

    - Housni

  11. this would tell you exactly what OS your use

    # cat /etc/issue
    

     

    also, the output of this might be useful:

    # uname -a
    

     

    i suppose you could check your processes to see if anything is taking up a lot of memory or if your server load is too high by typing:

    # top
    

     

    and maybe view your apache logs/system logs?

     

     

    also, is your system memory usage alright?

    # cat /proc/meminfo
    

    should show you those details.

     

     

    effigy might have a better solution for you though.

  12. yeah i'd like people to use PHP5 too as I've mentioned but there are real life situations where using the older versions are required. iv've come accross such situations at work but thank god we use redhat for our servers.

  13. when i was working with Photoshop (version 5.0 through to early CS) the Photoshop Bible was brilliant! i read the book cover to cover (this was the bible for 7.0) and it really got me very familiar with the tools...but you should definitely try the practical tutorials online to know what to use which tool when.

  14. There is always a choice, compile the source.

     

     

    well, i just think that if they are going to call Ubuntu the user friendly Linux for the beginner, they should make things very easy. if it was gentoo or something like that, i'd understand them discontinuing PHP4 since gentoo users will most likely know how to compile a program...and if they don't the only thing the gentoo wiki doesn't cover is how to build a space rocket.

     

    but yeah, i think ubuntu should make things easy for the user since that is what they represent...btw, does anyone know if debian repos's support PHP4?

  15. Koobi, so your system does not store the media locally? as you say 'upload' it?

     

    an rss feed of what files are there-i thought of this, but what use would that be to me?

     

     

    secondly -> im not sure if this applies, but how did you make it so they can stream from it, im having problems with directories, meaning i need to create sym links etc

     

    well my app is targetted for online use across multiple users. you didn't mention what you intended to use it for so i assumed it was the same as mine :)

     

    but i would find an RSS feed useful if many users are using this app so that they know what files exist on the server.

     

     

    regarding streaming...your best and easiest bet would be Flash or intense JS...this guy who works at Yahoo,,,Scott Schiller made an mp3 streaming...thing, not sure where it was but google for him and you should find something.

  16. Isn't PHP4 technically an older version? They don't leave e.g. Firefox 1.5 in the repository either. People could always just download the sources and compile it themselves.

     

     

     

    but there are situations where you would need an older version for either a dependency issue (where you can only use an older version of a dependecy library which the newer versions don't support) and if you are put in that situation, you are going to be in a big mess.

     

    PHP.net allows you to download the older versions as well so I believe Ubuntu repositories should. we should be given the choice. we know what is best suited for our system.

  17. yep, no more PHP4 support. you can always add your own repositories to support PHP4 but the default Ubuntu repositories don't support it. I think people should switch to PHP5 but I don't think they should leave people with no option but to use PHP5. People should have a choice of software.

     

     

    Nope, but i hate what they did to the ubuntu server in Ubuntu Feisty. It was better how it was in edgy im actually tempted to switch  to debian as this was not the only annoyance in ubuntu feisty. To me ubuntu feisty in general felt like they released it to early.

     

    And I know this might sound harsh but I hope php4 does slowly die to make room for php5 and php6 

    what do you mean? what have they done? I haven't upgraded yet but I'm considering it.

  18. i'm actually doing the same thing. but the mp3 side of things is a small component of the entire app.

     

    i also allow the users to upload a compressed file (.zip, .tar.gz, etc) and i decompress them and tag them via MusicBrainz's XMLWebService (http://wiki.musicbrainz.org/XMLWebService).

     

    The files when displayed are sortable according to their file system metadata (size, date accessed, etc) as well as the ID3 tags.

     

    apart from saving to the db for searching, i also produce an RSS feed of what files exist.

     

    when listing the files, i have a checkbox next to each file and if you check a bunch of files and submit the form, it will prompt you to download a compressed file (with a format of your choice) that contains all the files you selected.

  19. According to the Zend staff, Zend Optimizer won't work with IonCube but you can make them work so long as you first load IonCube and then load Zend Optimizer.

     

    If you are using Zend Core to configure you PHP settings, don't do so. Their latest version has a lot of bugs which they will fix and release in a few weeks.

  20. I have configured 7zip to use very high compression to make very small files, so it makes say a 7meg file instead of the 220meg file it does with the default settings.

     

    When I right click something and click 7zip>add to archive then it will use the settings that I set it to instead of default settings.

     

    Is there a way to do this in PHP, or to manually add these settings to the command line? Like dictionary size and compression level and all that good stuff? Please? :D

     

     

    oh ok, well since you are running it via exec(), PHP can't do anything about the settings.

     

    in any case, i'm not sure about the settings either. i think you probably have to set those settings when you configure the 7zip library before you compile to install it.

     

    sorry i can't help, i'm not familiar with 7zip. maybe you can look it up on their site?

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