Jump to content

if statement inside a function problem


GD77

Recommended Posts

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
Share on other sites

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
Share on other sites

$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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.