GD77 Posted July 11, 2012 Share Posted July 11, 2012 Hello, I ve the following code and the if is always returning returning true: function db_LA() { $this->u_tst="....."; $qry_1=mysql_query("SELECT COUNT(`yyy`) FROM `tbl` WHERE `id_tst`='".$this->u_tst."' "); $fetch_1=mysql_result($qry_1,0,0); if($fetch_1==0) { $qry_2=mysql_query("INSERT INTO `tbl` (...) VALUES (...) or die(mysql_error()); } if($fetch_1>0 && $fetch_1<4) { $qry_2_Update=mysql_query("UPDATE `tbl` SET `att` = `att` +1 WHERE `id`='".$this->u_tst."'); } } //if($fetch_1>0 && $fetch_1<4) { <---- this is being exsecuted even if the value was above 4 Link to comment https://forums.phpfreaks.com/topic/265511-if-statement-inside-a-function-problem/ Share on other sites More sharing options...
Barand Posted July 11, 2012 Share Posted July 11, 2012 When it IS 4 or when you EXPECT it to be 4? echo its value to check Link to comment https://forums.phpfreaks.com/topic/265511-if-statement-inside-a-function-problem/#findComment-1360728 Share on other sites More sharing options...
GD77 Posted July 11, 2012 Author Share Posted July 11, 2012 $fetch_1>0 && $fetch_1<4 <-- means values betwen 0 and 4 1,2,3... f the value is 5 or 6 the code should not be executed so why is it? Link to comment https://forums.phpfreaks.com/topic/265511-if-statement-inside-a-function-problem/#findComment-1360731 Share on other sites More sharing options...
abdfahim Posted July 11, 2012 Share Posted July 11, 2012 I don't see any problem except those syntax issues in query lines. Try to echo variable $fetch_1 before if loops. $qry_2=mysql_query("INSERT INTO `tbl` (...) VALUES (...)") or die(mysql_error()); $qry_2_Update=mysql_query("UPDATE `tbl` SET `att` = `att` +1 WHERE `id`='".$this->u_tst."'"); Link to comment https://forums.phpfreaks.com/topic/265511-if-statement-inside-a-function-problem/#findComment-1360733 Share on other sites More sharing options...
smoseley Posted July 11, 2012 Share Posted July 11, 2012 $fetch_1>0 && $fetch_1<4 <-- means values betwen 0 and 4 1,2,3... f the value is 5 or 6 the code should not be executed so why is it? As was stated, it's executing because the value is not actually > 4, as you believe. Try adding this line to your code, and you'll see something other than you expect. $fetch_1=mysql_result($qry_1,0,0); echo $fetch_1; Link to comment https://forums.phpfreaks.com/topic/265511-if-statement-inside-a-function-problem/#findComment-1360734 Share on other sites More sharing options...
GD77 Posted July 11, 2012 Author Share Posted July 11, 2012 oh man I m stupid :/ Link to comment https://forums.phpfreaks.com/topic/265511-if-statement-inside-a-function-problem/#findComment-1360736 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.