Creating a site to query a database of tables

前端 未结 7 910
后悔当初
后悔当初 2021-01-18 07:45

I have a small problem. I am working with some manual testers who are untrained in programming/database design. Our current process means that these manual testers need to i

7条回答
  •  情书的邮戳
    2021-01-18 08:19

    I think you could achieve this with a simple form and some ajax calls using on key up. Here is a simple example in which the list will update each time the user enters a letter in the column name they are searching for.

    Index.html

      
    
      
      
    
    
      
      
    

    next we need a script to carry out our search

    ajax-search.php

        //you must define your database settings
    define("DB_HOST", "FOO");
    define("DB_USERNAME", "BAR");
    define("DB_PASSWORD", "YOUR PASSWORD");
    define("DB_NAME", "DATABASE NAME");
    if(isset($_GET['keyword']))
        {
            $search = new mysqli(DB_HOST, DB_USERNAME, DB_PASSWORD, DB_NAME);
                if ($search->connect_errno)
                {
                    echo "Failed to connect to MySQL: (" . $search->connect_errno . ") " . $search->connect_error;
                    $search->close();
                }
                    $keyword =  trim($_GET['keyword']) ;
                    $query ="SELECT COLUMN_NAME FROM ".DB_NAME.".INFORMATION_SCHEMA.COLUMNS WHERE COLUMN_NAME LIKE '%".$keyword."%'";
                    $values = $search->query($query);
                        if($values->num_rows != 0)
                        {
                            while($row = $values->fetch_assoc())
                            { 
                                echo $row['COLUMN_NAME']."
    "; } } else { echo 'No Results for :"'.$_GET['keyword'].'"'; } }

    As the user types out a column name all of the column name like this will be returned and updated on the fly, without page reload. Hope this helps

提交回复
热议问题