Jump to content

IThinkMyBrainHurts

Members
  • Posts

    51
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by IThinkMyBrainHurts

  1. I believe PHP is a progression of C++, that said C++ and Java are very similar in coding style. Also C++ uses a whole lot of the same function names as PHP, which stems from the original C libraries.

     

    Java is very portable but, mmm very slow, C++ beats it hands down, hence why the majority of games are written in C++.

     

    As Requinix say's,it depends on what you want to do. If you're writing system programs, drivers, serious number cruncher's, simulators etc then it's C++ all the way. On the other hand if you want to write something once and quickly then Java is your bag, it's more akin to a bag of tricks. This bag of tricks is very adaptable and is being used for some very adaptable applications.

     

    From having a look at the job market recently, there seems to be a whole lot more C# job adverts than Java, in my area!?

  2. Hi,

     

    I'm after compiling a list of responsive menus that only use CSS, no JS allowed!!!

     

    Ideally they're to handle at least 3 levels, but 2 levels passable ;)

     

    Cheers and hope you lot find this list useful too...

  3. In your chatbox code, you set $id with something uninitialized / non-existent, so that will be null.

     

    $id=$rows['id'];
    

    Then you build the delete link, again with a null value.

     

    $dellink="<a href=\"delete.php?id=" . $id . "\"> Delete </a>";
    

     

    Then you add the same link to all the items:

     

    while($row=mysql_fetch_array($result)){
    //list the comments
    echo $row['name'] . "<br>" . $row['comment']."<br /> . $dellink .<br><hr>";
    }
    

     

    In reality the link should be constructed in the loop where you can actually access the id! So something like this:

     

    while($row=mysql_fetch_array($result)){
    echo $row['name'] . "<br>" . $row['comment']."<br /><a href=\"delete.php?id=" . $row['id'] . "\"> Delete </a><br><hr>";
    }
    
  4. The original is simplest in my view, however a wrapper class for this specific query could look like this (untested):

     

    class my_xyz_query{
        private $id = null;
        private $name = null;
        private $parms = null;
        
        public function__construct($name="",$id=""){
            $this->parms=array();
            $this->parms[] = array(':id',$id,PDO::PARAM_INT);
            $this->parms[] = array(':name',$name,PDO::PARAM_STR);
        }
        
        public function set_name($name){    $this->name=$name;    }
        public function set_id($id){    $this->id=$id;    }
        
        public function get_parms(){
            $this->parms[0][1]=$this->id;
            $this->parms[1][1]=$this->name;
            return $this->params;
        }
    }
    
  5. I'm using Laravel for the get_posts() so I'm not sure if you could follow along. I'm storing all of these in a cache file (.txt), not a session.

     

    Well if you can't do it at that level then you'll have to either use the lookup method mentioned before or refactor it before storing in the txt file db thing you're using!

     

    A txt file, how are you parsing that? Is that optimal???

  6. errrr... many ways... I'd suggest studying the MVC pattern, but a quick solution:

     

    Move the following:

    // Include the header file:
    include('./includes/header.inc.html');

    to after the possible header() clause in the $page pages... e.g here:

     

    <?php

    // Check login status, If not redirect to login page
    if (!login_check($mysqli) == true) {
    $url = BASE_URL.BASE_URI.'index.php';
    // Define the URL.
    header("Location: $url");
    exit( ); // Quit the script.
    }

    // Include the header file:
    include('./includes/header.inc.html');

     

    Others may suggest using ob_start and such.

    * In Wordpress themes, each page template use an include for the header section

     

     

    Why I suggest the MVC approach is because you work out all the bits of the Model before outputting the View.

    For instance, on page request you check the page request link, then handle any form bits (from the Controller, i.e. the response from the View), and then output the View. For more see the Application Design forum here on PHPFreaks: http://forums.phpfreaks.com/topic/20556-resources/

     

    Also from that same page here's a link about how to use the cache (ob_start, etc): http://www.devshed.com/c/a/PHP/Output-Caching-with-PHP/

  7. How are these being used? Are they all in one file? If so, the use of "return" not within a function scope basically acts like exit...http://php.net/manual/en/function.return.php

     

    If called from the global scope, then execution of the current script file is ended.
    As Muddy_Funster demonstrates, use functions to wrap your code (that's when you normally use "return" statements).If you really do want to put them in separate files (but by sounds you want functions!) then use some form of include(), include_once(), require() or require_once() to include the file, anything not within a class or function will be executed straight away.
  8. Starting from 5, the 3 is tested by the mod 3 later, 4 is not a prime. This part is neither here nor there really.The loop step size means that it makes 6 times fewer checks than the other version, and if you're testing say 104729 (the 10,000th prime), that's what 17,454 times more efficient, and that prime is tiny when it comes to public key encryption.*** Looks like it only makes it 3 times faster?

     

    The algorithm can be improved further by observing that all primes are of the form 6k ± 1, with the exception of 2 and 3. This is because all integers can be expressed as (6k + i) for some integer k and for i = −1, 0, 1, 2, 3, or 4; 2 divides (6k + 0), (6k + 2), (6k + 4); and 3 divides (6k + 3). So a more efficient method is to test if n is divisible by 2 or 3, then to check through all the numbers of form 6k ± 1 \scriptstyle{}\leq\sqrt n. This is 3 times as fast as testing all m.
    http://en.wikipedia.org/wiki/Primality_test* My knowledge on the subject is over 10 years old now, also it was only a personal interest
  9. So...

     

    $ndir=str_replace('\\','/',rtrim(__DIR__,"nub"));    //    Pre PHP 5.3 use dirname(__FILE__) instead of __DIR__
    

    Since Windows handles both path types, whereas Linux doesn't. This way the config file can be transferred easily without re-install!

     

    Cheers

  10. lol, makes perfect sense, doh!

     

    However, that path is generated by __DIR__:

     

    $ndir=rtrim(__DIR__,"nub");
    

     

    On searching i'm not seeing this issue mentioned... or output showing similar either???

     

    Yes, Ican replace these manually, issue solved. However is this the expected behaviour of __DIR__ or ...?

     

    Cheers

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