1

私はPHPとmysqlが初めてです。私のプロジェクトはバイオ「辞書」のようなものです。WORD を見つけたいのですが、その定義を取得し、探している WORD に関する関連情報を含む列をいくつか追加します。素敵なテーブルで辞書データを取得したい。

mysql データベースから自分の単語に関連するデータを取得するためのクエリを作成しました。4 つの異なるテーブルからデータを取得します。

以下に掲載されている Index.php および data.php コードを作成しました。問題点>>>>>>

1) inded.php ファイルを実行しているときにエラーが発生する

function get() { $.post ('data.php', { word: form.name.value }, function (output) { $('#defination') .html(output).show() ; }); } "

2) data.php ファイルのコードを書くのが難しいので、アドバイスをお願いします。複数のテーブルからデータを取得しているので、非常に混乱しています。

私を助けてください、私は本当に苦労しています。あなたの助けに感謝します.

ありがとうございました

index.php

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
    "http://www.w3.org/TR/html4/strict.dtd"

<html lang="en">

<head>
    <title></title>

    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript"></script>   
             function get() {
                  $.post ('data.php', { word: form.name.value },
                          function (output) {

                        $('#defination') .html(output).show() ;

                    });
             }
</head>

<body>

<p>
 <form name ="form">
    <input type="search" name="name" size = "30" placeholder="Please enter the Word">
    <input type="button" value="Get" onClick="get();">

 </form>

 <div id="defination"> </div>
</p> 


</body>
</html>

data.php

    <table border="2" cellpadding="5" cellspacing="1" bordercolor="#000000">
    <tr>
    <!--<td width="120"><b>Normalized Word</b></td>
    <td width="120"><b>Normalized String</b></td>-->
    <td width="120"><b>Word</b></td>
    <td width="120"><b>Defination</b></td>
    <td width="120"><b>Type of Sementic</b></td>
    <td width="120"><b>Source</b></td>

    </tr>
    <tr>
    <td>

    <?php
    $username = "root";
    $password = "";
    $hostname = "127.0.0.1"; 

    //connection to the database
    $dbhandle = mysql_connect($hostname, $username, $password) 
     or die("Unable to connect to MySQL");


    //select a database to work with
    $selected = mysql_select_db("umls",$dbhandle) 
      or die("Could not select examples");


      // $_Post

      $name = mysql_real_escape_string($_POST['word']);

    //Name  is NULL
    if ($word==NULL)
        echo "Please enter a Word" ;
    else {
    // Do Query

    $result = mysql_query("SELECT DISTINCT * FROM nString WHERE Normalized_String= '$word' GROUP by  string, defination, Source");
    $result_num_rows = mysql_num_rows($result);
    //fetch tha data from the database 



        while ($row = @mysql_fetch_array($result))
        {
        $variable1=$row["Normalized_Word"];
        $variable2=$row["Normalized_String"];
        $variable3=$row["String"];
            $variable4=$row["Defination"];
        $variable5=$row["Semantic_type"];
        $variable6=$row["source"];

        //table layout for results

        print ("<tr>");
        //print ("<td>$variable1</td>");
        //print ("<td>$variable2</td>");
        print ("<td>$variable3</td>");
            print ("<td>$variable4</td>");
        print ("<td>$variable5</td>");
        print ("<td>$variable6</td>");

        print ("</tr>");
        }
        }   


       // while ($row = mysql_fetch_array($result)) {
     //   echo $row{'CUI'}.$row{'SUI'}.$row{'AUI'}."<br>";

    //close the connection
    mysql_close($dbhandle);
    ?>

    </table>
4

1 に答える 1