如何将PHP变量插入到IF MySQL Row1 = Row2语句中

时间:2012-11-22 09:23:12

标签: php mysql sql database

这是我现在的代码:

<td align="center" valign="middle">
        <?php 
        // IF the users tips match with the correct tip, echo correct, else wrong on table cell
        if ($row['1g1']==$row['1w1']){
        ?>          
            <img src="../../images/tick-cross/Tick1.png" width="20" height="20" alt="Correct" border="0" />
        <?
        }
        else
        {
        ?>
            <img src="../../images/tick-cross/Cross1.png" width="20" height="20" alt="Wrong" border="0" />
        <?
        }
        ?>
        </td>

基本上,如果表格中的2行相等,则会插入勾选/勾选的图像,如果它们不是,则会插入十字形图像。

如果您感到困惑view the table here

好的,所以我想把'g'和'w'之前的数字变成变量,因为否则我必须改变它们数百次。 在线:

if ($row['1g1']==$row['1w1']){

我想成功:if ($row['$VARIABLEg1']==$row['$VARIABLEw1']){

这样做的正确语法是什么?它让我疯了!

2 个答案:

答案 0 :(得分:0)

尝试

if ($row[$VARIABLE . "g1" ]==$row[$VARIABLE . "w1"]) {

这应该有效

答案 1 :(得分:0)

通过在变量周围添加花括号来完成正确的语法:

$row["{$VARIABLE}g1"] == $row["{$VARIABLE}w1"]){

顺便说一句,它只适用于双引号。

相关问题