Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ทำเมนู แบบ แปรผันกันจากฐานข้อมูลแล้วไม่เปลี่ยน ตรงรายการที่ 3 เพราะอะไร รบกวนดู code ให้หน่อย



 

ทำเมนู แบบ แปรผันกันจากฐานข้อมูลแล้วไม่เปลี่ยน ตรงรายการที่ 3 เพราะอะไร รบกวนดู code ให้หน่อย

 



Topic : 117316



โพสกระทู้ ( 85 )
บทความ ( 0 )



สถานะออฟไลน์




Code (PHP)
<div class="from">
              <form id="form1" name="form1" method="post" action="add_product_total.php" onSubmit="JavaScript:return fncSubmit();" ENCTYPE="multipart/form-data">
                <table width="829" border="0" cellspacing="2" cellpadding="2">
                  <tr>
                    <td colspan="3" background="img/bg2.jpg"><span class="style2">เพิ่มข้อมูลชนิดสินค้าและรายละเอียด</span></td>
                    </tr>
                  <tr>
                    <td>รายการสำคัญ</td>
                    <td><select name="catalog" class="inputs1" id="catalog"onchange="location.href='frm_pro2.php?cat_id='+this.value;" style="width:300px">
                      <option value="">- Choose -</option>
                      <?
include ("connect.php");
$cat_id=$_GET['cat_id'];
$sql="select * from tb_product1 order by cat_id ASC";
$dbquery=mysql_db_query($dbname,$sql);
while($result=mysql_fetch_array($dbquery)){
if($cat_id == $result[cat_id]){ //เพื่อให้ แสดง $cat_id ที่ส่งค่ามาให้
?>
                      <option value="<?=$result[cat_id];?>" selected="selected">
                        <?=$result[cat_name_th];?>
                        </option>
                      <?
}else{?>
                      <option value="<?=$result[cat_id];?>">
                        <?=$result[cat_name_th];?>
                        </option>
                      <?
} }
?>
                    </select></td>
                    <td>&nbsp;</td>
                  </tr>
                  <tr>
                    <td>รายละเอียด (ย่อย1)</td>
                    <td><select name="subcatalog" id="subcatalog" class="inputs1"  style="width:300px">
                      <option value="">- Choose -</option>
                      <?
$cat_id=$_GET['cat_id'];
if($cat_id != ""){ //กรณีที่ มี่คา caat_id ส่งมาให้ทำงาน
include ("connect.php");
$sql_sub="select * from tb_subproduct where cat_id = '$cat_id' ";
$dbquery_sub = mysql_db_query($dbname, $sql_sub);
while($result_sub=mysql_fetch_array($dbquery_sub)){
?>
                      <option value="<?=$result_sub[sub_id];?>">
                        <?=$result_sub[sub_name_th];?>
                        </option>
                      <?
}}
?>
                    </select></td>
                    <td>&nbsp;</td>
                  </tr>
                  <tr>
                    <td>รายละเอียด (ย่อย2)</td>
                    <td><select name="subcatalog1" id="subcatalog1" class="inputs1"  style="width:300px">
                      <option value="">- Choose -</option>
                      <?
$sub_id=$_GET['sub_id'];
echo "$cat_id";
if($sub_id != ""){ //กรณีที่ มี่คา caat_id ส่งมาให้ทำงาน
include ("connect.php");
$sql_sub="select * from tb_subproduct_1 where sub_id = '$sub_id' ";
$dbquery_sub = mysql_db_query($dbname, $sql_sub);
while($result_sub=mysql_fetch_array($dbquery_sub)){
?>
                      <option value="<?=$result_sub[sub_id];?>">
                      <?=$result_sub[sub_name_th];?>
                      </option>
                      <?
}}
?>

list111
ddd



Tag : PHP









ประวัติการแก้ไข
2015-06-22 21:21:45
Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2015-06-22 21:14:01 By : chayaphol View : 681 Reply : 2
 

 

No. 1



โพสกระทู้ ( 1,521 )
บทความ ( 2 )

สมาชิกที่ใส่เสื้อไทยครีเอท Hall of Fame 2012

สถานะออฟไลน์
Facebook

เหมือนจะมี <?=$result_sub[sub_name_th];?> ของ Select อันที่ 3 ต้องเป็น <?=$result_sub[sub1_name_th];?> ป่าว
แถมแบบ ajax ไม่ได้เทสนะคับ มั่วๆเอา
product.php
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <table>
        <tr>
            <td>
                <select name="catalog" id="catalog">
                    <?php
                    include ("connect.php");
                    $cat_id=$_GET['cat_id'];
                    $sql="select * from tb_product1 order by cat_id ASC";
                    $dbquery=mysql_db_query($dbname,$sql);
                    while($result=mysql_fetch_array($dbquery)){
                            echo '<option value="'.$result[cat_id].'">'.$result[cat_name_th].'</option>';
                    }
                    ?>
                </select>
            </td>
        </tr>
        <tr>
            <td>
                <select name="subcatalog" id="subcatalog"></select>
            </td>
        </tr>
        <tr>
            <td>
                <select name="subcatalog1" id="subcatalog1"></select>
            </td>
        </tr>
    </table>
    <script type="text/javascript" src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
    <script type="text/javascript">
        $(function(){
            $('#catalog,#subcatalog').change(function(){
                var type = $(this).attr('id');
                var find_id = $(this).val();
                $.ajax({
                    url: 'catalogJson.php',
                    type: 'post',
                    dataType: 'json',
                    data: {
                        target: type,
                        toFind: find_id
                    }
                })
                .done(function(response){
                    if(type == 'catalog'){
                        $('#subcatalog').empty();
                        $.each(response, function(key, val){
                            $('#subcatalog').append('<option value="'+ val.sub_id +'">'+ val.sub_name_th +'<option>');
                        });
                    }else{
                        $('#subcatalog1').empty();
                        $.each(response, function(key, val){
                            $('#subcatalog1').append('<option value="'+ val.sub1_id +'">'+ val.sub1_name_th +'<option>');
                        });
                    }
                });
            });

        })
    </script>
</body>
</html>


catalogJson.php
<?php 
    header('Content-Type:application/json');
    include ("connect.php");
    $type = $_POST['target'];
    $find_id = $_POST['toFind'];
    $response = array();
    if($type == 'catalog'){
        $sql_sub="select * from tb_subproduct where cat_id = '$find_id' ";
        $dbquery=mysql_db_query($dbname,$sql);
        while($result=mysql_fetch_array($dbquery)){
            array_push($response,array('sub_id'=>$result['sub_id'],'sub_name_th'=>$result['sub_name_th']));
        }
    }else{
        $sql_sub="select * from tb_subproduct_1 where sub_id = '$find_id' ";
        $dbquery=mysql_db_query($dbname,$sql);
        while($result=mysql_fetch_array($dbquery)){
            array_push($response,array('sub1_id'=>$result['sub1_id'],'sub1_name_th'=>$result['sub1_name_th']));
        }
    }
    
    echo json_encode($response, TRUE);
?>









ประวัติการแก้ไข
2015-06-23 00:34:05
2015-06-23 00:35:08
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-06-23 00:28:25 By : Krungsri
 


 

No. 2



โพสกระทู้ ( 85 )
บทความ ( 0 )



สถานะออฟไลน์


ตอบความคิดเห็นที่ : 1 เขียนโดย : Krungsri เมื่อวันที่ 2015-06-23 00:28:25
รายละเอียดของการตอบ ::
ขอบคุณครับ เดี๋ยวลองดู

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2015-06-23 15:46:54 By : chayaphol
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ทำเมนู แบบ แปรผันกันจากฐานข้อมูลแล้วไม่เปลี่ยน ตรงรายการที่ 3 เพราะอะไร รบกวนดู code ให้หน่อย
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่