SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Thread: Help me Sellect auto with PHP & MYSQL

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2010
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs down Help me Sellect auto with PHP & MYSQL

    I have 2 files:
    Database name: muangay123
    Database :
    PHP Code:
    -- phpMyAdmin SQL Dump
    -- version 2.7.0-pl2
    -- http://www.phpmyadmin.net
    -- 
    -- 
    Hostlocalhost
    -- Generation TimeFeb 142012 at 10:19 PM
    -- Server version5.0.18
    -- PHP Version5.1.2
    -- 
    -- 
    Database: `muangay123`
    -- 

    -- --------------------------------------------------------

    -- 
    -- 
    Table structure for table `chi_tiet_sp`
    -- 

    CREATE TABLE `chi_tiet_sp` (
      `
    idint(255NOT NULL auto_increment,
      `
    ten_spvarchar(100NOT NULL,
      `
    ma_spvarchar(50NOT NULL,
      `
    hang_sxvarchar(60NOT NULL,
      `
    giavarchar(30NOT NULL,
      `
    datedatetime NOT NULL,
      `
    chitiet_sptext NOT NULL,
      `
    thuvarchar(20NOT NULL,
      `
    id_clvarchar(10NOT NULL,
      
    PRIMARY KEY  (`id`)
    ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=43 ;

    -- 
    -- 
    Dumping data for table `chi_tiet_sp`
    -- 

    INSERT INTO `chi_tiet_spVALUES (6'May khau NV-30''NV-30''Brother''12500000''2012-01-05 05:33:19''Máy điện tử cực hay''''3');
    INSERT INTO `chi_tiet_spVALUES (14'May Danh Giay M02 ''M02''SilRoad''2650000''2012-01-06 22:24:35''Dung gia dinh va van phong''''3');
    INSERT INTO `chi_tiet_spVALUES (21'Máy lọc không khí L318-AZ ''L318-AZ''LifePro''1750000''2012-01-05 23:56:59''Khử mùi rất tốt''''2');
    INSERT INTO `chi_tiet_spVALUES (17'Máy sưởi dầu SD-02''1750000''Nonan''1750000''2012-01-06 00:06:10''Sưởi ấm mùa đông lạnh giá''''');
    INSERT INTO `chi_tiet_spVALUES (18'Máy mài dao KS01''KS01''Nonan''650000''2012-01-05 23:51:51''Mài dao gia đình''''');
    INSERT INTO `chi_tiet_spVALUES (27'Máy khâu Riccar ''Riccar''Riccar''2000000''2012-01-06 02:38:20''Loai moi nhat day''''3');
    INSERT INTO `chi_tiet_spVALUES (29'Bàn là hơi nước ''KG75''Kangaroo''1750000''2012-01-06 02:38:01''Rất tốt cho chị em PN''''');
    INSERT INTO `chi_tiet_spVALUES (28'Máy tính bàn ''computer''ha noi''1000000''2012-01-05 23:58:42''cực hay , chạy êm''''2');
    INSERT INTO `chi_tiet_spVALUES (22'Máy giặt Little Duck ''ko có''Little Duck''1400000''2012-01-05 05:35:24''Máy tốt chạy êm''''');
    INSERT INTO `chi_tiet_spVALUES (23'Máy sưởi dầu SD03 ''SD03''Nonan''1300000''2012-01-05 05:39:50''Sưởi ấm cực tốt''''1');
    INSERT INTO `chi_tiet_spVALUES (26'Máy rửa bát ''Daiwa''Daiwa''2000000''2012-01-05 05:51:05''rửa bát gia đình''''');
    INSERT INTO `chi_tiet_spVALUES (30'Máy đánh giày cực hay ''MDG012''Silroad''5000000''2012-01-06 20:57:02''Chay tốt''''');
    INSERT INTO `chi_tiet_spVALUES (31'Xem máy LS ''LS''Nhật''50000000''2012-01-06 20:57:43''Chạy êm''''');
    INSERT INTO `chi_tiet_spVALUES (32'Máy Bay LS111 ''LS111''USA''1000000000''2012-01-06 23:39:48''Bắn các loại''''');
    INSERT INTO `chi_tiet_spVALUES (33'Máy học tiếng Anh ''TAH''Đức''2000000''2012-01-06 22:24:02''Giúp bé học tốt E''''1');
    INSERT INTO `chi_tiet_spVALUES (34'Máy kích điện IQ110 ''IQ110''MaxQ''2900000''2012-01-07 22:59:31''Kích điện gia đình''''1');
    INSERT INTO `chi_tiet_spVALUES (35'Máy Bay LS222 ''LS222''USA''21000000''2012-01-06 23:39:28''Bay mọi góc độ''''');
    INSERT INTO `chi_tiet_spVALUES (39'Tên lửa F53 ''F53''Liên Xô''12000000''2012-01-07 22:53:06''<p class="Normal">"H&ocirc;m nay l&agrave; ng&agrave;y thứ 14 kể từ khi t&agrave;u Vinalines Queen mất t&iacute;ch. Chiến dịch t&igrave;m kiếm do Việt Nam &aacute;p dụng đối với con t&agrave;u n&agrave;y c&oacute; quy m&ocirc; chỉ đứng sau cuộc t&igrave;m kiếm thuyền vi&ecirc;n mất t&iacute;ch do b&atilde;o Chanchu", &ocirc;ng Vũ n&oacute;i.</p>\r\n<table width="1" border="0" cellspacing="0" cellpadding="3" align="center">\r\n<tbody>\r\n<tr>\r\n<td><img src="http://vnexpress.net/Files/Subject/3b/bd/12/2d/vn1.jpg" alt="Ảnh: J.W." width="480" height="353" /></td>\r\n</tr>\r\n<tr>\r\n<td class="Image">Việc t&igrave;m kiếm thuyền vi&ecirc;n Vinalines Queen kh&ocirc;ng tiếp tục thực hiện bằng c&aacute;c phương tiện chuy&ecirc;n dụng nữa. Ảnh: <em>J.W.</em></td>\r\n</tr>\r\n</tbody>\r\n</table>''''1');
    INSERT INTO `chi_tiet_spVALUES (40'Tên lửa đạn đạo ''TLDD''Nga''12000000''2012-01-07 22:59:02''<p>&nbsp;</p>\r\n<p>Iran ho&agrave;i nghi vụ Mỹ giải cứu ngư d&acirc;n</p>\r\n<p>&nbsp;</p>\r\n<h2 class="Lead">Tehran cho rằng "cử chỉ nh&acirc;n đạo" của Mỹ khi giải cứu c&aacute;c ngư d&acirc;n Iran kh&ocirc;ng xoay chuyển được căng thẳng song phương, trong khi giới truyền th&ocirc;ng coi h&agrave;nh động n&agrave;y như được d&agrave;n dựng sẵn.<br />&gt; <a class="Lead" href="http://vnexpress.net/gl/the-gioi/2012/01/hai-quan-my-cuu-ngu-dan-iran/">Hải qu&acirc;n Mỹ cứu ngư d&acirc;n Iran</a></h2>\r\n<p>&nbsp;</p>\r\n<table width="1" border="0" cellspacing="0" cellpadding="3" align="center">\r\n<tbody>\r\n<tr>\r\n<td><img src="http://vnexpress.net/Files/Subject/3b/bd/12/20/iran3.jpg" alt="" width="463" height="512" border="1" /></td>\r\n</tr>\r\n<tr>\r\n<td class="Image">Ngư d&acirc;n Iran &ocirc;m một hải qu&acirc;n Mỹ đ&atilde; cứu sống &ocirc;ng khỏi tay cướp biển. Ảnh: <em>AP</em></td>\r\n</tr>\r\n</tbody>\r\n</table>''''1');

    -- --------------------------------------------------------

    -- 
    -- 
    Table structure for table `chung_loai`
    -- 

    CREATE TABLE `chung_loai` (
      `
    id_clint(10NOT NULL auto_increment,
      `
    ten_chung_loaivarchar(20NOT NULL,
      
    PRIMARY KEY  (`id_cl`)
    ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=;

    -- 
    -- 
    Dumping data for table `chung_loai`
    -- 

    INSERT INTO `chung_loaiVALUES (1'DIEN GIA DUNG');
    INSERT INTO `chung_loaiVALUES (2'NOI THAT');
    INSERT INTO `chung_loaiVALUES (3'CAC SAN PHAM KHAC');

    -- --------------------------------------------------------

    -- 
    -- 
    Table structure for table `members`
    -- 

    CREATE TABLE `members` (
      `
    idint(4NOT NULL auto_increment,
      `
    usernamevarchar(65NOT NULL default '',
      `
    passwordvarchar(65NOT NULL default '',
      
    PRIMARY KEY  (`id`)
    ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=;

    -- 
    -- 
    Dumping data for table `members`
    -- 

    INSERT INTO `membersVALUES (1'john''1234');
    INSERT INTO `membersVALUES (2'vlbknl2''12345'); 
    I writed code like below but it don't run:
    PHP Code:
    <head>
    <script>
    function autoSubmit_formUpLoad()
    {
        document.linh.submit();
    }
    </script>
    </head>

    <?php
    require_once('../includes/ketnoi.php');
    mysql_select_db("$db_name")or die("khong the ket noi co so du lieu");
    ?>
    <form  action='sellect3.php' method='post' name='linh' id='linh'>
    <select name="loai" id="loai" onchange='autoSubmit_formUpLoad();'>
    <?php
    $sql
    ="SELECT * FROM chung_loai ORDER BY id_cl DESC";
    $result=mysql_query($sql);
    $count=mysql_num_rows($result);

    if(
    $count<>0)
    {
          while(
    $row_cl=mysql_fetch_assoc($result))
          {
            
    $id_cl=$row_cl['id_cl'];
            
    $ten_chung_loai=$row_cl['ten_chung_loai'];
                if(isset(
    $_POST['loai'])&&$_POST["loai"]==$id_cl)
                {
                echo
    "<option value='$id_cl'  selected='selected'>$ten_chung_loai</option>";    
                }
                else
                {
                echo
    "<option>$ten_chung_loai</option>";
                }
                    
          echo
    "<br>";
          }
        
    }
    ?>
    </select>
    <label>
    <select name="loai1" id="loai1" onchange='autoSubmit_formUpLoad();' >
    <?php
    $sql1
    ="SELECT * FROM chi_tiet_sp ORDER BY id_cl DESC";
    $result1=mysql_query($sql1);
    $count1=mysql_num_rows($result1);

    if(
    $count1<>0)
    {
          while(
    $row_cl1=mysql_fetch_assoc($result1))
          {
            
    $id_cl1=$row_cl1['id_cl'];
            
    $ten_sp=$row_cl1['ten_sp'];
             if(
    $id_cl1==$id_cl)
            
                echo
    "<option value='$id_cl1' selected='selected'>$ten_sp</option>";    
                
                
            }                
          echo
    "<br>";
          
    }
    ?>
    </select>
    </form>
    Now:
    I want to write as Sellect -> Option like Picture below:




    And result like when I chose : “CAC SAN PHAM KHAC”


    Help Me!
    Thanks All!

  2. #2
    From Italy with love bronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    8,645
    Mentioned
    77 Post(s)
    Tagged
    4 Thread(s)
    If you want to change the values of the second drop down box after the user has chosen a value in the first drop down box, you'll have to use AJAX.
    Googling for 'php ajax dropdown' will give you lots of tutorials and examples. You can also search this forum and the Javascript forum, because the question has been asked lots of times.

  3. #3
    SitePoint Enthusiast
    Join Date
    Oct 2010
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I want to write code php $ mysql
    In database use two table: table1,table2
    I need use ajax dropdown to sellect 2 table, Help me!

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •