in this double condition [else if($test1[0] == "Regular Project" && $test1[0] == "FSA Project")] is not working properly. this is the way to do . or in_array i have to use.

   $sql1 = "SELECT Select_Type,Prj_Id,Status FROM PROJECT_ACTIVE WHERE Memr_Id='$data[0]'";
   $test = mysql_query($sql1);
   $test1 = mysql_fetch_array($test);

   /*echo "<select name='selecttype'>";
   for($i=0;$i<3;$i++)
   {
       echo " value ".$test1[0];
       echo "value 1".$a[0];
       if(in_array($test1[0], $a[i])){
           continue;
       }
       else
       {
           echo "<option value='$a[i]' >$a[i]</option>";             
       }
   }
   echo "<select>";*/




     if($test1[0] == "Regular Project"){
     echo "<select name='selecttype'>
        <option value='TGF Project'>TGF Project</option>
        <option value='FSA Project'>FSA Project</option>
        </select>";
        }

        else if($test1[0] == "FSA Project")
        {
        echo "<select name='selecttype'>
        <option value='Regular Project'>Regular Project</option>
        <option value='TGF Project'>TGF Project</option>
        </select>";
        }

        else if($test1[0] == "TGF Project")
        {
        echo "<select name='selecttype'>
        <option value='Regular Project'>Regular Project</option>
        <option value='FSA Project'>FSA Project</option>
        </select>";
        }
        else if($test1[0] == "Regular Project" && $test1[0] == "FSA Project"){
        echo "<select name='selecttype'>
        <option value='TGF Project'>TGF Project</option>
        </select>";
        }
        else if($test1[0] == "Regular Project" && $test1[0] == "TGF Project"){
        echo "<select name='selecttype'>
        <option value='FSA Project'>FSA Project</option>
        </select>";
        }
        else if($test1[0] == "FSA Project" && $test1[0] == "TGF Project"){
        echo "<select name='selecttype'>
        <option value='Regular Project'>Regular Project</option>
        </select>";
        }
        else
        {
        echo "<select name='selecttype'>
        <option value='Regular Project'>Regular Project</option>
        <option value='FSA Project'>FSA Project</option>
        <option value='TGF Project'>TGF Project</option>
        </select>";
        }

Dani AI

Generated

You cannot make one scalar value equal two different strings at the same time, so a condition that checks the same variable for two different labels with && will always be false. If the goal is to show only the project types a member has not already used, collect the member’s existing types into an array and subtract them from the full set of options, then render the remaining choices.

Example approach using PDO and set logic:

// Fetch all existing types for this member
$stmt = $pdo->prepare('SELECT Select_Type FROM PROJECT_ACTIVE WHERE Memr_Id = ?');
$stmt->execute([$memrId]);
$chosen = array_map('trim', $stmt->fetchAll(PDO::FETCH_COLUMN));

// Define the full list of allowed types
$all = ['Regular Project', 'FSA Project', 'TGF Project'];

// Compute available options by removing already-chosen ones
$available = array_values(array_diff($all, $chosen));

// Render the select
echo '<select name="selecttype">';
foreach ($available as $label) {
    $esc = htmlspecialchars($label, ENT_QUOTES, 'UTF-8');
    echo "<option value=\"$esc\">$esc</option>";
}
echo '</select>';

Notes:

  • Use || when either of multiple values is acceptable for one variable; use && when comparing different variables or array members (e.g., $a == 'X' && $b == 'Y'). See PHP logical operators.
  • array_diff and in_array are ideal for this pattern; docs: array_diff, in_array.
  • The legacy mysql_* API is removed; prefer PDO or MySQLi with prepared statements for safety and future compatibility (PDO, MySQLi).

Recommended Answers

All 5 Replies

lets assume you have array

$test1 = array("Regular Project", "FSA Project", "TGF Project");

so when you select double condition like this
if ($test1[0] == "Regular Project" && $test1[0] == "FSA Project")
$test[0] contain one value in this moment, its either Regular Project or FSA Project so that why double condition not working.

How can i mention! i will use || instead of &&. i tried with ||,not getting what i expect.

sorry for asking,this is the right way?

else if($test1[0] == "Regular Project" ){
            if($test1[0] == "FSA Project"){
            echo "<select name='selecttype'>
            <option value='TGF Project'>TGF Project</option>
            </select>";
            }
        }

if($test1[0] == "Regular Project" )
in this line $test1[0] contain value "Regular Project" so its impossible to have another value "FSA Project", I suggest have another array or another variable contain other value so we can check like :
if ($test1[0] == "Regular Project" && $test2[0] == "FSA Project")

Thanks,Ya i checked but if the conditoin is like this

else if($test1[0] == "FSA Project" && $test_2[0] == "TGF Project"){

            echo "<option value='Regular Project'>Regular Project</option>";

        }

it should come regular project only! but this is checking single condition

else if($test1[0] == "TGF Project")
        {
        echo "<option value='Regular Project'>Regular Project</option>
        <option value='FSA Project'>FSA Project</option>";
        }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.