ช่วยบอกวิธึการเอาข้อมูลออกมาแสดงทีครับ

คือว่าผมต้องการให้มันแสดงข้อมูลในส่วนของ หมวดหมู่ย่อยครับ ส่วนหมวดหมู่หลักได้แล้วครับ ดึงข้อมูลมาจากสองตาราง คือ main_cat และ sub_cat ในส่วนของ main_cat มี id_main, main_name, main_pic ส่วน ตาราง sub_cat มี id_sub, id_main, sub_name ครับ ผมทำแล้วมันไม่ได้ครับ มันขึ้นเหมือนรูปที่แนบมาครับ ติดส่วนนี้ส่วนเดียวครับ มีโค้ดมาให้ดูด้วยครับ

<?php require_once('../Connections/thaiindexz.php'); ?><?php require_once('../Connections/thaiindexz.php');
$cols = 2;
$c = $cols;
?>
<?php
mysql_select_db($database_thaiindexz, $thaiindexz);
$query_show = "SELECT * FROM main ORDER BY id_main ASC";
$show = mysql_query($query_show, $thaiindexz) or die(mysql_error());
$row_show = mysql_fetch_assoc($show);
$totalRows_show = mysql_num_rows($show);

mysql_select_db($database_thaiindexz, $thaiindexz);
$query_showsub = "SELECT * FROM sub ORDER BY id_main ASC";
$showsub = mysql_query($query_showsub, $thaiindexz) or die(mysql_error());
$row_showsub = mysql_fetch_assoc($showsub);
$totalRows_showsub = mysql_num_rows($showsub);
?>
<!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=utf-8" />
<title>#Show All Main Categoly and Sub Categoly#</title>
<link href="../StyleSheet/Style_sheet.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table border="0" align="center" cellpadding="2" cellspacing="2">
    <tr>
 <?php do { $c --;?>
      <td width="70" height="80" valign="bottom"><img src="../add_cat/thumbcat/<?php echo $row_show['main_pic']; ?>" width="60" height="60" class="boxpic" /></td>
   <td width="250" height="80" valign="top">
<table border="0" cellpadding="0" cellspacing="0">
        <tr>
          <td height="25" class="font6"><a href="main_cat.php?id_main=<?php echo $row_show['id_main']; ?>"><?php echo $row_show['main_name']; ?></a></td>
        </tr>
        <tr>
          <td height="50" valign="top" class="font6"><?php echo $row_showsub['sub_name']; ?></td>
        </tr>
      </table></td>
   <? if($c == 0) { $c = $cols;?>
 </tr>
    <?php }} while ($row_show = mysql_fetch_assoc($show));?>
</table>
</body>
</html>
<?php
mysql_free_result($show);

mysql_free_result($showsub);
?>
 

ช่วยทีนะครับ ทำไม่ได้สักที ขอขอบคุณล่วงหน้าครับ
11 ก.พ. 2552 1 2,701

ลองใช้คำสั่ง SQL ในรูป INNER JOIN ดูครับ หรือไม่ก็ทำการ query ทีละกลุ่ม

วิธีการจริงๆก็ขึ้นอยู่กับการออกแบบ db ครับ ออกแบบ db ดีก็ query ง่ายครับ
#1
ความคิดเห็น
ไฟล์อัปโหลด ชนิด jpg, jpeg ขนาดไฟล์ไม่เกิน 1024
^