1

If I have a value of 1+ in a VARCHAR column in a MySQL table, how can I compare this variable in php?

 if ($days=="1+") 

does not appear to work, so how to compare it including the plus sign?

Perception
  • 79,279
  • 19
  • 185
  • 195
user2133342
  • 151
  • 1
  • 2
  • 8
  • 2
    Please explain your problem more fully. – Mere Development Mar 14 '13 at 01:34
  • in my mysql table i have a column DAYS, it has field types of varchar, and is filled with numbers 1 till 30, but also 1+. so, 1, 1+, 2, 3 etc. now i want to echo something when the value in DAYS is 1+, but i cannot use an IF as above since it sees it as just 1, not 1+ – user2133342 Mar 14 '13 at 01:37

2 Answers2

1

If in your database if you days column as varchar, than you will get the exact value (even with +), so:

if($days == "1+") is true

a more complete code for you to try

$res = mysql_query("SELECT days FROM table");
while( $row = mysql_fetch_assoc($res) ) {
    if($row["days"] == "1+") echo 'found' . '<br>';
}
  • Please don't write answers with old `mysql_` functions. [Find out why](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php) – Ja͢ck Mar 14 '13 at 01:58
0

Can you show us your query? I have a feeling that you've misidentified the issue.

That said, have you tried typecasting?

if ((string) $days == "1+") 
Poet
  • 91
  • 1
  • 3