将值发送到数据库然后将结果显示为警报

时间:2012-01-03 08:31:41

标签: php jquery mysql join alert

我不知道这样说。我有一些输入表单连接到数据库中的两个表。首先,我有两个文本域:

<input type="text" id="model"> i type alfa
<input type="text" id="serial_number"> i type A0020

表A:

Model      serial        start_serial        end_serial
alfa       301           A0001                A0100
alfa       101           A0101                A0200

表B:

Model     serial       remark
alfa      301          delay

从上面的信息我有两个变量$ model和$ serial_number。 我想做的是:

1. send variable to query, check the model and serial
2. in query i type SELECT.....WHERE A.Model = '$Model' //SEARCH all data which have value alfa
3. in this step i want to check $serial_number //if A0020 is in range start serial A0001 and end serial A0100
4. if match i will get result serial = 301
5. join table A to table B, LEFT JOIN ....ON A.Model=B.Model AND A.Serial=B.serial
6. so if i type alfa and A0020 in textfield i will get REMARK VALUE = delay

如何在我的查询中将最后结果作为延迟?所以我可以把它显示为警报。

2 个答案:

答案 0 :(得分:0)

看一下这个链接。 http://api.jquery.com/serialize/ 您还可以执行以下操作:

$.ajax({
    type:"post",
    url:"process.php",
    data:"&check="+data2+"&action=acceso",  //this works for my jquery projects
    cache:false,
    async:false,
    success: function(res){
                           alert(res);                              
                             }
    });

答案 1 :(得分:0)

我真的无法理解你的问题,所以我根据你留下的评论做出回答,总结了这个问题

  

“如何将结果显示为警报值延迟的警报”

如果您的意思是要显示警报值(文本)为“延迟”的警告:

alert('delay');

如果您想在延迟后显示警报,则ajax响应指定延迟:

success: function(res){
         setTimeout(function() { alert(res); }, (int)res);                              
}

修改

阅读更新后的问题。

您的服务器端脚本将与数据库进行所有通信。让我们说它是一个PHP脚本

//make sure you sanitize input
$model = $_POST['model'];
$serial = $_POST['serial_number']

//this is a very poor query. I'm bad at SQL. Utilize Joins to make it better
// this is just to give you an idea
$res = mysql_query("SELECT `remark` FROM `yourtableB` WHERE `serial` IN 
(SELECT `serial` FROM `yourtableA` WHERE `Model` = '$Model' AND ('$serial' > `start_serial`) AND ('$serial' < `end_serial))");

if (mysql_num_rows($res) > 0)
{
    $resp = mysql_fetch_array($res);
    echo $resp['remark'];
}
else
{
    echo "none";
}

Jquery方面,修改success函数

success: function(res){
        if (res != "none")
        {
            alert(res);
        }
        else
        {
            alert('No data found');
        }
}