ช่วยหน่อยเรื่องตารางที่โชว์ออกมาเกินแล้วไม่มีข้อมูลแก้ไงหรอค่ะ
คือเราเพิ่มข้อมูลลงไปแล้ว4อัน แล้วเรียกออกมาจากฐานข้อมูลแต่นี่นี้เราเพิ่มไปแค่ 4 อันใช่ไหมค่ะแต่มันดันออกมาเปน 6 อันโดยที่ โดยที่อีก2 อันหลังมันไม่มีข้อมูลอะไรอ่ะค่ะทำไงดีค่ะแก้ตรงไหนค่ะ
รุปภาพประกอบ
Code ตัวโปรแกรมนะช่วยแก้หน่อยปวดหัวเราแก้มา 5 วันแล้วอ่ะ T T
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>.: welcome to shrimp :.</title>
<link rel="shortcut icon" href="../img/favicon.ico">
<link href="../CSS/bg.css" rel="stylesheet" type="text/css" />
<script src="../Scripts/AC_RunActiveContent.js" type="text/javascript"></script>
<script type="text/javascript">
<!--
function MM_preloadImages() { //v3.0
var d=document; if(d.images){ if(!d.MM_p) d.MM_p=new Array();
var i,j=d.MM_p.length,a=MM_preloadImages.arguments; for(i=0; i<a.length; i++)
if (a[i].indexOf("#")!=0){ d.MM_p[j]=new Image; d.MM_p[j++].src=a[i];}}
}
function MM_swapImgRestore() { //v3.0
var i,x,a=document.MM_sr; for(i=0;a&&i<a.length&&(x=a[i])&&x.oSrc;i++) x.src=x.oSrc;
}
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}
function MM_swapImage() { //v3.0
var i,j=0,x,a=MM_swapImage.arguments; document.MM_sr=new Array; for(i=0;i<(a.length-2);i+=3)
if ((x=MM_findObj(a[i]))!=null){document.MM_sr[j++]=x; if(!x.oSrc) x.oSrc=x.src; x.src=a[i+2];}
}
//-->
</script>
<style type="text/css">
<!--
.style1 { font-size: 24px;
font-weight: bold;
}
-->
</style>
</head>
<body onload="MM_preloadImages('../icon/menu/11.jpg','../icon/menu/33.jpg','../icon/menu/22.jpg','../icon/menu/44.jpg','../icon/menu/55.jpg','../icon/menu/66.jpg','../icon/menu/88.jpg','../icon/logout1.jpg','../icon/menu/Product1.jpg')">
<table width="862" height="1000" border="3" align="center">
<tr>
<td height="146" colspan="2"><script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','900','height','175','src','../flash/head','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','../flash/head' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="900" height="175">
<param name="movie" value="../flash/head.swf" />
<param name="quality" value="high" />
<embed src="../flash/head.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="900" height="175"></embed>
</object></noscript></td>
</tr>
<tr>
<td height="47" colspan="2"><table width="866" height="43" border="0">
<tr bgcolor="#00CFFF">
<td width="105" height="39"><a href="index.php"><img src="../icon/menu/index.jpg" name="Image2" width="108" height="40" border="0" id="Image2" onmouseover="MM_swapImage('Image2','','../icon/menu/index1.jpg',1)" onmouseout="MM_swapImgRestore()" /></a></td>
<td width="105" height="39"><a href="information.php"><img src="../icon/menu/information.jpg" width="108" height="40" border="0" id="Image3" onmouseover="MM_swapImage('Image3','','../icon/menu/information1.jpg',1)" onmouseout="MM_swapImgRestore()" /></a></td>
<td width="105" height="39"><a href="Product.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('product','','../icon/menu/Product1.jpg',1)"><img src="../icon/menu/Product1.jpg" name="product" width="108" height="40" border="0" id="product" /></a><a href="Product_r.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('product','','../icon/menu/Product1.jpg',1)"></a></td>
<td width="105" height="39"><a href="Party.php"><img src="../icon/menu/Party.jpg" width="108" height="40" border="0" id="Image5" onmouseover="MM_swapImage('Image5','','../icon/menu/Party1.jpg',1)" onmouseout="MM_swapImgRestore()" /></a></td>
<td width="105" height="39"><a href="Order.php"><img src="../icon/menu/Order.jpg" width="108" height="40" border="0" id="Image6" onmouseover="MM_swapImage('Image6','','../icon/menu/Order1.jpg',1)" onmouseout="MM_swapImgRestore()" /></a></td>
<td width="105" height="39"><a href="Delivery.php"><img src="../icon/menu/Delivery.jpg" width="108" height="40" border="0" id="Image7" onmouseover="MM_swapImage('Image7','','../icon/menu/Delivery1.jpg',1)" onmouseout="MM_swapImgRestore()" /></a></td>
<td width="105" height="39"><a href="am.php"><img src="../icon/menu/am.jpg" width="108" height="40" border="0" id="Image8" onmouseover="MM_swapImage('Image8','','../icon/menu/am1.jpg',0)" onmouseout="MM_swapImgRestore()" /></a></td>
<td width="105" height="39"><a href="map.php"><img src="../icon/menu/map.jpg" width="108" height="40" border="0" id="Image9" onmouseover="MM_swapImage('Image9','','../icon/menu/map1.jpg',1)" onmouseout="MM_swapImgRestore()" /></a></td>
</tr>
</table></td>
</tr>
<tr>
<td width="180" height="701" valign="top"><div align="center">
<table width="180" height="208" border="0" cellpadding="0" cellspacing="0" background="../picture/login3.png" >
<tr>
<td valign="bottom"><?
@session_start();
if($_SESSION[status] != "member")
{
?>
<table width="180" border="0" cellpadding="0" cellspacing="0">
<tr>
<td><form id="form2" name="form1" method="post" action="check_login.php">
<table width="180" height="200" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="500" height="198" background="../img/n1.png"><center>
<img src="../icon/loginH.jpg" width="176" height="46" /><br />
<table width="169" border="0" cellspacing="2" cellpadding="2">
<tr>
<td width="75"><img src="../icon/login.jpg" width="72" height="21" /></td>
<td width="237"><input name="mem_user" type="text" id="mem_user" size="12" /></td>
</tr>
<tr>
<td><img src="../icon/login1.jpg" width="72" height="21" /></td>
<td><input name="mem_pass" type="password" size="12" /></td>
</tr>
</table>
</center>
</p>
<div align="center">
<input name="Submit" type="submit" id="button" value="เข้าสู่ระบบ" />
<input type="reset" name="button2" id="button2" value="ลบข้อมูล" />
</div>
<table width="180" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td><label>
<a href="Register.php">
<center>
<img src="../icon/loginOK.jpg" width="111" height="38" border="0" />
</center>
</a>
<div align="center"></div>
<div align="center"></div></td>
</tr>
</table></td>
</tr>
</table>
</form></td>
</tr>
</table>
<p>
<?
}
else
{
?>
</p>
<table width="176" height="152" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td width="205" height="152" background="../img/n1.png"><p>
<center>
<img src="../icon/loginH.jpg" width="176" height="46" />
</center>
</p>
<table width="175" border="0" cellpadding="0" cellspacing="0">
<tr>
<td width="80"><img src="../icon/login.jpg" width="72" height="21" /></td>
<td width="95"><span class="style1"><? echo $_SESSION[mem_user]; ?></span></td>
</tr>
<tr>
<td height="26" colspan="2"><a href="check_edit_member.php">แก้ไขข้อมูล</a></td>
</tr>
<tr>
<td height="26" colspan="2"><div align="center"><a href="logout.php" onmouseout="MM_swapImgRestore()" onmouseover="MM_swapImage('Image17','','../icon/logout1.jpg',1)"><img src="../icon/logout.jpg" name="Image17" width="110" height="40" border="0" id="Image17" /></a></div></td>
</tr>
</table></td>
</tr>
</table>
<p>
<?
}
?>
</p></td>
</tr>
</table>
</div>
<div align="center"></div>
<p></p>
<p></p>
<p> </p>
<p> </p>
<p> </p></td>
<td width="714" valign="top" background="../img/bg_SAI.png">
<form action="" method="get">
<img src="../img/br.gif" width="706" height="29" />
</form>
<form id="pic" name="pic" method="post" action="">
<table width="709" height="33" border="0" cellpadding="2" cellspacing="2">
<tr>
<td width="137" height="29"><div align="center"><a href="Product_bl.php"><img src="../img/bl.gif" width="105" height="30" border="0" /></a></div></td>
<td width="136"><div align="center"><a href="Product_r.php"><img src="../img/r.gif" width="105" height="30" border="0" /></a></div></td>
<td width="138"><div align="center"><a href="Product_o.php"><img src="../img/o.gif" width="105" height="30" border="0" /></a></div></td>
<td width="121"><div align="center"><a href="Product_wh.php"><img src="../img/wh.gif" width="105" height="30" border="0" /></a></div></td>
<td width="145"><div align="center"><a href="Product_bk.php"><img src="../img/bk.gif" width="105" height="30" border="0" /></a></div></td>
</tr>
</table>
</form>
<form action="" method="get">
<div align="center"><img src="../img/r_head.gif" width="250" height="94" /> </div>
</form>
<table width="603" align="center" cellpadding="0" cellspacing="0">
<!-- open tag table -->
<?
include "..\Connections\conn.php";
$show_pd="select * from redclaw.product where p_type='red' ";
$query=mysql_query($show_pd);
$num=mysql_num_rows($query);
$record=$num; // num from mysql_num_rows function
$start_rows=0; // start value rows
$start_col=0; // start value colums
$end_col=3; // number is colums show
$end_rows=ceil($record/$end_col); // caculate for number rows with Ceil function
//echo $end_rows;
while($start_rows<$end_rows){ // loop while for show rows begins
?>
<tr>
<?
while($start_col<$end_col){
$show=mysql_fetch_array($query)// loop while for show colums begins
?>
<td align="center" valign="bottom"><form id="form1" name="form1" method="post" action="cart.php">
<br />
<table width="227" height="425" border="0" cellpadding="0" cellspacing="0" bordercolor="0">
<tr>
<td colspan="2"><img src="../img/head_table.png" width="228" height="29" /></td>
<td> </td>
</tr>
<tr>
<td colspan="2" rowspan="6" bgcolor="#FFFFFF"><div align="center"><a href='../img/product/<? echo $show[p_pic]?>' target="_blank"><img src="../img/product/<?php echo $show['p_pic']; ?>" width="170" height="200" border="0" /></div></td>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td width="10"> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td width="55" align="right" bgcolor="#FFFFFF"><div align="right"><strong><span class="style22">ชื่อสินค้า: </span></strong></div></td>
<td width="169" bgcolor="#FFFFFF"><div align="left"><strong><span class="style22"><img src="../img/br.gif" width="26" height="22" /><? echo $show[p_id]; ?></span></strong></div></td>
<td> </td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF"><div align="right"><strong>สี:</strong></div></td>
<td bgcolor="#FFFFFF"><div align="left"><strong><span class="style22"><img src="../img/br.gif" width="26" height="22" /></span><? echo $show[p_color]; ?></strong></div></td>
<td> </td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF"><div align="right"><strong><span class="style22">ราคา: </span></strong></div></td>
<td bgcolor="#FFFFFF"><div align="left"><strong><span class="style22"><img src="../img/br.gif" width="26" height="22" /><? echo $show[p_price]; ?></span></strong></div></td>
<td> </td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF"><div align="right"><strong>ขนาด: </strong></div></td>
<td bgcolor="#FFFFFF"><div align="left"><strong><span class="style22"><img src="../img/br.gif" width="26" height="22" /><? echo $show[p_size]; ?></span></strong></div></td>
<td> </td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF"><div align="right"><strong>สี: </strong></div></td>
<td bgcolor="#FFFFFF"><div align="left"><strong><span class="style22"><img src="../img/br.gif" width="26" height="22" /><? echo $show[p_type]; ?></span></strong></div></td>
<td> </td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF"><div align="right"><strong>สถานะ: </strong></div></td>
<td bgcolor="#FFFFFF"><div align="left"><strong><span class="style22"><img src="../img/br.gif" width="26" height="22" /><? echo $show[p_status]; ?></span></strong></div></td>
<td> </td>
</tr>
<? if(!$_SESSION[id_mem])
{
?>
<?
}
?>
<tr>
<td colspan="2" bgcolor="#FFFFFF"><?
if ($_SESSION[status] == "member")
{
?></td>
<td> </td>
</tr>
<tr>
<td colspan="2" rowspan="2" bgcolor="#FFFFFF">
<div align="right">
<input name="p_id" type="hidden" id="p_id" value="<? echo $show[p_id]; ?>" />
<input name="qty" type="text" id="qty" value="1" size="3" maxlength="3" />
<input type="submit" name="Submit2" value="ซื้อสินค้า" />
</div></td>
<td> </td>
</tr>
<tr>
<td height="25"> </td>
</tr>
<tr>
<td height="25" colspan="2"><img src="../img/head_table.png" width="228" height="26" /></td>
<td> </td>
</tr>
<?
}
?>
</table>
<br />
<br />
</form></td>
<?
$start_col++; // add value \$start_col up 1 value
}
?>
</tr>
<!-- colse tag rows -->
<?
$start_col=0; // reset value \$start_col for show colums in next time
$start_rows++; // add value \$start_rows up 1 value
}
?>
</table></td>
</tr>
<tr>
<td height="50" colspan="2"><img src="../img/foot.jpg" width="899" height="90" /><br/> </td>
</tr>
<tr></tr>
<tr></tr>
</table>
</body>
</html>Tag : PHP
Date :
2011-09-24 13:28:23
By :
Taadccc
View :
752
Reply :
6
ลองใช้เป็ฯแบบนี้ดูครับ
$show_pd="select * from redclaw.product where p_type='red' LIMIT 4";
Date :
2011-09-24 13:44:27
By :
adaaugusta
มันก็ยังไม่ได้อยู่ดีอ่ะพอเวลาเพิ่มเข้าไปก็ไม่โชว์เลยอ่ะแล้วก็เปนช่องว่างแบบเดิมด้วยอ่ะ T T
Date :
2011-09-24 14:23:43
By :
Taadccc
ผมว่า While แบบ Table มันยากไปนะครับ งงมาก
ใช้ <div> เอาดีกว่าไหม
<?php while ( เงื่อนไข) { ?>
<div>
// data
</div>
<?php } //end while ?>
Date :
2011-09-24 15:12:20
By :
adaaugusta
ไม่เข้าใจอ่ะ
Date :
2011-09-24 15:33:38
By :
Taadccc
ก็ While เฉพาะข้อมูลน่ะครับ คุณต้องการให้ Table ออกมา 4 ชุดถูกไหม
คุณก็
Code (PHP)
<?php while (เงื่อนไข) { ?>
<table width="227" height="425" border="0" cellpadding="0" cellspacing="0" bordercolor="0">
<tr>
<td colspan="2"><img src="../img/head_table.png" width="228" height="29" /></td>
<td> </td>
</tr>
<tr>
<td colspan="2" rowspan="6" bgcolor="#FFFFFF"><div align="center"><a href='../img/product/<? echo $show[p_pic]?>' target="_blank"><img src="../img/product/<?php echo $show['p_pic']; ?>" width="170" height="200" border="0" /></div></td>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td width="10"> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td> </td>
</tr>
<tr>
<td width="55" align="right" bgcolor="#FFFFFF"><div align="right"><strong><span class="style22">ชื่อสินค้า: </span></strong></div></td>
<td width="169" bgcolor="#FFFFFF"><div align="left"><strong><span class="style22"><img src="../img/br.gif" width="26" height="22" /><? echo $show[p_id]; ?></span></strong></div></td>
<td> </td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF"><div align="right"><strong>สี:</strong></div></td>
<td bgcolor="#FFFFFF"><div align="left"><strong><span class="style22"><img src="../img/br.gif" width="26" height="22" /></span><? echo $show[p_color]; ?></strong></div></td>
<td> </td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF"><div align="right"><strong><span class="style22">ราคา: </span></strong></div></td>
<td bgcolor="#FFFFFF"><div align="left"><strong><span class="style22"><img src="../img/br.gif" width="26" height="22" /><? echo $show[p_price]; ?></span></strong></div></td>
<td> </td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF"><div align="right"><strong>ขนาด: </strong></div></td>
<td bgcolor="#FFFFFF"><div align="left"><strong><span class="style22"><img src="../img/br.gif" width="26" height="22" /><? echo $show[p_size]; ?></span></strong></div></td>
<td> </td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF"><div align="right"><strong>สี: </strong></div></td>
<td bgcolor="#FFFFFF"><div align="left"><strong><span class="style22"><img src="../img/br.gif" width="26" height="22" /><? echo $show[p_type]; ?></span></strong></div></td>
<td> </td>
</tr>
<tr>
<td align="right" bgcolor="#FFFFFF"><div align="right"><strong>สถานะ: </strong></div></td>
<td bgcolor="#FFFFFF"><div align="left"><strong><span class="style22"><img src="../img/br.gif" width="26" height="22" /><? echo $show[p_status]; ?></span></strong></div></td>
<td> </td>
</tr>
<? if(!$_SESSION[id_mem])
{
?>
<?
}
?>
<tr>
<td colspan="2" bgcolor="#FFFFFF"><?
if ($_SESSION[status] == "member")
{
?></td>
<td> </td>
</tr>
<tr>
<td colspan="2" rowspan="2" bgcolor="#FFFFFF">
<div align="right">
<input name="p_id" type="hidden" id="p_id" value="<? echo $show[p_id]; ?>" />
<input name="qty" type="text" id="qty" value="1" size="3" maxlength="3" />
<input type="submit" name="Submit2" value="ซื้อสินค้า" />
</div></td>
<td> </td>
</tr>
<tr>
<td height="25"> </td>
</tr>
<tr>
<td height="25" colspan="2"><img src="../img/head_table.png" width="228" height="26" /></td>
<td> </td>
</tr>
<?
}
?>
</table>
<?php } ?>
ประมาณนี้น่ะครับ
เหมือน Table จะผิดหลายจุดดูมันซ้อนๆ ดูงงๆยังไงไม่รู้
Date :
2011-09-24 15:43:46
By :
adaaugusta
ขอบคุณจ้าไว้จะลองทำดูใหม่นะ
Date :
2011-09-24 17:30:28
By :
Taadccc
Load balance : Server 00