Jump to content

[SOLVED] Creating an if statment made out of variables.


pocobueno1388

Recommended Posts

What I am trying to do is create an if statement that is made out of purely variables, but I am having trouble getting it to work properly.

 

Here is my code, I will comment through it to help you understand:

<?php
   
   //I select the fields I am dealing with from the database.
   $funInfo = mysql_query("SELECT discipline, height FROM horses WHERE horseID='$horseID'");
   $f = mysql_fetch_assoc($funInfo);

   //Here are the two variables I am working with
   $stat = trim($split_first[0]); //echos out "discipline"
   $split_first[1]; //This variable got it's value earlier in the script. It echos out "== 'western' "

   //Build the IF statment
   if ($f[$stat].$split_first[1]){
       echo 'The statement is true!';
    }
?>

 

So I am basically trying to get this line:

if ($f[$stat].$split_first[1]){

 

to be read as an if statement by PHP that should look something like this:

if (english == 'western'){

 

But for some reason it is always returning true....and it shouldn't.

 

Any advice on how to build this if statement with variables would be greatly appreciated. Thanks xD

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.