Hello,
I'm using the following code which works fine:-

if($Text_Box_2 == '0x0x0x0')
{
$query2=("INSERT INTO query_results2 (Location1, Average_Income) VALUES ('$Text_Box_1', '$area_1')");
}

My problem is I need to run similar if statements on $Text_Box_3 and $Text_Box_4 and $Text_Box_5 and $Text_Box_6 and $Text_Box_7 and $Text_Box_8 to see whether any of these text boxes are == '0x0x0x0'.

Is there an elegant way to do this in a one line statement?

Thank you very much for your guidance.

    Thank you all for reading. After some experiments, I discovered how to solve this problem of mine in the best way I knew how :-) Anyway, this is how I solved it:-

    if($Text_Box_2 == '0x0x0x0' and $Text_Box_3 == '0x0x0x0' and $Text_Box_4 == '0x0x0x0' and $Text_Box_5 == '0x0x0x0' and $Text_Box_6 == '0x0x0x0' and $Text_Box_7 == '0x0x0x0' and $Text_Box_8 == '0x0x0x0')
    			{
    			$query2=("INSERT INTO query_results2 (Location1, Average_Income) VALUES ('$Text_Box_1', '$area_1')");
    			}

    I appreciate all the help I've been getting from many people on this forum. Thank you once again.

      ...change your if statement if you want SOME and not ALL of statements to be true...
      Because you stated:

      transfield wrote:

      to see whether any of these text boxes are == '0x0x0x0'.

      In your example - you check if every variable is equal to 0x0x0x0, BUT if you want to check if some of them is, and not necessarilly all, equal to 0x0x0x0, use something like:

      if($Text_Box_2 == '0x0x0x0' or $Text_Box_3 == '0x0x0x0' or $Text_Box_4 == '0x0x0x0' or $Text_Box_5 == '0x0x0x0' or $Text_Box_6 == '0x0x0x0' or $Text_Box_7 == '0x0x0x0' or $Text_Box_8 == '0x0x0x0')
      

        Yes, I understand what you mean now & I thank you very much for your guidance. God bless you, Bodzan.

          Would be far better to use arrays instead of raw naming of the variables.

          eg, make it so $Text_Box[2] works instead of $Text_Box_2

          Also, keep your variables descriptive - Text_Box ? Whats that? Is it the price of something? Then use $price for example.

            Thank you for your advice, Plasma. I need to study what arrays are all about because I don't know how they work. Nevertheless, I suppose that using arrays would make the code shorter, perhaps?

            I appreciate your advice & it looks like I've got a lot to learn.....:-)

            Thank you once again & warm regards.

              Write a Reply...