Jump to content

PaulRyan

Members
  • Posts

    876
  • Joined

  • Last visited

  • Days Won

    4

Posts posted by PaulRyan

  1. The forgot password function you are trying to implement isn't really viable.

     

    Anyone could go on to your website, enter someone elses username and then reset that persons password.

     

    The best method is to firstly, allow a person to enter their username.

    Send an e-amil to their e-mail address with a password reset link.

    The link will go to your website, and you will then send out a new password for them to log in with.

     

    The benefits of the above is that, if I went to your website and entered a username, the password wouldn't change, unless the user associated with that username clicked on the link sent to them.

  2. Hello, I'm Paul Ryan.

     

    I am 23 years old and have around 8 years experience in programming with the following languages:

    - PHP

    - MySQLi

    - HTML

    - CSS

    - JavasScript (jQuery, AJAX)

     

    I have worked on many project over the years, including the following:

    - BoxSelect.com

    - Taccd.com

    - FTA.ie

    - BelfastCookerySchool.com

    - Dittnyebad.no

    - MassasjeShop.no

    - Project: Universe (Personal Project)

     

    I have worked on many other smaller jobs, updating outdated code, database and code optimizations etc.

     

    You can contact me via the following methods:

    - PHP Freaks Personal Message

    - Skype: paulryanmc91

    - E-mail: paul.ryan.mclaughlin@gmail.com

     

    I am available to start work immediately whether the job be big or small, don't hesitate to contact me.

     

    Thanks for your time, look forward to hearing from you.

     

    Kind Regards,

    Paul Ryan

  3. This is quite simple, you should look at pow to complete this. See the following:

    <?PHP
    
      //### Start at 1
      $currentNumber = 1;
     
      //### While true, continuos till break is hit
      while(true) {   
        
        //### Multiply the number by itself
        $number = pow($currentNumber, 2);
        
        //### If the number is less than 20000 display it
        //### If the number is greater than 20000, break the while loop
        if($number < 20000) {
          echo $number .'<br>';
        } else {
          break;
        }
        
        //### Add 1 to the current number
        $currentNumber++;
      }
    
    ?>
  4. I agree with Ch0cu3r, you have far too much repetition in your code. You have also miscalculated the amount on the pension, it is 2.5% not 25%. So the multiplier would be 0.025 not 0.25.

     

    I have restructured your code as follows, I haven't done anything.

    <?PHP
    
      //### Function to return tax amount
      function tax_amount($salary) {
        if($salary >= 500000) {
          return $salary*0.45;
        } else if($salary >= 300000) {
          return $salary*0.35;
        } else if($salary >= 200000) {
          return $salary*0.2;
        } else if($salary >= 100000) {
          return $salary*0.1;
        } else {
          return 0;
        }  
      }
    
      //### Set pension contribution amount
      $pensionContribution = 0.025;
    
      //### Employee data in an array
      $employees = array(array('name' => 'Aron',    'gender' => 'm', 'dob' => '1930-01-25', 'position' => 'manager',    'start_date' => '1998-01-01', 'gross_salary' => 635000.00),
                         array('name' => 'Britney', 'gender' => 'f', 'dob' => '2001-05-06', 'position' => 'researcher', 'start_date' => '2001-03-15', 'gross_salary' => 420000.00),
                         array('name' => 'Daniel',  'gender' => 'm', 'dob' => '2003-01-15', 'position' => 'officer',    'start_date' => '2003-12-06', 'gross_salary' => 260000.00),
                         array('name' => 'Jessica', 'gender' => 'f', 'dob' => '2002-11-21', 'position' => 'officer',    'start_date' => '2007-02-20', 'gross_salary' => 350000.00),
                         array('name' => 'Peter',   'gender' => 'm', 'dob' => '1998-01-07', 'position' => 'assistant',  'start_date' => '2009-09-06', 'gross_salary' => 250000.00),
                         array('name' => 'Keith',   'gender' => 'm', 'dob' => '2003-07-25', 'position' => 'intern',     'start_date' => '2012-06-27', 'gross_salary' => 90000.00)
                        );
                    
      //### Iterate over employee data                  
      foreach($employees AS $employee) {
     
        //### Add tax amount, pension amount and net salary
        $employee['tax_amount']     = tax_amount($employee['gross_salary']);
        $employee['pension_amount'] = ($employee['gross_salary']*$pensionContribution);
        $employee['net_salary']     = (($employee['gross_salary']-$employee['pension_amount'])-$employee['tax_amount']);
     
        //### Display employee data
        echo '<pre>';
        print_r($employee);
        echo '</pre>';
      }
     
    ?>

    As you can see, it is a lot easier to read and see what data is where. I also created a function to return tax amount.

    I calculated the tax amount, pension amount and net salary during the while loop so it's less code to write.

  5. Edit* - Thought it was wrong function, actually malformed time string.

     

     

    <?PHP
    
      $string = '2013-09-27 14:00:01';
     
      $timestamp = strtotime($string);
     
      if($timestamp < ($_SERVER['REQUEST_TIME'] - (60*60*24))) {
        echo 'True';
      }
     
    ?>
  6. @Denno - If the posts array does not equal a number that is divisible by 3, then your code will not close the final div.

     

    Try this instead.

     

    <?PHP
    
      //### How many per row
      $perRow = 3;
     
      //### Keep count of posts per row
      $perRowCount = 0;
     
      //### Start output
      $output = '';
     
      //### Dummy data, replace with your own
      $posts = array('1', '2', '3', '4', '5', '6', '7', '8', '9', '10');
     
      //### Iterate over each post
      foreach($posts AS $post){
        //### If there is no remainer from division, open container
        if($perRowCount%$perRow == 0) {
          $output .= '<div class="container">Container Start'.PHP_EOL;
        }
        
        //### Add the comment element with data
        $output .= '<div class="comment">'. $post .'</div>'.PHP_EOL;
    
        //### IF the remainer from the division is 2, close the container ready for opening another next time round
        if($perRowCount%$perRow == 2) {
          $output .= 'Container End</div>'.PHP_EOL;
        }
        
        //### Increase per row count
        $perRowCount++;
      }
     
      //### If the remainder from the division is not 0, then close the final open div
      if($perRowCount%$perRow != 0) {
        $output .= 'Container End</div>'.PHP_EOL;
      }
    
      //### Echo the output
      echo $output;
     
    ?>
  7. Try this

    <?PHP
    
      $string = "abc  12,345 def";
     
      $stringElements = explode(' ', $string);
     
      foreach($stringElements AS $key => $element) {
        if(preg_match('/[a-z]/', $element)) {
          $stringElements[$key] = strrev($element);
        }
      }
     
      echo implode(' ', $stringElements);
     
    ?>
  8. Here is how I would do it:

     

    Feature Videos Table

     

    CREATE TABLE IF NOT EXISTS `featured_videos` (
      `video_id` int(11) NOT NULL,
      `featured_date` date NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

     

    Cron Job

     

    <?PHP
    
      //### Connect to database
      $conn = mysql_connect("127.0.0.1", "root", "") or die(mysql_error());
      mysql_select_db("test");
        
      //### Set how many to select
      $videos = 5;
        
      //### Select max ID
      $selectMaxQuery = "SELECT MIN(`id`) AS `min`, MAX(`id`) AS `max` FROM `video_tbl`";
      $selectMax      = mysql_query($selectMaxQuery, $conn) or die(mysql_error());
        
      //### Check to see if rows are returned
      if(mysql_num_rows($selectMax)) {
        
        //### Assign record to variable
        $selected = mysql_fetch_assoc($selectMax);
        
        //### Select videos randomly
        $start = mt_rand($selected['min'], $selected['max']-($videos));
          
        //### Now select videos from database
        $selectVideosQuery = "SELECT `id` FROM `video_tbl` LIMIT {$start}, {$videos}";
        $selectVideos      = mysql_query($selectVideosQuery, $conn) or die(mysql_error());
          
        //### Check for returned rows
        if(mysql_num_rows($selectVideos)) {
          
          //### Start query
          $insertVideosQuery = "INSERT INTO `featured_videos` (`video_id`, `featured_date`) VALUES ";
          
          //###Iterate over each row
          while($video = mysql_fetch_assoc($selectVideos)) {
            $videosArray[] = "({$video['id']}, NOW())";
          }
            
          //### Add to end of query
          $insertVideosQuery .= implode(',', $videosArray);
            
          //### Execute query
          $insertVideos = mysql_query($insertVideosQuery, $conn) or die(mysql_error());
          
        }
      }
     
    ?>

     

    And to select the videos

     

    <?PHP
    
      //### Connect to database
      $conn = mysql_connect("127.0.0.1", "root", "") or die(mysql_error());
      mysql_select_db("test");
        
      //### Select videos from featured table
      $selectVideosQuery = "SELECT `vt`.`id`, `vt`.`vid`
                            FROM `featured_videos` AS `fv`
                            LEFT JOIN `video_tbl` AS `vt` ON `vt`.`id` = `fv`.`video_id`
                            WHERE `fv`.`featured_date` = CURDATE()";
                            
      $selectVideos = mysql_query($selectVideosQuery, $conn) or die(mysql_error());
     
      //### Check for videos
      if(mysql_num_rows($selectVideos)) {
     
        //### Iterate over each row
        while($video = mysql_fetch_assoc($selectVideos)) {
          echo '<pre>';
          print_r($video);
          echo '</pre>';
        }
     
      } else {
        echo 'No videos to show.';
      }
     
    ?>
×
×
  • 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.