No announcement yet.

Should be a couple of simple questions...

  • Filter
  • Time
  • Show
Clear All
new posts

  • Should be a couple of simple questions...

    OK... this is likely incredibly simple... but I'm a total newb and simply don't know who to do it.

    I need to extract a string from a custom user field, convert it to an integer, do some math on it, then write the modified integer back to the profile field as a string.

    Also, I need it to check that the string is indeed just a number and not text, because some users will have text in that field rather than numbers.

    The second question is a bit harder.

    When an option in my vB is called, I want it to set one of the custom userfields with the current date and time...

    And then... I need code that checks the timestamp in that field to see whether 30 days have passed or not. If they have, then it performs another function.

    The reason behind this is that many custom titles in my forum are temporary in nature and only last 30 days. I'm looking for a way to automatically make them expire and reset to default.

    Can anyone post some code that would do these things?

  • #2
    $query="SELECT field FROM table WHERE field=variable";

    That will select the data and convert it into an integer number, to turn something into an integer just add round()


    • #3
      I was under the impression that round() converted a real number to an integer.

      I need to convert a text string to an integer.


      • #4
        PHP variables are by default 'variant'. That means that they can conform to any datatype.

        If you need to cast your variables as a specific datatype, you can use settype(). Or you can simply cast the type when you do this:
        PHP Code:
        $string "123.456";      // initial string of numbers
        $var = (int) $string;     // integer
        $var = (float) $string;   // floating decimal
        $var = (string) $string;  // back to string 
        Read more about type casting here.


        • #5
          OK, I have the string-integer thing under control.

          But can anyone help me with the timestamp thing?


          widgetinstance 262 (Related Topics) skipped due to lack of content & hide_module_if_empty option.