使用PHP,MySQL,JS进行比较和数据提取

时间:2015-07-28 10:06:21

标签: php jquery mysql

我有一个数据库,golf_add.php和ajax_price.php文件。

所以我不能这样做:

从表单中选择值>来自|到|转移类型|高尔夫日期选项框字段,我想要这些字段'比较值并从数据库中选择适当的数据(对于高尔夫价格值)到高尔夫价格文本框。

例如:
来自:XXX Otel(id = 15)
至:YYY Place(id = 25)
转机类型:班车(id = 4)
高尔夫日期:2015/08/05
从表单中选择这些值后,我想点击刷新按钮或者在我选择高尔夫日期最后一步之后,根据我的选择,它自动必须从正确的行中获得价格..

您可以在此处预览我的表单:http://i.stack.imgur.com/Fzzr9.jpg

golf_add.php代码:

<!-- OTHER CODES ... -->

<script>
function refreshforprice() {
    jQuery.ajax({
        type: 'GET',
        url: 'ajax_price.php',
        data: 'tid='+jQuery('#op_transfer_type_id').val()+'&p='+jQuery('#operation_pax').val()+'&p2='+jQuery('#operation_pax2').val()+'&v=1',
        cache : false,
        success: function(sonuc){
            sonucx = sonuc.split(';');
            jQuery('#sold_tour_price_auto').val(sonucx[0]+'.00');
            jQuery('#xprice1').html('* '+sonucx[1]+'.00 €');
            jQuery('#xprice2').html('* '+sonucx[2]+'.00 €');
        }
     });
}
</script>

<form method="POST" action="golf_add.php" name="adminForm" id="adminForm">

    <table class="adminlist">
        <thead>
            <tr>
                <th> GOLF DETAILS </th>
            </tr>
        </thead>
    </table>

    <table class="adminlist">
        <tbody>
            <?PHP $i = 0; ?>                
            <tr class="<?php $i++; $m=$i%2; if($m=='1') echo "row0"; else echo "row1";?>">
                <td align="right"><b>From</b></td>
                <td id="fromarea">
                    <select size="1" name="operation_pickup_from" id="operation_pickup_from">

                        <option value="-1" disabled selected> --- Select Pick Up Point --- </option>

                        <?php
                        $strSQL2 = "SELECT * FROM pickup_points_From WHERE region_id='".$regionidx."' soldtours='1' ORDER BY pickup_point_name ASC";
                        $resultSQL2 = mysql_query($strSQL2);
                        $ks = mysql_num_rows($resultSQL2);
                        for ($z=0; $z<$ks; $z++) {
                            $rowSQL2 = mysql_fetch_array($resultSQL2);
                            ?><option value="<?=$rowSQL2['pickup_point_id']?>"><?=$rowSQL2['pickup_point_name']?></option><?
                        }
                        ?>
                    </select>
                </td>
            </tr>

            <tr class="<?php echo "row1";?>">
                <td align="right"><b>To</b></td>
                <td id="fromarea">
                    <select size="1" name="operation_pickup_to" id="operation_pickup_to">
                        <option value="-1" disabled selected> --- Select Drop Point --- </option>
                        <?php
                            $strSQL3 = "SELECT * FROM pickup_points_To WHERE region_id='".$regionidx."' AND soldtours='1' ORDER BY drop_point_name";
                            $resultSQL3 = mysql_query($strSQL3);
                            while($rowSQL3 = mysql_fetch_array($resultSQL3)) {
                        ?>
                            <option value="<?=$rowSQL3['drop_point_id']?>"><?=$rowSQL3['drop_point_name']?></option>
                        <? } ?>

                    </select>
                </td>
            </tr>

            <tr class="<?php $i++; $m=$i%2; if($m=='1') echo "row0"; else echo "row1";?>">
                <td align="right"><b>Transfer Type</b></td>
                <td id="tourtypes">
                    <select size="1" name="op_transfer_type_id" id="op_transfer_type_id">
                        <option value="-1" disabled selected> --- Select Transfer Type --- </option>
                        <?php
                            $strSQL2 = "SELECT * FROM operation_transfer_types WHERE op_transfer_type_id IN (4,10) ORDER BY op_transfer_type_name";
                            $resultSQL2 = mysql_query($strSQL2);
                            while($rowSQL2 = mysql_fetch_array($resultSQL2)) {
                                ?><option value="<?=$rowSQL2['op_transfer_type_id']?>"><?=$rowSQL2['op_transfer_type_name']?></option><?
                            }
                        ?>
                    </select>
                </td>
            </tr>

            <tr class="<?php $i++; $m=$i%2; if($m=='1') echo "row0"; else echo "row1";?>">
                <td width="45%" align="right"><b>Golf Date</b>&raquo;</td>
                <td width="55%"><input type="text" name="operation_date" id="operation_date" value="<?=$_GET['selected_day']?>" size="10" class="datepicker" autocomplete="off"> <input type="text" name="operation_time" id="operation_time" size="5" class="timepicker" autocomplete="off">&laquo;<b>Golf Time</b></td>
            </tr>

            <tr class="<?php $i++; $m=$i%2; if($m=='1') echo "row0"; else echo "row1";?>">
                <td align="right"><b>Adult</b></td>
                <td><input type="text" name="operation_pax" id="operation_pax" size="5" value="1" onkeypress="return OnlyDigits(event);" 
                    onblur="OnlyDigits(event,false)" autocomplete="off"> &nbsp;&nbsp;&nbsp;<span id="xprice1" style="color: green;">* 0.00 €. </span>
                </tr>

            <tr class="<?php $i++; $m=$i%2; if($m=='1') echo "row0"; else echo "row1";?>">
                <td align="right" id="agex1"><b>06-12 Age</b></td>
                <td><input type="text" name="operation_pax2" id="operation_pax2" size="5" value="0" onkeypress="return OnlyDigits(event);" 
                    onblur="OnlyDigits(event,false)" autocomplete="off"> &nbsp;&nbsp;&nbsp;<span id="xprice2" style="color: green;">* 0.00 €. </span>
                </td>
            </tr>

            <tr class="<?php $i++; $m=$i%2; if($m=='1') echo "row0"; else echo "row1";?>">
                <td align="right"><b>Golf Price</b></td>
                <td id="pricediv"><input type="text" name="sold_tour_price_auto" id="sold_tour_price_auto" size="8" class="bestupper" 
                    value="0.00" onkeypress="return OnlyDigits(event,'.');" onblur="OnlyDigits(event,false)"> &nbsp;&nbsp;EUR 
                </td>
            </tr>
        </tbody>
    </table>        
</form>

<!-- OTHER CODES ... -->

ajax_price.php代码:

<?php
$tid = intval(@$_GET['tid']);
$p = intval(@$_GET['p']);
$p2 = intval(@$_GET['p2']);
$v = intval(@$_GET['v']);

$sql = "SELECT * FROM transfer_type WHERE transfer_id='".$tid."'";
$s = mysql_query($sql);
$ks = mysql_num_rows($s);
if ($ks > 0) {
    $k = mysql_fetch_assoc($s);
    $pprice = floatval($k['golf_price']);

    if ($tid == 4) {
        $price_pax = $p + $p2;
        $price = ($price_pax * $pprice) + ($price_pax * 7); 
    }
    else {
        $price = ($pprice * $p) + ($pprice * $p2); 
    }

    if ($v == 1) { echo $price.';'.$pprice.';'.$pprice; }
    else { echo $price; }
    ?><?PHP
}
else {
    if ($v == 1) { ?>0;0;0<?PHP }
    else { ?>0<?PHP }
}
?>

1 个答案:

答案 0 :(得分:0)

我不太确定,但我无法在您的表单中看到您使用函数refreshforprice()的位置,我在<select>框中使用onchange中的函数做了类似的操作

例如<select id="something" name="something" onchange"function();">