-1

Below is the base code I am trying for a product comparison. How can I highlight the larger/small value ? For example Consider the price as an example.

attached result screenshot

attached excel example with highlight on value

 $results = $mysqli->query('SELECT * FROM filterr where pid in ('.$pid1.''.$pid2.''.$pid3.''.$pid4.') ');

 ?>

// SETP FOUR : Displaying table values through HTML Table
<table> 
<thead>
    <tr>
     <th>Details</th>
     <th>Model 1</th>
     <th>Model 2</th>
     <th>Model 3</th>
     <th>Model 4</th>
    </tr>
</thead>

<tbody>
       <tr>
       <td>Manufacturer</td>
     <?php foreach ($results as $result){ ?>
         <td> <?php echo $result['product_brand']; ?> </td>
    <?php } ?>
    <tr>
      <tr>
       <td>Price</td>
     <?php foreach ($results as $result){ ?>
         <td> <?php echo $result['product_price']; ?> </td>
    <?php } ?>
    <tr>
      <tr>
       <td>Rating</td>
     <?php foreach ($results as $result){ ?>
         <td> <?php echo $result['score']; ?> </td>
    <?php } ?>
    <tr>
      <tr>
       <td>Battery</td>
     <?php foreach ($results as $result){ ?>
         <td> <?php echo $result['battery']; ?> </td>
    <?php } ?>
    <tr>
      <tr>
       <td>Storage</td>
     <?php foreach ($results as $result){ ?>
         <td> <?php echo $result['product_storage']; ?> </td>
    <?php } ?>
    <tr>
</tbody>
</table>
Shijil
  • 9
  • 6
  • 1
    you don't need to write multiple `foreach` loops, 1 is enough – meewog Jul 30 '20 at 11:34
  • It looks like your SQL is broken. See https://stackoverflow.com/questions/7537377/how-to-include-a-php-variable-inside-a-mysql-statement – Dharman Jul 30 '20 at 16:23
  • @Mehrdad Dastgir, I will try to improve it, I couldn't figure out the foreach loop and tables together. it was confusing. – Shijil Jul 31 '20 at 04:50
  • @Dharman, thank you for the tip, I will definitely try the suggested link. I was just testing the code. – Shijil Jul 31 '20 at 04:51
  • 1
    @Dharman, please tell me, if you mean the `('.$pid1.''.$pid2.''.$pid3.''.$pid4.'` part as wrong ? if yes, I am aware of that. is there any other SQL issues in this code ? – Shijil Jul 31 '20 at 05:51

1 Answers1

1

you can use simple if like :

.green{background-color:green;}
<?php if( $result['product_price'] > 5000 ){ //higher then ?>
<td class='green'>
<?php }else{ ?>
<td>
<?php } ?>

You can use same method for lower with another class.

Simone Rossaini
  • 8,115
  • 1
  • 13
  • 34
  • I will try it , thank you for giving the time and effort. – Shijil Jul 31 '20 at 04:51
  • this can be used for "score/rating" section. But cant use for price or anything else. If we set `$result['product_price'] > 5000 ` and a user try to compare smartphone below 5000, it wont work. The `` should work based on displayed values. – Shijil Jul 31 '20 at 06:03
  • it's was an example, you can use all math you need. give me another example i will help you – Simone Rossaini Jul 31 '20 at 06:12
  • Can you upvote and acept the question if solve your problem? – Simone Rossaini Sep 30 '20 at 11:24