Please I have a field in my data base with a type text, but that could contains some integer value.
When I select data from this field I should distinct if is an integer or text (Just to handle mysql operation like < or >) So I’ve tried :
$clause = "";
if(is_int($_GET['f']))
$clause = " AND myValue < ".$_GET['f']." ";
else
$clause = " AND myValue = '".$_GET['f']."' ";
$ds->query("SELECT * FROM myTable WHERE id = 1 ".$clause);
please note the quote in case it wasn’t an integer.
But this doesn’t work and it’s normal I think because the field has a type text.
Please have you any solution for this problem. Thanks in advance !
A
texttype column always treats its values as text (a string), so regardless of what value is stored, you need to enclose it in'. MySQL can compare a number as a string.Also,
is_intis not suitable for checking$_GETvalues, as they are considered strings. Useis_numericinstead.But notice the comments to your question, a redesign is more suitable if you need to store integers and/or strings separately in your database.