0

如果 C2 列的值为“03”,我想将其打印为“K9”,如果它的值为“O4”,那么我想将其打印为“k10”,否则任何其他值,它应该显示它。

我怎样才能做到这一点..

        //my code//
select a.capacity,a.comment, b.c1,b.c2,b.c3 from table1 a inner join table2 b on a.capacity=b.capacity WHERE a.capacity= $name

      $rs = mysql_query( $sql ) or die('Database Error: ' . mysql_error());


        $num = mysql_num_rows( $rs );

        if($num >= 1 ){
            echo "";
            while($row = mysql_fetch_array( $rs )){
        echo "<table>
            <tr>
                <th align='left' valign='middle'>Capacity</th>
                <td align='left' valign='middle'>$row[capacity]</td>
            </tr>
            <tr>
                <th align='left' valign='middle'>C2</th>
               <td align='left' valign='middle'>$row[c2]</td>
                </tr>               
            </table>";
         }
4

1 回答 1

0

尝试用这个while循环替换并检查,它可能对你有用:

 while($row = mysql_fetch_array( $rs )){
    $row['c2'] = ( $row['c2'] == '03') ? 'K9' : $row['c2'] ;
    $row['c2'] = ( $row['c2'] == 'O4') ? 'k10' : $row['c2'] ;
    echo "<table>
        <tr>
            <th align='left' valign='middle'>Capacity</th>
            <td align='left' valign='middle'>$row[capacity]</td>
        </tr>
        <tr>
            <th align='left' valign='middle'>C2</th>
           <td align='left' valign='middle'>$row[c2]</td>
            </tr>               
        </table>";
     }
于 2013-05-14T06:48:53.377 回答