Doubt with SQL / PHP

2

I have the following query:

$qrysel = "select * from pack";
$ressel = mysqli_query($db, $qrysel);
$obj = mysqli_fetch_object($ressel);

In html I have this:

<?= $obj['pack_name']; ?>

How could I make it show the value according to a given id, without using WHILE and without putting WHERE in the query ...

Is it possible to set WHERE directly in the html obj?

Table:

<table>
  <tbody>
    <tr>
      <td>item 1</td>
      <td>item 2</td>
      <td>item 3</td>
    </tr>
    <tr><td>&nbsp;</td></tr>
    <tr>
      <td>item 4</td>
      <td>item 5</td>
      <td>item 6</td>
    </tr>
  </tbody>
</table>

If I were to use the while it would repeat all TDs then I need them to be displayed as above.

There are exactly 6 records in this table.

    
asked by anonymous 25.09.2017 / 20:10

1 answer

3

First of all you do the querry

$qrysel = "select * from pack";
$ressel = mysqli_query($db, $qrysel);
$obj = mysqli_fetch_object($ressel);

Then mount the table

                                <table>
                                    <thead>
                                        <tr>
                                                <th>id</th>
                                                <th>nome</th>
                                        </tr>
                                    </thead>
                                    <tbody>
                                        <?php
                                                foreach($ressel as $obj){ ?>
                                                <tr>
                                                   <?php if($obj['id']==1){echo "<td>"  .$obj['id']. "</td>";} else{ echo"sem registro";}?>
                                                   <?php if($obj['id']==1){echo "<td>"  .$obj['nome']. "</td>";}else{echo"sem registro";}?>
                                                </tr>
                                        <?php     }                                ?>
                                    </tbody>
                                </table>

Try to do this here, I think it will solve your problem!

    
25.09.2017 / 20:45