$query = "SELECT category,name,brand,count,price,count*price,unit FROM goods order by category"; $result = mysqli_query ($conn, $query) or die ('Error'); if($result) { $rows = mysqli_num_rows($result); echo "<table border='3' bgcolor='#696969'><tr><td>Category</td><td>Name</td><td>Brand</td><td>Count</td><td>Price</td><td>Summary price</td><td>Unit tovar</td></tr>"; for ($i = 0 ; $i < $rows ; ++$i) { $row = mysqli_fetch_row($result); echo "<tr>"; for ($j = 0 ; $j < 7 ; ++$j) echo "<td>$row[$j]</td>"; echo "</tr>"; } echo "</table>"; mysqli_free_result($result); } 

It is necessary to replace the duplicate values ​​of category with a blank value when the table is displayed.

enter image description here

  • And what was the problem? - Enikeyschik
  • if ($ result) {$ rows = mysqli_num_rows ($ result); echo "<table border = '3'> <tr> <td> Category </ td> <td> Name </ td> <td> Brand </ td> <td> Count </ td> <td> Price < / td> <td> Summary price </ td> <td> Unit </ td> </ tr> "; for ($ i = 0; $ i <$ rows; ++ $ i) {$ row = mysqli_fetch_row ($ result); echo "<tr>"; for ($ j = 0; $ j <7; ++ $ j) {if ($ i === 0 && $ j> 0 && $ row [$ j] === $ row [$ j - 1]) echo "<td> </ td>"; else echo "<td> $ row [$ j] </ td>"; } echo "</ tr>"; } echo "</ table>"; mysqli_free_result ($ result); } - user275180
  • this way does not work - user275180
  • Questions asking for help with debugging (“why does this code not work?”) Should include the desired behavior, a specific problem or error, and a minimum code for playing it right in the question. Questions without an explicit description of the problem are useless for other visitors. - Enikeyschik 1:01

1 answer 1

You can add a variable to check for a repeating category. For example:

 //... $current_category = -1; for ($i = 0 ; $i < $rows ; ++$i){ $row = mysqli_fetch_row($result); echo "<tr>"; for ($j = 0 ; $j < 7 ; ++$j){ echo "<td>"; if($j == 0){ if($row[$j] != $current_category){ // если категория новая, выводим ее и делаем текущей. echo $row[$j]; $current_category = $row[$j]; } } else { echo $row[$j]; } echo "</td>"; } echo "</tr>"; } //...