Print value based on the coloumns value - MYSQL, PHP -
if c2 column value '03' want print 'k9' , if value 'o4' want print 'k10' else other values, should show it.
how can that..
//my code// select a.capacity,a.comment, b.c1,b.c2,b.c3 table1 inner join table2 b on a.capacity=b.capacity 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>"; }
try replace while loop , check, may work :
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>"; }
Comments
Post a Comment