vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   Member Archives (https://vborg.vbsupport.ru/forumdisplay.php?f=202)
-   -   Need Help (https://vborg.vbsupport.ru/showthread.php?t=39201)

Neo 05-29-2002 08:00 PM

Need Help
 
I have a table that is set to varchar(50) and I put both numbers and letter in it... now I cant figure out how to get this code to work..... i always returns string even with numbers..

PHP Code:

    if (!is_int($userinfo[table])) { 
      echo 
"String<br>";
    } else {
      echo 
"Integer<br>";
    } 

can anyone help?

Xenon 05-29-2002 08:10 PM

i'm not sure, but doesn't mean varchar(50) that it is always a string with 50 chars like: "12345 " is a string.

try !is_int(trim($userinfo[table]))

but i'm not sure ;)

Neo 05-29-2002 08:19 PM

I was thinking that. I just needed a second opinion. ;)

Neo 05-29-2002 08:43 PM

Hmm... doesnt work. Damn this is a pain...

Logician 05-30-2002 09:18 AM

in PHP there is no strict variable types: every string can be an integer and every integer can be a string.

eg. if you have a string like "45asda23" and use it as an integer, you can, php will convert it to 45.

So what exactly trying to do with this code? In other words when you want your script to return "integer" result?

if you want to return integer when there is no chars in the string except a number, you can use this:

PHP Code:

if ((string)($userinfo[table])!=(int)($userinfo[table])) 

    echo 
"String<br>";
}
else 
{
    echo 
"Integer<br>";


or try "is_numeric" :

PHP Code:

if (is_numeric($userinfo[table]))

    echo 
"Integer<br>";
}
else 
{
    echo 
"String<br>";



is_int checks the variable type only, not the context of variable..

Regard,
Logician

Admin 05-30-2002 09:32 AM

Also bear in mind, that like forms, MySQL will always return data as a string, even if the field is INT. So yes, is_numeric() is the best way to do this.

Another method would be:
PHP Code:

if ($variable == ($variable 0)) {
// It's a number



Neo 05-30-2002 12:47 PM

Thank You.


All times are GMT. The time now is 04:26 PM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01139 seconds
  • Memory Usage 1,725KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (4)bbcode_php_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (7)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete