Jump to content

JonnoTheDev

Staff Alumni
  • Posts

    3,584
  • Joined

  • Last visited

  • Days Won

    3

Posts posted by JonnoTheDev

  1. Why are you storing a calculation in the DB? You should store the values that are used in the calculation and then calculate the value when you need to use it.

     

    Not really. What if you wanted to pull a report on all people who worked longer than 5 hours?

  2. Firstly you should use MySQL TIME type for your 'diff' field. It would be even better if you could use the DATETIME format for the other 3 fields and include the date in the data. If you are using a VARCHAR then change it.

     

    To insert the missing data using the INSERT query you must first use PHP to calculate the time difference. To do this you will need the date. There is an issue. If the start time is say 5pm and the end time is 2am the following morning you will need the actual end date as just adding the current day to your time values will not work. So, $_POST['edin'] must be a datetime and $_POST['out'] must be a datetime YYYY-MM-DD HH::MM::SS

     

    It is then easy to find the time difference using a simple function. If you are using PHP 5.3 then there are objects that can do this much easier.

    <?php
    // function get the time difference between start and end date
    function get_time_diff($start, $end)
    {
     $diff = strtotime($end) - strtotime($start);
     $hr = floor($diff / 3600);
     $remaining = $diff - $hr * 3600;
     return sprintf('%02d', $hr) . gmdate(':i:s', $remaining);
    }
    
    // this should be what is in your $_POST['edin'] variable
    $start = '2013-07-01 12:20:00';
    // this should be what is in your $_POST['out'] variable
    $end = '2013-07-01 12:23:00';
    // should print 00:03:00
    $out = get_time_diff($start, $end);
    echo $out;
    ?>
    
  3. You can't use a URL in the move_uploaded_file() function for the destination parameter. Use a proper path and make sure the directory has write permissions.

    // bad
    move_uploaded_file($_FILES["file"]["tmp_name"], "http://www.jasondoyleracing.com/news-images/" . $newfilename);
    
    // good
    move_uploaded_file($_FILES["file"]["tmp_name"], "/public_html/news-images/" . $newfilename);
    
  4. $data holds the query row in your loop not $list

    $list = mysql_query("SELECT name, email FROM ".mysql_real_escape_string($_POST['db1']));
    $mailList = array();
    while($data = mysql_fetch_assoc($list)) 
    {
    	// probably better to use email as the array key as it is unique
    	$mailList[$data['email']] = $data['name'];
    }
    						
    echo '<br /> var dump <br />';
    						
    	var_dump($mailList);
    						
    echo '<br /> var dump <br />';
    
  5.  

    I am kind of new to coding but I want to make a php script that is reactive to the information entered by the user.

    Remember, PHP is only executed on the server, not by a web browser. So, for PHP to do anything with form data it must first get to the server, i.e the form must be submitted. As Psych has stated, if you want the data to be processed as soon as something is entered into the text field (you have termed it reactive), then you require code that the browser understands to get the input data to the server without the user clicking a submit button. PHP can then deal with the data and send a response back. Javascript is needed (AJAX). To make your life simple I would use the JQuery framework. Have a look at this simple tutorial which pretty much does what you are after.

     

    http://www.phptutorialforbeginners.com/2013/01/jquery-ajax-tutorial-and-example-of.html

  6. SEO is a trial & error game. Sure, there is plenty of material out there regarding on-site optimization such as page titles, descriptive anchor links, friendly urls, meta data, etc. However, off-site is key i.e link building, etc, but remember too much, too soon and Google may find you out and de-index your site quickly. Google's algorithms change often, that is why there is no black and white, 'do this and your site will rank' method. People who are good at SEO will never reveal their methodology, i.e the tools they use.

  7. Advantages: No need to learn PHP, etc if you are using it straight out of the box, quick to setup

     

    Disadvantages: Possible security holes, need to install patches for bug fixes, may not have a feature that you or a client requires in their website, looks and feels the same as other websites using the same system, possible steep learning curve if you wish to modify the code yourself to add new functionality.

     

    This applies to any CMS, not just the one you mention

  8. Let me elaborate. You should not store delimited ids in a text field as you will end up with a mass of issues down the line. To normalize your database you need to do the following (I am guessing your table / field names)

     

    players

    =======

    player_id (int)

    name (vc 50)

     

    announcements

    =============

    an_id (int)

    content (vc 255)

     

    players_to_announcements

    ======================

    id (int)

    player_id (int)

    an_id (int)

    date_read (datetime)

     

    So if you have 3 players in the players db table with ids 1, 2, and 3 and you have an announcement in the announcements table with an id of lets say 456, if a player reads an announcement you record this by storing a record in the players_to_announcements table. If player id 2 & 3 have read the announcement the data will look as follows:

     

    1 | 2 | 456 | 2013-01-01 01:00:00

    2 | 3 | 456 | 2013-01-01 02:00:00

     

    You can then easily query this data to find what players have read each announcement

  9. You may need to change the way your checkout functions. If your website is setup where you need to complete a registration form, then login before they can add to basket and proceed to checkout I would scrap that. Firstly, i'm guessing that your database design will not allow orders to be disjointed from a customer, i.e they need a customer ID.

     

    I would change your website so customers are actually registered on checkout whether they are going to come back to your website or not. When they checkout the first thing you can do is ask for their email address and password. If they dont have an account i.e If they are a first time buyer they still need to enter their details for shipping, payment, etc on your website so you can capture this and register them at this point and complete the checkout. Similar to how Amazon works.

     

    I would not be looking at deleting any information. What if a customer needs to print off an invoice in the future? If you have deleted their record there is no way that they can do this. Customers should always be registered, it is the order process that should be ammended.

  10. Seems like I wasn't specific enough in my opening line. What I meant to say was that I would not store the time in the cookie, as the user could easily defeat the system in that case.

     

    Using a cookie to identify the user, however, is indeed a requirement. Whether you set the cookie manually, or rely upon the PHP session handler to do it for you. ;)

     

    Then all is forgiven LOL :happy-04:

  11. I wouldn't do it that way, as it's way too easy to manipulate a cookie.

     

    For this I'm going to assume that you're using a login-system, so that you can verify your users in that manner. What I'd do then, is to save the starting time in the database, and check this upon (re-)entry of the page. Should said timer be older than now + timeout, then show them the "sorry" message.

    To get the counter on the page, just send the start time and timeout to a JS, and use it to display the counter.

     

    If you are going to store the start time in a database then you still require an identifier for the user upon returning to the page. This is not a problem if you must login prior. This is why I suggested using a cookie.

  12. The way I would tackle this is by using a cookie.

     

    When the user hits the start button I would set a cookie that contains the time that the button was clicked. You can then read this value and add 5 minutes to it to get your expiry time. If the current time is greater than the expiry time you will know that the user has ran out of time. To display a counter you will need to use javascript and a little bit of ajax to get the required data from the server. By using a cookie, a user can leave your website, close their web browser, etc, come back and the data will still be available.

     

    PHP has lots of time functions. For instance to get the current time as a unix timestamp, simply use time().

     

    All of PHP's date & time functions are listed on the left of the manual page

    http://php.net/time

     

    What you are trying to do will require a decent knowledge of PHP / JS / AJAX

  13. Undefined index means that you are attempting to access data inside an array (in this case the $_POST array) using a key that doesn't exist. Your error is due to either the form field name being spelled different to HouseNumberName and CityTown, or there is no data present in the field. What you are getting is a notice (more of a warning than an error) and your code should still function. However to clean this up check your form field names are correct and the same as what you are using as the $_POST array key and always check that data exists and is set before attempting to use it in any way i.e

     

    // check if data is present and store in variable. if not variable will be FALSE
    $house = (isset($_POST['HouseNumberName']) && !empty($_POST['HouseNumberName'])) ? $_POST['HouseNumberName'] : FALSE;
    

  14. This is certainly not something you want to be doing using your web browser. This is the sort of thing suited to a command line script. I'm not sure why you would not know the exact xml urls that need reading, please elaborate.

     

    You have a simple error in your code. Variables are not translated inside single quotes, only inside double quotes. If you want to use single quotes then the following will work:

     

    $possibleids = range(1,100);
    foreach ($possibleids as $value)
    {
    $xml = 'http://www.website.com/item=' . $value . '&xml';
    }
    

  15. I will have to look at keeping a copy of the original upload at a specific resolution as you guys have suggested for future projects. As I am not a designer I have never been given a design that required an original size image. I have always scaled and optimized images to the size required on the design and destroyed the original.

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