dongpeng7744 2017-09-25 15:04 采纳率: 100%
浏览 69
已采纳

在PHP中发布选项文本而不是值

I want to post the data like USA and Florida instead of numbers (1 and 1). I tried to change .value to text but the code was not working.

This for filter city and state based on country but I have to update database with country and state name, currently I am getting values only, is there anyway to fix this?

DB structure

INSERT INTO `case_category` (`id`, `category`) VALUES
(1, 'USA'),
(2, 'China'):

INSERT INTO `case_sub_category` (`id`, `sub_category`, `category_id`) VALUES
(1, 'Florida', 1),
(2, 'Guangdong', 2),
(3, 'Sichuan', 2);

loadData.php

$loadType=$_POST['loadType'];
$loadId=$_POST['loadId'];

if($loadType=="subCat"){
    $sql="select id,sub_category from case_sub_category where category_id='".$loadId."' order by sub_category asc";
}else{
    $sql="select id,sub_sub_category from case_sub_sub_category where sub_category_id='".$loadId."' order by sub_sub_category asc";
}
$res=mysql_query($sql);
$check=mysql_num_rows($res);
if($check > 0){
    $HTML="";
    while($row=mysql_fetch_array($res)){
        $HTML.="<option value='".$row['id']."'>".$row['1']."</option>";
    }
    echo $HTML;
}
?> 

Selector

<table>
    <tr>
        <td>
            <select name="request_type_c"  onchange="selectsubSubCat(this.options[this.selectedIndex].value)">
                <option value="-1">Select Category</option>
                <?php
                while($rowCategory=mysql_fetch_array($resCategory)){
                    ?>
                    <option value="<?php echo $rowCategory['id']?>"><?php echo $rowCategory['category']?></option>
                    <?php
                }
                ?>
            </select>
        </td>
    </tr>
    <tr>
        <td>
            <select name="request_type_c_sub"  id="subCat_dropdown" onchange="selectsubCat(this.options[this.selectedIndex].value)">
                <option value="-1">Select Sub Category</option>
            </select>
            <span id="subCat_loader"></span>
        </td>
    </tr>

    <tr>
        <td>
            <select name="request_type_c_sub_sub" id="subSubCat_dropdown">
                <option value="-1">Select Sub Sub Category</option>
            </select>
            <span id="subSubCat_loader"></span>
        </td>
    </tr>
</table>

AJAX

 <script type="text/javascript">
    function selectsubSubCat(Category_id){
        if(Category_id!="-1"){
            loadData('subCat',Category_id);
            $("#subSubCat_dropdown").html("<option value='-1'>Select Category</option>");   
        }else{
            $("#subCat_dropdown").html("<option value='-1'>Select Sub Category</option>");
            $("#subSubCat_dropdown").html("<option value='-1'>Select Sub Sub Category</option>");       
        }
    }

    function selectsubCat(subCat_id){
        if(subCat_id!="-1"){
            loadData('subSubCat',subCat_id);
        }else{
            $("#subSubCat_dropdown").html("<option value='-1'>Select Sub Sub Category</option>");       
        }
    }

    function loadData(loadType,loadId){
        var dataString = 'loadType='+ loadType +'&loadId='+ loadId;
        $("#"+loadType+"_loader").show();
        $("#"+loadType+"_loader").fadeIn(400).html('Please wait... <img src="image/loading.gif" />');
        $.ajax({
            type: "POST",
            url: "loadData.php",
            data: dataString,
            cache: false,
            success: function(result){
                $("#"+loadType+"_loader").hide();
                $("#"+loadType+"_dropdown").html("<option value='-1'>Select "+loadType+"</option>");  
                $("#"+loadType+"_dropdown").append(result);  
            }
        });
    }
    </script>
  • 写回答

1条回答 默认 最新

  • dpo60833 2017-09-25 15:15
    关注

    on DB, you must change the type of fields to varchar, so you can set the values as string (usa or other country) instead of numbers. set the field "category" as foreing key in sub category table...

    set AI in each table, so you can make queries about countries and cities name...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 phython如何实现以下功能?查找同一用户名的消费金额合并—
  • ¥15 孟德尔随机化怎样画共定位分析图
  • ¥18 模拟电路问题解答有偿速度
  • ¥15 CST仿真别人的模型结果仿真结果S参数完全不对
  • ¥15 误删注册表文件致win10无法开启
  • ¥15 请问在阿里云服务器中怎么利用数据库制作网站
  • ¥60 ESP32怎么烧录自启动程序
  • ¥50 html2canvas超出滚动条不显示
  • ¥15 java业务性能问题求解(sql,业务设计相关)
  • ¥15 52810 尾椎c三个a 写蓝牙地址