Question

I'm trying to show images based on some labels with jQuery datatables.

               <?php
                while ($row = mysql_fetch_array($result2)) {
                    ?>
                    <tr>
                        <td><?=$row['IP']?></td>
                        <td><?=$row['Agent']?></td>
                        <td><?=$row['Verified']?></td>

                        if($row['Label'] == "Other"){
                        <td><img src="imgb.png"></td>
                        }
                        else{
                        <td><img src="imgc.png"></td>
                        }

                    </tr>
                 <?php
                }
                ?>

The problem is the 'if part' is not working, it just show all the two images. And also it echo following.

if($row['Label'] == "Other"){ } else{ } if($row['Label'] == "OtherCrawler"){ } else{ } if($row['Label'] == "OtherCrawler"){ } else{ } 

What is wrong here?. Please consider I'm bit new to php/jQuery.

Was it helpful?

Solution

Because you need to start php tags before and after if

<?php if($row['Label'] == "Other"){ ?> <td><img src="imgb.png"></td> <?php } else{ ?> <td><img src="imgc.png"></td> <?php } ?>

OTHER TIPS

            <?php
               while ($row = mysql_fetch_array($result2)) {
                ?>
                <tr>
                    <td><?=$row['IP']?></td>
                    <td><?=$row['Agent']?></td>
                    <td><?=$row['Verified']?></td>
                  <?php
                    if($row['Label'] == "Other"){
                  ?>
                    <td><img src="imgb.png"></td>
                <?php  }
                    else{
                    <td><img src="imgc.png"></td>
                    }
                  ?>
                </tr>
             <?php
            }
            ?>

Above answer is for image display when it returns using while/for-each loop from the database. But when we are using ssp.customized.class file then it will be not in use.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top