Dear experties, I have a problem which is my code not running correct way. I want to display data by radio button and checkbox selection. Maybe my if else statement have a problem.. If select "All", data show correctly, but if select "My Task" data not shown correctly..seem like my query not work as I want..
Any body can help me out??? Plsss..

This code is form for selection :

<form name="form1" method="post" action="test_view.php">
  <table width="200" align="center" cellspacing="0">
    <tr>
      <td colspan="2">&nbsp;</td>
    </tr>
    <tr>
      <td width="98"><input name="by" type="radio" id="by" value="all" checked>
      <label for="by">All</label></td>
      <td width="96"><input type="radio" name="by" id="by" value="my">
      <label for="by">My Task</label></td>
    </tr>
    <tr>
      <td height="28" colspan="2"><input name="s1" type="checkbox" id="s1" value="1">
        Pending</td>
    </tr>
    <tr>
      <td colspan="2"><input name="s2" type="checkbox" id="s2" value="2">
      <label for="s2">Open</label></td>
    </tr>
    <tr>
      <td colspan="2"><input name="s3" type="checkbox" id="s3" value="3">
      <label for="s3">Monitor</label></td>
    </tr>
    <tr>
      <td colspan="2"><input name="s4" type="checkbox" id="s4" value="4">
      <label for="s4">Close</label></td>
    </tr>
    <tr>
      <td colspan="2"><input type="submit" name="View" id="View" value="View"></td>
    </tr>
  </table>

This code for query (test_view.php)

<?php
extract ($_POST);
include 'template.php';
$username = $_SESSION['username'];
$sqlmy = "SELECT * FROM user WHERE username='$username'";
$resultmy = mysql_query($sqlmy);
$rowmy = mysql_fetch_array($resultmy);
$pic = $rowmy['name'];


if(isset($_POST['View']))

if(isset($s1))
 $stts1=$s1;
 else
 $stts1=NULL;

if(isset($s2))
 $stts2=$s2;
 else
 $stts2=NULL;

if(isset($s3))
 $stts3=$s3;
 else
 $stts3=NULL;

if(isset($s4))
 $stts4=$s4;
 else
 $stts4=NULL;

$selstts = $stts1."".$stts2."".$stts3."".$stts4; 

?>


<form name="form1" method="post" action="">
  <p>&nbsp;</p>

  <table width="200" cellspacing="0">
    <tr>
      <td>ID</td>
      <td>Status</td>
    </tr>
    <?php


        if ($by=="all"){
        $sql="SELECT * FROM request WHERE status='$stts1' OR status='$stts2' OR status='$stts3' OR status='$stts4'";

        }
        else if ($by=="my"){
        $sql="SELECT * FROM request WHERE status='$stts1' OR status='$stts2' OR status='$stts3' OR status='$stts4' AND curPIC='$pic'";

        }
        $result=mysql_query($sql);
        while ($row=mysql_fetch_array($result)) { 
    ?>
    <tr>
      <td><?php echo $row['misRefId']; ?></td>
      <td><?php echo $row['status']; ?></td>
    </tr>
    <?php } ?>
  </table>
  <p>&nbsp;</p>
</form>

Plsss help me...

Are you getting any errors?

You need to add else to the end of your if statement.
So do something like:

if ($by=="all"){
    $sql="SELECT * FROM request WHERE status='$stts1' OR status='$stts2' OR status='$stts3' OR status='$stts4'";
}else if ($by=="my"){
    $sql="SELECT * FROM request WHERE status='$stts1' OR status='$stts2' OR status='$stts3' OR status='$stts4' AND curPIC='$pic'";
}else{
    $sql="SELECT * FROM request WHERE status='$stts1' OR status='$stts2' OR status='$stts3' OR status='$stts4'";
}

Thanks for reply glycerine..
Already update my code but still same.. no error message i get..
only if select "My Task" code not query correctly.. don't know why..
Actually I had display the value and try to match but still same.. :(

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.