php How to display multiple products in one line
php can be used to connect to the database to query products and output the display For users, but if you want to display multiple products in one row, you need to use css technology. The specific implementation is as follows:
1. First, the php code
<?php $sql = "select * from user"; $result = $conn->query($sql); if ($result) { if ($result->num_rows>0) { echo '<div class="parent">'; while ($rows = $result->fetch_array()) { print_r($rows); echo '<div class="item">'; echo '<i>'.$rows['id'].'</i>'; echo '<img src="'.$rows['imgurl'].'" alt="How to display multiple products in one line in php" >'; echo '<span>'.$rows['name'].'</span>'; echo '</div>'; }//end while() echo '</div>'; }else{ echo '查询结果为空!'; }//end if() }else{ echo '查询失败!'; }//end if()
Note that there is an output div tag above, and it has class.
2. The following is the implementation of the css code
The following is the simulated database data
Note: For the flex layout involved, friends who want to learn can search for css tutorials on the php Chinese website.
Effect:
For more PHP related knowledge, please visit PHP Chinese website!
The above is the detailed content of How to display multiple products in one line in php. For more information, please follow other related articles on the PHP Chinese website!