Jump to content

marcus

Members
  • Posts

    1,842
  • Joined

  • Last visited

Posts posted by marcus

  1. for($i = $startNum; $i <= $endNum; $i += $increment){
        echo "The square of " . $i . " is " . ($i*$i) . "<br/>\n";
    }
    
    // alternatively
    
    $range = range($startNum, $endNum, $increment);
    
    foreach($range AS $value){
        echo "The square of " . $value . " is " . ($value*$value) . "<br/>\n";
    }

  2. You don't need to use $this because it's within the scope of the function.

     

    Also on your if statements, are you trying to check if the value of $k isn't equal to the value of $v? If so, then you would use $k != $v, because what you're saying now is $v is set to NOT $k which would become false regardless.

  3. $input = 100;
    $array = array(50.5, 40.5, 35);
    
    $remainder = 0;
    
    foreach($array AS $num){
        $remainder = ($remainder == 0) ? $input : $remainder;
        $out = $remainder - $num;
        if($out < 0){
            break;
        }
        $remainder = $out;
    }
    
    echo $remainder;

     

    Just a quick example of how I interpreted your code. I get the result of "9" when I use input=100 and the array=[50.5, 40.5, 35]

     

    Give a try and implement my code into yours.

  4. I more valuable solution instead of using getsqlvaluestring is type casting.

     

    $a = "57878.044cats";
    
    var_dump((int)$a, (string)$a, (double)$a, (float)$a, (bool)$a);

     

    int(57878) string(13) "57878.044cats" float(57878.044) float(57878.044) bool(true)

  5. Why would you store a person's password in the directory name? That is just plain stupid. You could literally just store it under the username, why would you allow multiple users to have the same username?

  6. Personally I would just store it as the seconds. But if you wanted to use either DATETIME or TIMESTAMP I would use TIMESTAMP.

     

    It's easier to calculate the time differences using the actual seconds. Going from TIMESTAMP to seconds and then finding the time difference requires that conversion.

  7. Since time is a method it can't just be called in the middle of a variable unless escaped. You could have assigned the time method to a variable ($time = time()) and used $time in your query if you wanted. You aren't restricted to using the UNIX_TIMESTAMP() and NOW() MySQL methods, you can use the PHP time() method, but you have to escape it or assign it to a variable for it to work in your query.

     

    You could do the math in MySQL or PHP, it's really up to you.

     

    SELECT (UNIX_TIMESTAMP(NOW()) - last_activity) as lastActive FROM member

     

    Then loop through the results.

     

    while($row = mysqli_fetch_assoc($query){
         $indicator = ($row['lastActive'] < 50) ? "green" : ((in_array($row['lastActive'], range(50,100))) ? "idle" : "offline");
         // 0-49 = green, 50-100 = idle, > 100 = offline, you can change those values to correspond with however you want it to be
         // maybe Online = last 15 minutes, idle = 15-30 minutes, offline = > 30 minutes
         // lastActive will return in seconds so 15 minutes = 900 seconds
    }

  8. Well look at it this way. If you don't escape time() the query is going to treat it as string(6) "time()" instead of the Unix timestamp we were looking for. Using the MySQL methods UNIX_TIMESTAMP and NOW() we don't have to worry about them being parsed as strings because MySQL will recognize them and treat them as methods instead of strings.

     

    You could continue using time() if you wanted to, like:

    $q2 = "UPDATE member SET logged_in = ?, last_activity = '".time()."', updated_on = NOW() WHERE id = ? LIMIT 1";

     

    Hope that clears things up.

  9. How am I supposed to help you when I don't know how your GetSQLValueString function works? Or even where it's implemented in your code.

     

    You are posting ZERO information on how we can help you, provide usable code, give us something other than "meh it doesn't work."

  10. The reason for your error is because the mysqli_prepare statement is returning false. It could either be because a) Your connection is invalid or b) The query is wrong.

     

    Try making this change to your query:

     

    $q2 = "UPDATE member SET logged_in = ?, last_activity = UNIX_TIMESTAMP(NOW()), updated_n = NOW() WHERE id = ? LIMIT 1";

  11. It exists in your code, not mine, so I don't know how your's works.

     

    Go ahead and test my function with any SQL injection, it will always return the empty string (or a float value if it begins with an integer)

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