09/10/2018, 23:58

Mình muốn chia thành 2 cột hiện product làm sao? có sẵn code 1 cột

code sau đây hiển thị 1 sản phẩm rồi xuống hàng

mình muốn chia cách hiện sản phẩm của mình là 2 sản phẩm rồi xuống hàng hiện tiếp 2 sản phẩm,cứ thế...

bạn nào có thể sửa code dùm mình với,thx nhiều !!!

function fShowNewProduct()
{
$sSQL="select * from product where iStatus>0 and iNew>0 order by iProductID desc";
$Result=mysql_query($sSQL) or die(mysql_error());
if(mysql_num_rows($Result))
{
echo "
<table width=100% bgcolor=#cccccc cellpadding=0 cellspacing=1>
<tr bgcolor=#F26464>
<td width=100% align=center class=text height=22><font color=#ffffff><b>Sản phẩm mới</b></font></td>
</tr>
<tr>
<td width=100% bgcolor=#F7FFFF>
<table width=100% class=text>
<tr>
<td height=5></td>
</tr>
";
$i=0;
while(($aRow=mysql_fetch_array($Result))and($i<10) )
{
$i++;
$sPicture="";
if(strlen($aRow['sThumbnail'])>0)
$sPicture="<a href='product_details.php?iCatID=$aRow[iCatID]&iPID=$aRow[iProductID]'><img src='$aRow[sThumbnail]' border=0></a><br>";
echo "<tr><td align=center>
$sPicture
<a href='product_details.php?iCatID=$aRow[iCatID]&iPID=$aRow[iProductID]'>$aRow[sProductName]</a>
</td></tr>
<tr><td height=5></td></tr>
";
}
echo "</table>

</td>
</tr>

</table>
<table>
<tr><td height=5></td></tr>
</table>
";
}
}
Về Đâu viết 02:00 ngày 10/10/2018
$a = 0, sao mỗi lần lập $a++, nếu $a chia hết cho 2 echo </tr>.
còn code của bạn bạn tự sửa
redami viết 02:15 ngày 10/10/2018
thx bạn nhiều,mình hiểu ý bạn nhưng mình không biết ngôn ngữ php
bạn có thể edit dùm mình chổ đó luôn được không?
Adam viết 02:09 ngày 10/10/2018
Làm vòng lặp theo số cột.
Vd: $cols = 2;
Thực hiện vòng lặp,nếu khách yêu cầu 3 cột thì $cols =3 là xong.
Bạn thử test cái này xem sao nhé:




function fShowNewProduct()
{
$cols = 2;
$sSQL="select * from product where iStatus>0 and iNew>0 order by iProductID desc";
$Result=mysql_query($sSQL) or die(mysql_error());
if(mysql_num_rows($Result))
{
echo "
<table width=100% bgcolor=#cccccc cellpadding=0 cellspacing=1>
<tr bgcolor=#F26464>
<td width=100% align=center class=text height=22><font color=#ffffff><b>Sản phẩm mới</b></font></td>
</tr>
<tr>
<td width=100% bgcolor=#F7FFFF>
<table width=100% class=text>
<tr>
<td height=5></td>
</tr>
";
$i=0;
while(($aRow=mysql_fetch_array($Result))and($i<10) )
{
$i++;
$sPicture="";
if(strlen($aRow['sThumbnail'])>0)
$sPicture="<a href='product_details.php?iCatID=$aRow[iCatID]&iPID=$aRow[iProductID]'><img src='$aRow[sThumbnail]' border=0></a><br>";
echo "<tr>
for($j =0;$j<$cols;$j++){
<td align=center>
$sPicture
<a href='product_details.php?iCatID=$aRow[iCatID]&iPID=$aRow[iProductID]'>$aRow[sProductName]</a>
</td>
}
</tr>
<tr><td height=5></td></tr>
";
}
echo "</table>
</td>

</tr>

</table>
<table>
<tr><td height=5></td></tr>
</table>
";
}
}
redami viết 02:08 ngày 10/10/2018
thx Adam nhiều,nhưng vẫn không được,nó báo 1 cột và show vài code thừa trong đó

mong sự giúp đỡ của mọi người edit code dùm mình
redami viết 02:12 ngày 10/10/2018
ai help mình với T_T
Bài liên quan
0