Jump to content

awjudd

Staff Alumni
  • Posts

    422
  • Joined

  • Last visited

  • Days Won

    1

Posts posted by awjudd

  1. http://php.net/string

     

    More specifically this piece right here: '$_POST[id]'.  That will always return the same value.  if you echo it you will see that it is saying $_POST[id] exactly how you have it.

     

    <?php
    session_start();
    if ($_SESSION['cart']['content']['id'] == $_POST['id']) {
    	$_SESSION['cart']['content'][$_POST['id']]['quantity'] = $_SESSION['cart']['content'][$_POST['id']]['quantity'] + $_POST['quantity'];
    } else {
                                /* You were just appending it to the array but you are doing a search for it above so you need the actual id as the index */
    	$_SESSION['cart']['content'][$_POST['id']] = array ('id' => $_POST['id'], 'size' => $_POST['size'], 'quantity' => $_POST['quantity']);
    }
    echo '<DIV class="result">Added to cart.</DIV>';
    ?>
    

     

    ~juddster

  2. You can't make a default value of a variable.

     

    In order to do what you want you should change it to something like this:

     

    public static function is_valid ( $method = NULL )
    {
        /* Check if it is NULL, that means just use $_POST */
        if ( $method === NULL )
        {
            $method = $_POST;
        }
    }
    

     

    That said the variable name is very misleading.  If I read a variable named $method, I would think it would be something like 'POST' / 'GET' however, you are using it as the array to validate.  So I would change that accordingly to make the code more readable.

     

    ~juddster

     

    ~juddster

  3. 1 - http://php.net/ereg - an old regular expression match (RTFM)

    2 - It would either make your current else an else if OR it would just consume the body of your else statement

    3 - They are automatically defined for you.  You just change the variable you are reading from, from $_REQUEST --> $_POST

     

    else if ( isset ( $_POST [ 'button' ] )
    {
    
        // Required field error
        echo 'Required fields are empty';
    
        // Lets fine out which one(s)
        $nameError = ($_POST['name'] == '' ? true : false);
        $emailError = ($_POST['name'] == '' ? true : false);
        $enquiryError = ($_POST['name'] == '' ? true : false);
    }
    else
    {
        $nameError = false;
        $emailError = false;
        $enquiryError = false;
    }
    

     

    ~juddster

  4. The query I provided and the one that you changed it to are two completely different queries.  The one you changed it to does an ANSI JOIN without any conditions making it a CROSS JOIN.

     

    What part of my queries didn't work?  Did they take too long to execute or what?

     

    I noticed a typo in my query:

     

    SELECT u.User_email, lt.last_time AS last_signed_in, r.last_time AS reminder
    FROM Users u
    LEFT JOIN ( SELECT User_id, MAX(log_time) AS last_time FROM log01 WHERE log_type = 3 GROUP BY User_id ) lt ON u.User_id = lt.User_id
    LEFT JOIN ( SELECT User_id, MAX(log_time) AS last_time FROM log01 WHERE log_type = 12 GROUP BY User_id ) r ON u.User_id = r.User_id 
    

     

    ~juddster

  5. I would add in a check either with the ereg (deprecated - should be using the preg family of functions) to see if all of the required values have been set before attempting to send the email.

     

    If you want to keep it in your else, just put it in an if statement.  For example:

     

    if ( isset ( $_POST [ 'button' ] ) ) 
    { 
        echo 'Required fields are empty'; 
        /* Extra code */
    }

     

    That said, you swap between $_POST and $_REQUEST.  I would make that consistent because you don't want some things coming from the URL or a cookie and others from $_POST.

     

    ~juddster

  6. You have MD5 as your password however, in your INSERT query you are using

    SHA1(CONCAT(UPPER('$usr'),':',UPPER('$var')))

    to insert the encrypted password.  You need to be consistent if you want to pull the data back.

     

    ~juddster

  7. Using JOINs makes it insanely easy.

     

    SELECT r.ItemID, it.ItemTitle, SUM(r.Rating) AS mr
    FROM dd_rating r
    JOIN dd_items it ON r.ItemID = it.ItemID
    GROUP BY r.ItemID, it.ItemTitle
    ORDER BY mr DESC
    LIMIT 0, 4

     

    I'm not sure why iblood isn't a fan of JOINs but that is just crazy.

     

    ~juddster

  8. Something like this should work:

     

    SELECT u.User_email, lt.log_time AS last_signed_in
    FROM Users u
    JOIN ( SELECT User_id, MAX(log_time) AS last_time FROM log01 WHERE log_type = 3 GROUP BY User_id ) lt ON u.User_id = lt.User_id
    JOIN ( SELECT User_id, MAX(log_time) AS last_time FROM log01 WHERE log_type = 12 GROUP BY User_id ) r ON u.User_id = r.User_id

     

    Basically the problem is you are having is that effectively making a CROSS JOIN for the log table which is going to be bad ...

     

    Another approach is:

    SELECT Users.User_email
              , MAX(CASE WHERE lt.log_type = 3 THEN lt.log_time ELSE NULL END) AS last_signed_in
              , MAX(CASE WHERE lt.log_type = 12 THEN lt.log_time ELSE NULL END) AS last_reminder_sent
    FROM Users u
    JOIN log01 AS lt ON lt.log_usr = Users.User_id
    WHERE l.log_type IN ( 3, 12 )
    

     

    Basically the first query will go against the log table and find the maximum log time for each user for the reminders and log in times and then just use that in the outside.  This will be able to run quicker than yours is currently because each table will be returning up to 1 row per user.

     

    The second one which I think is a bit cleaner but could be slower.  It is essentially just grabbing all of the rows where the log type is either 3 or 12 and then processing it in the MAX function (determining what to send) based on the log type.

     

    Does this make sense?

     

    ~juddster

  9. By using JOINS instead of IN

     

    SELECT p.product_num 
    FROM products p
    JOIN tconversions t ON p.product_id = t.to_product_id to_product_id 
    JOIN products p2 ON t.fr_product_id =  p2.product_id 
    WHERE p2.product_num = '$product_num'
    

  10. For the comments table join since it is a LEFT JOIN, if there are no matching results then it will return NULL.  Because of that you should be adding your condition for the status on that table = in the ON clause instead of in there WHERE clause.  Because if it appears in the WHERE clause it needs to find a comment to show up (you could just have the condition as: tblComments.comments_status = 2 OR tblComments.comments_status IS NULL).

     

    ~juddster

  11. I would go one layer deeper where you are looking for 'td' and actually look for the 'a' tag.  Then you would be able to grab the innertext.

     

    /* An extension to your code */
    $visitor =  $visitor->find('td','1')->find('a','1')->innertext . "<br>";
    

     

    ~juddster

  12. != is does not equal, not /=

     

    That said, there is a very much an easier way of doing this ...

     

    /* Check if the dice and roll match */
    if ( $roll == $dice )
    {
         /* They do, congrats */
         print "Great Job, You're Good!";
    }
    else
    {
         /* They don't, too bad */
         print "Wrong";
    }
    
    /* Print the dice number */
    print "<img src='dice" . $dice . ".png'>"."<br />";
    

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