简体   繁体   English

如何从MySQL的表的列中获取特定项目并使用它来制作另一个 <select>改变其知名度

[英]How to get a specific item from a column of a table in MySQL and use it to make another <select> change its visibility

my problem is i want to get specific item from column of table here with photo [1]: https://i.ibb.co/4KcwScM/Captfffffure.png "the first item of the title" i want to get this specific value and hide and visible some option 我的问题是我想从表的列中获取带有照片[1]的特定项: https : //i.ibb.co/4KcwScM/Captfffffure.png “标题的第一项”我想获取此特定值隐藏并可见一些选项

here is the code to explain more , this select i want when people select this specific title it will show them another specific section which in this photo [2]: https://i.ibb.co/hyRcfPS/Carrrrrrrrrrrrrrrrrpture.png ""the section will show" , and when they show other options it will hide the previous section and visible a new section to all the other options [3]: https://i.ibb.co/K05PpkL/Capturffffffffffae.png "this one explain every thing". 这是用于解释更多内容的代码,当人们选择此特定标题时,我希望此选择将向他们显示此照片中的另一个特定部分[2]: https : //i.ibb.co/hyRcfPS/Carrrrrrrrrrrrrrrrrrrpture.png该部分将显示“,并且当他们显示其他选项时,它将隐藏上一部分,并在所有其他选项中显示一个新部分[3]: https : //i.ibb.co/K05PpkL/Capturffffffffffae.png ”这一个解释每件事”。

<label style="margin-left:20px; padding: 0 20px;
    margin-bottom: 39px;">كيف نساعدك؟  </label><select name="topic"  id="type" Required="Required">
        <option>اختر الخدمة</option>
<?php
// Make the connection:
$connection = mysqli_connect ('localhost', '#', '#', '#');
// If no connection could be made, trigger an error:
if ($connection->connect_error)
{
    die("Database selection failed: " . $connection->connect_error);
}
# Set encoding to match PHP script encoding.
mysqli_set_charset($connection, 'utf8');
$query = "SELECT * FROM newservices";
$select_newservice = mysql_query($query);
while ($row = @mysql_fetch_assoc($select_newservice)) {
echo "<option value=\"".$row['id']."\">".$row['title']."</option>\n  ";
}
?>
</select><br>

this code after the first one 第一个代码之后

<div id="price"> 
<label style="    margin-left: 136px;
    margin-bottom: 30px;     padding: 0 20px;">سعر الخدمة</label><select disabled style="
    -webkit-appearance: none;
"    Required="Required">
        <option>0$</option>
</select>
</div>
<div id="tax"> 
       <label style="margin-left:40px;     padding: 0 20px;"> سعر الخدمة شامل الضريبة</label><span class='prisee'>0$</span><br>
       </div>

here is the ajax of it 这是它的ajax

<script>
 $("select[name='topic']").on("change",function(e) {
     e.preventDefault();
    //getting selected  value
    var topic=$(this).val();
    console.log(topic);
        $.ajax({
            type: 'POST',
            url: 'contactusprise.php',
             data: {'topic': topic },//<-passing value to php
            success: function(php) {
               $("#price").html(php);//<--response will show in div with id=price
            }               
        });

    });
</script>
<script>
 $("select[name='topic']").on("change",function(e) {
     e.preventDefault();
    //getting selected  value
    var topic=$(this).val();
    console.log(topic);
        $.ajax({
            type: 'POST',
            url: 'contactustax.php',
             data: {'topic': topic },//<-passing value to php
            success: function(php) {
               $("#tax").html(php);//<--response will show in div with id=price
            }               
        });

    });
</script>

this is code it and the other are the same but with different row 这是代码,另一个是相同的,但行不同

 <?php
    // Make the connection:
    $connection = mysqli_connect ('localhost', '#', '#', '#');
    // If no connection could be made, trigger an error:
    if ($connection->connect_error)
    {
        die("Database selection failed: " . $connection->connect_error);
    }
    $topic=$_POST['topic'];//<-getting value which is passed from ajax
    # Set encoding to match PHP script encoding.
    mysqli_set_charset($connection, 'utf8');
 //here column name will be name of coulmn which you need to compare 
    $query = "SELECT * FROM newservices where id= ".$topic;
    $select_newservice = mysqli_query($connection, $query);
    echo '<label style=" margin-left: 136px;
    margin-bottom: 30px;padding: 0 20px;">السعر بضريبة البيبال</label><select  style="
    -webkit-appearance: none;
" disabled name="topic1"   Required="Required">';
    while ($row = mysqli_fetch_assoc($select_newservice)) {
    echo "<option value=\"".$row['id']."\" >".$row['tax']."</option>\n  ";
}

    echo "</select>";
    ?>

code of this section of the specific item which from specific column i am already found solution of select the item and show it ,the problem it get the section for all items of select and i want to hide when the select isn't this item the code for this section of the specific item 从特定列中我已经找到了选择项目的解决方案并显示它的特定项目的这一部分的代码,问题是它获得了select的所有项目的部分,而我想在select不是该项目时隐藏该问题特定项目此部分的代码

<div id="containeer" >
<div id="chango" style="
    display: inline-flex;
    width: 286px;
">
<label style="margin-left:20px; padding: 0 20px;
    margin-bottom: 39px;">عدد الصفحات </label> <input type="text" class="form-controle" name="topic1" placeholder="اختر العدد" style="
    width: 118px;
    text-align-last: center;
">
    </div>
<div id="wprice" style="display: inline-flex;
    width: 286px;" >
<label style="margin-left:20px; padding: 0 20px;
    margin-bottom: 39px;">عدد الكلمات</label><select style="-webkit-appearance: none;    width:118px;
    text-align-last: center;" Required="Required">

</select>
</div>
<div id="pricee" style="
    display: inline-flex;
    width: 286px;
"> 
<label style="    margin-left: 136px;
    margin-bottom: 30px;     padding: 0 20px;">السعر الاجمالي</label><select disabled style="
    -webkit-appearance: none;margin-right: -65px;
"    Required="Required">
        <option>0$</option>
</select>
</div>
<div id="pricees" style="
    display: inline-flex;
    width: 286px;
"> 
<label style="    margin-left: 61px;
    margin-bottom: 30px;     padding: 0 13px;">السعر الاجمالي شامل الضريبة</label><select disabled style="
    -webkit-appearance: none;margin-right: -60px;
"    Required="Required">
        <option>0$</option>
</select>
</div>
</div>

here is the ajax codes 这是ajax代码

<script>
 $("input[name='topic1']").on("change",function(e) {
     e.preventDefault();
    //getting selected  value
    var topic1=$(this).val();
    console.log(topic1);
        $.ajax({
            type: 'POST',
            url: 'wpcontactusnum.php',
             data: {'topic1': topic1 },//<-passing value to php
            success: function(php) {
               $("#wprice").html(php);//<--response will show in div with id=price
            }               
        });

    });
</script>
<script>
 $("input[name='topic1']").on("change",function(e) {
     e.preventDefault();
    //getting selected  value
    var topic1=$(this).val();
    console.log(topic1);
        $.ajax({
            type: 'POST',
            url: 'price_pages.php',
             data: {'topic1': topic1 },//<-passing value to php
            success: function(php) {
               $("#pricee").html(php);//<--response will show in div with id=price
            }               
        });

    });
</script>
<script>
 $("input[name='topic1']").on("change",function(e) {
     e.preventDefault();
    //getting selected  value
    var topic1=$(this).val();
    console.log(topic1);
        $.ajax({
            type: 'POST',
            url: 'taxprice_pages.php',
             data: {'topic1': topic1 },//<-passing value to php
            success: function(php) {
               $("#pricees").html(php);//<--response will show in div with id=price
            }               
        });

    });
</script>

there is the wpcontactusnum.php code the other are same but different rows 有wpcontactusnum.php代码,其他相同但行不同

<?php
    // Make the connection:
    $connection = mysqli_connect ('localhost', '#', '#', '#');
    // If no connection could be made, trigger an error:
    if ($connection->connect_error)
    {
        die("Database selection failed: " . $connection->connect_error);
    }
    $topic1=$_POST['topic1'];//<-getting value which is passed from ajax
    # Set encoding to match PHP script encoding.
    mysqli_set_charset($connection, 'utf8');
 //here column name will be name of coulmn which you need to compare 
    $query = "SELECT * FROM details where pages= ".$topic1;
    $select_detail = mysqli_query($connection, $query);
    echo '<label style=" margin-left: 31px; 
    margin-bottom: 39px;padding: 0 20px;">عدد الكلمات</label><select  style="
    -webkit-appearance: none;width: 118px;
    text-align-last: center;
" disabled name="topic1"   Required="Required">';
    while ($row = mysqli_fetch_assoc($select_detail)) {
        $detail_words = $row['words'];
    echo "<option value=\"".$row['pages']."\"  >".$row['words']."</option>\n  ";
}

    echo "</select>";
    ?>

To check if the selected option is first or second you can do like below : 要检查所选选项是第一还是第二,您可以执行以下操作:

Ajax code : Ajax代码:

 $("select[name='topic']").on("change",function(e) {
     e.preventDefault();

  //checking if first option is selected
    if($(this)[0].selectedIndex == 0)
    {
        //hide topic1
        $("select[name='topic1']").hide();
         //show price and tax
         $("#price").show();
         $("#tax").show();
    }
   else if($(this)[0].selectedIndex == 1) {
      //hide price and tax
       $("#price").hide();
         $("#tax").hide();
      //show topic1
        $("select[name='topic1']").show();

   }
  });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何制作从 mysql 中的另一个表列获取数据的派生属性 - how to make derived attribute that get data from another table column in mysql 如何按特定列从mysql表中获取属性? - How can I get the attributes from a mysql table by specific column? Codeigniter查询:当我使用sum Select函数从另一个表中获取数据时,如何从表中的列中获取所有记录 - codeigniter query: how to take all the record from a column in a table when i use sum Select function to get data from another table MySQL从不在另一个表中的表中选择特定条目 - MySQL select specific entry from a table which is not in another table PHP使用API​​通过ID从表中选择特定值 - PHP Use an API to select a specific value from a table by its ID MySQL-通过参考表从另一个表中选择列 - MySQL - Select column from another table via a reference table 从mysql表中选择3行,然后获取每一行的特定列 - select 3 rows from mysql table, then get each row's specific column 如何从与另一个表具有一对多关系的表中选择特定列? - How to select specific column from a table that has one to many relationship with another table? 如何根据另一个表列从一个表中选择一列? - how to select a column from one table according to another table column? mysql从表中全选,但只更改一个列名 - mysql select all from table but change column name of only one
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM