Php - 如何交替进行多次搜索多次搜索?

时间:2017-03-15 02:07:05

标签: javascript php jquery mysql

我有一个关于多输出交替只有一个搜索引擎的问题....我在下面有这个场景..

情景:

  1. 首先搜索数据。输出将进入textarea1(id='content')
  2. 第二次搜索数据。输出将进入textarea2(id='content1')
  3. 第三次搜索数据。输出将进入textarea3('content2')
  4. 注意:我只使用了一个搜索引擎..

    请帮帮我:( 谢谢你,祝你有美好的一天! 以下是我的代码

    表:用户

     CREATE TABLE users
     (id INT PRIMARY KEY AUTO_INCREMENT,
     name VARCHAR(50),
     age INT)
    

    的index.php

    <html>
    
    <head>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript">
        function get() {
            $.post('data.php', {
                    name: form.search.value
                },
                function(output) {
                    $('#content').html(output).show();
                    $('#content1').html(output).show();
                    $('#content2').html(output).show();
                });
        }
        </script>
    </head>
    
    <body>
        <p>
            <form name="form">
                <input type="text" name="search">
                <input type="button" value="Get" onClick="get();">
            </form>
            <div>
                <textarea id='content' cols='15' rows='5'></textarea>
                <textarea id='content1' cols='15' rows='5'></textarea>
                <textarea id='content2' cols='15' rows='5'></textarea>
            </div>
        </p>
    </body>
    
    </html>
    

    data.php

    <?php
    require 'connection.php';
    
    $name = mysql_real_escape_string($_POST['name']);
    
    if($name==NULL)
    echo "Please enter a name";
    
    else{
    $age = mysql_query("SELECT age FROM users WHERE memberName='$name'");
    $age_num_rows = @mysql_num_rows($age);
    
    if($age_num_rows==0)
    echo "Name does not exists";
    
    else
    {
    $age = mysql_result($age, 0);   
    echo "$name's age is $age";
    }
    }
    

0 个答案:

没有答案
相关问题