我在IF ELSE中遇到错误

I am new in PHP. I face problem in my IF ELSE. My IF ELSE Statement is not working. I have two sql queries. In starting i have a simple query which fetch client_id against opinion_id and store the result of thi squery in a variable $opinion_id

After that i have my sql query which fetch the all opinion_id against client_id which is fetched from previous query.

My 3rd query is for that if there is no client_id against opinion_idwith reference to my 1st query than it only print the record against thatopinion_id`

In My IF ELSE I have a problem it always execute my ELSE part if my client_id is null or not.

My remaining PHP code is

$opinion = array();

while($row1 = mysql_fetch_assoc($result1))
{        
    $opinion[]= $row1['opinion'];
    $action[]= $row1['atitle'];
    $long_term[]= $row1['ltitle'];
    $outlook[]= $row1['otitle'];
    $rating_type[]= $row1['ttitle'];
    $short_term[]= $row1['stitle'];


}

Html Code is

<?php
include ("connection.php");
include ("sqlquery.php");
    ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
table {
    border-collapse: collapse;
}

table, td, th {
    border: 1px solid black;
}
</style>
<title>Untitled Document</title>
</head>

<body>
<div style="margin-top:auto; width:auto;font-family:'Times New Roman', Times, serif; text-align:left; font-size:12px; text-align:center">
<table width="657">
        <tr>
            <td width="225"> <strong>Opinion</strong></td>
            <td width="62"> <strong>Action</strong></td>
            <td colspan="4"><strong>Ratings</strong></td>
            <td width="54"><strong>Outlook</strong></td>
            <td width="67"><strong>Rating Type</strong></td>
        </tr>
        <tr>
          <td width="225">&nbsp;</td>
          <td width="62">&nbsp;</td>
          <td colspan="2"><b>Long Term</b></td>
          <td colspan="2"><b>Short Term</b></td>
          <td width="54">&nbsp;</td>
          <td width="67">&nbsp;</td>
        </tr>
        <tr>
          <td width="225">&nbsp;</td>
          <td width="62">&nbsp;</td>
          <td width="52"><b>Current</b></td>
          <td width="45"><b>Previous</b></td>
          <td width="49"><b>Current</b></td>
          <td width="51"><b>Previous</b></td>
          <td width="54">&nbsp;</td>
          <td width="67">&nbsp;</td>
        </tr>
        <?php
        for ($i=0; $i<count($opinion); $i++) {
    //if ($opinion[$i] == "")continue;
        ?>


    <tr>
           <td><?php echo $opinion[$i]?></td>
          <td><?php echo $action[$i] ?></td>
          <td><?php echo $long_term[$i] ?></td>
          <td><?php //echo $p_long_term[$i]?></td>
          <td><?php echo $short_term[$i] ?></td>
          <td><?php //echo $p_short_term[$i] ?></td>
          <td><?php echo $outlook[$i] ?></td>
          <td><?php echo $rating_type[$i] ?></td>
        </tr>

        <?php
        }
?>
 </table>
 <tr>
          <td width="225"><?php // echo $liaison_one_chunks[0]?></td>
          <td width="62"><?php //echo $liaison_one_chunks[1]?></td>
          <td width="52"><b><?php //echo $liaison_one_chunks[2]?></b></td>
          <td width="45"><b><?php //echo $liaison_one_chunks[3]?></b></td>
          <td width="49"><b><?php //echo $liaison_one_chunks[4]?></b></td>

        </tr>
 <table>

 </table>
        </div>
</body>
</html>

I forget to execute my query in PHP. I just solved my problem by executing of my query.

    $opinion_id = "SELECT `client_id` FROM `pacra_client_opinion_relations` WHERE `opinion_id` = 170";
$result = mysql_query($opinion_id) or die;
$row = mysql_fetch_assoc($result);
$client_id = $row['client_id'];

Before you write:

if($opinion_id == NULL){
    $query = $q_opinion1;
    }
    else
    { 
        $query = $q_opinion;
    }
  $result1 = mysql_query($query) or die;

You must have a returned value from the query or otherwise in order to use that in the $opinion_id. For instance, did you try to echo $opinion_id and see what you got?

Something like:

$opinion_id = $returned_value;
if($opinion_id == NULL){
    $query = $q_opinion1;
    }
    else
    { 
        $query = $q_opinion;
    }
  $result1 = mysql_query($query) or die;