Home > Enterprise >  Match text and img in Datatables PHP
Match text and img in Datatables PHP

Time:11-15

So, I'm generating some dummy data with FakerPHP

Either by generating data or manually putting it into my Datatables
Based on the BRAND of the car, id like to automatically display the right IMG

For example I generate 500 new rows of BRAND "AUDI"
and I want to auto display "AUDI.jpg"
In every column that BRAND is AUDI, display the logo picture as well.

What would be the optimal way to do this?
Example: https://i.imgur.com/vrP16ig.png

CodePudding user response:

you can name logo picture same as brand name so that in picture column you can display logo base on brand name like the recontructed table below:

<table border="1">

                <thead>
                    <tr>

                        <th >BRAND</th>
                        <th >Model</th>
                        <th >Sub model</th>
                        <th >year</th>
                        <th >price</th>
                        <th >Photo</th>
                    </tr>
                </thead>
    
                <tbody>
                    <tr>
                        <td><?php echo $row['brand']; ?></td>
                        <td><?php echo $row['model']; ?></td>
                        <td><?php echo $row['submodel']; ?></td>
                        <td><?php echo $row['year']; ?></td>
                        <td><?php echo $row['price']; ?></td>
                        <td><img src="images/<?php echo $row['brand']; ?>.jpg" alt="" ></td>
                    </tr>
    </tbody>

</table>
  • Related