상품 2개씩 출력 문의 드림니다.
본문
<?
$result=mysql_query('SELECT it_img1 ,it_id, it_name, it_price FROM g5_shop_item WHERE it_type4="1" ' );
while($row = mysql_fetch_array($result)){
echo "<div id='test'><a href='/shop/item.php?it_id=".$row[1]."'><img src=/data/item/".$row[0]." width=130
border=1></a><br>".$row[it_name]." <br>".$row[it_price]."</div>"; }
?>
지금 현재 이렇게 해서 인기상품을 한줄에 하나 씩은 출력 됨니다.
이것을 한줄에 2개의 상품을 출력 하고 싶은대.. 어떻게 해야 하나요?
몇일 동안 이렇게 저렇게 해 보는대.. 지식이 부족하군요.. 도움을 청합니다.
답변 1
echo 문을 조금 바꾸면 되지 않을까요.
<?
$result=mysql_query('SELECT it_img1 ,it_id, it_name, it_price FROM g5_shop_item WHERE it_type4="1" ' );
$n=1;
while($row = mysql_fetch_array($result)){
if($n%2==1) echo "<div class='test'>";
echo "<a href='/shop/item.php?it_id=".$row[1]."'><img src=/data/item/".$row[0]." width=130
border=1></a><br>".$row[it_name]." <br>".$row[it_price];
if($n%2==0) echo "</div>";
$n++;
}
?>
답변을 작성하시기 전에 로그인 해주세요.