Jump to content

Cagecrawler

Members
  • Posts

    247
  • Joined

  • Last visited

    Never

Posts posted by Cagecrawler

  1. Try something like this:

    <?php
    //Do your connection and checking player/password is correct.
    $competitions = array('fifaworldcup' => 'fifaworldcup', 'golfusopen' => 'usopengolf', 'wimbledontennis2010' => 'wimbledon2010'); //Complete with each competition you run, where the key is the POST value and value is the database field.  
    
    $sql_array = array();
    foreach($competitions as $key => $value){
    if($_POST[$key] != '-'){
    	$sql_array[] = "$value = '{$_POST[$key]}'";
    }
    }
    $sql = 'UPDATE upcpicks SET '.implode(',',$sql_array)." WHERE user='".$_POST['person']."'";
    ?>
    

     

    The sql now only updates the fields where the data has been entered.

  2. Try naming the class Default_Form_Login, keeping filename and place the same.  If this doesn't work, you'll have to set up a specific autoloader.

     

    If you're using Zend_Application_Module_Autoloader (as they do in the quickstart guide) then the example they provide should work (I haven't tested).  Insert the following function into your bootstrap.

    <?php
    protected function _initAutoload(){
        $autoloader = new Zend_Application_Module_Autoloader(array(
            'namespace' => 'Default_',
            'basePath'  => dirname(__FILE__),
        ));
        return $autoloader;
    }
    

     

    I'm actually using Zend_Loader_Autoloader (for more complex things) - below is how I solve it.

    <?php
    protected function _initAutoload(){
        $resourceLoader = new Zend_Loader_Autoloader_Resource(array(
            'basePath'  => APPLICATION_PATH, //APPLICATION_PATH is is folder Bootstrap.php is in
            'namespace' => 'Default',
        ));
        $resourceLoader->addResourceType('form','forms/','Form');
    }
    

  3. If they are limited to two teams, you could have 'team1_id' and 'team2_id'.  Then use SQL something like this:

    SELECT * FROM user WHERE team1_id = 10 AND team2_id = 15

     

    Of course, only using two tables means adding an extra column if you want to allow them to be in another team, which should be avoided.

  4. I'd use three tables in that case.  A 'user' table for each player (could easily double up as storage for login info etc), a 'teams' table listing each team and it's info and a 'user_team' (or something to that effect) table which stores each user-team relationship.

     

    Altering deadonarrival's table structure, remove team_id from the users table.  Then create a third table ('user_team') with three columns - id, user_id and team_id.  If a player is in more than one team, they have more than one entry in the table.

  5. header("Location: " . $_SERVER['PHP_SELF']);

    The header("Location:.... function instantly redirects the script to the target location - anything after this point is ignored by the script and so will not be printed.  If you want to show the text for a little while and then redirect, you should use the html <meta> tag.

    <?php
    echo "<META HTTP-EQUIV=\"Refresh\" CONTENT=\"5; URL=".$_SERVER['PHP_SELF']."\">";
    ?>
    

    You need to put this into the <head> tag of your page though, so it might not be appropriate.

  6. Oops, I noticed that because some of the codes overlap (ari/rin/ri), some of the letters get mistaken.  I've reversed the loop and all works fine now:

    <?php
    function decode($message)
    {
    $letters = array('ka','tu','mi','te','ku','lu','ji','ri','ki','zu','me','ta','rin','to','mo','no','ke','shi','ari','chi','do','ru','mei','na','fu','zi',' ');
    $alphabet = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' ');
    for($i = count($letters) -1;$i >= 0;$i--)
    {
    	$message = eregi_replace($letters[$i],$i.".",$message);
    }
    
    $tmp = "";
    
    foreach(explode('.',$message) as $t)
    {
    	$tmp .= $alphabet[$t];
    }
    return $tmp;
    }
    
    function encode($message)
    {
    $letters = array('ka','tu','mi','te','ku','lu','ji','ri','ki','zu','me','ta','rin','to','mo','no','ke','shi','ari','chi','do','ru','mei','na','fu','zi',' ');
    $alphabet = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z',' ');
    for($i = count($letters) -1;$i >= 0;$i--)
    {
    	$message = eregi_replace($alphabet[$i],$i.".",$message);
    }
    
    $tmp = "";
    
    foreach(explode('.',$message) as $t)
    {
    	$tmp .= $letters[$t];
    }
    return $tmp;
    }
    ?>
    

  7. I've used numbers as a transition phase to stop the decoder from altering parts that have already been decoded:

    <?php
    function decode($message)
    {
    $letters = array('ka','tu','mi','te','ku','lu','ji','ri','ki','zu','me','ta','rin','to','mo','no','ke','shi','ari','chi','do','ru','mei','na','fu','zi',' ');
    $alphabet = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u,','v','w','x','y','z',' ');
    for($i=0;$i < count($letters);$i++)
    {
    	$message = eregi_replace($letters[$i],$i.'.',$message);
    }
    
    $tmp = '';
    
    foreach(explode('.',$message) as $t)
    {
    	$tmp .= $alphabet[$t];
    }
    return $tmp;
    }
    
    function encode($message)
    {
    $letters = array('ka','tu','mi','te','ku','lu','ji','ri','ki','zu','me','ta','rin','to','mo','no','ke','shi','ari','chi','do','ru','mei','na','fu','zi',' ');
    $alphabet = array('a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u,','v','w','x','y','z',' ');
    for($i=0;$i < count($alphabet);$i++)
    {
    	$message = eregi_replace($alphabet[$i],$i.'.',$message);
    }
    
    $tmp = '';
    
    foreach(explode('.',$message) as $t)
    {
    	$tmp .= $letters[$t];
    }
    return $tmp;
    }
    

  8. He's used a ternary operator to choose whether to use the SESSION array or create a new one.  Using If else:

    <?php
    if(isset($_SESSION['somename']) && is_array($_SESSION['somename']))
    {
        $array = $_SESSION['somename'];
    }
    else
    {
        $array = array();
    }
    ?>
    

  9. PHP is a program like any other.  When you request a php webpage, your webserver tells the PHP interpreter (can be called the runtime, ie. php.exe) to take the interpret the file you asked for and then gives the output to the client.  When you run a cron, you tell the computer to start the php interpreter and bypass the browser completely.

     

    There are three different interpreters, php (the main one), php-cgi and php-win (for windows machines).  You can use php or php-win, I don't think it matters. 

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