douzhiba6873 2015-09-21 11:35
浏览 48
已采纳

我在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>
  • 写回答

2条回答 默认 最新

  • douyan4243 2015-09-22 05:32
    关注

    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'];
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥20 数学建模,尽量用matlab回答,论文格式
  • ¥15 昨天挂载了一下u盘,然后拔了
  • ¥30 win from 窗口最大最小化,控件放大缩小,闪烁问题
  • ¥20 易康econgnition精度验证
  • ¥15 msix packaging tool打包问题
  • ¥28 微信小程序开发页面布局没问题,真机调试的时候页面布局就乱了
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能