How do I write Query code while I use Jquery in PHP -


i new php , mysql. project bio "dictionary". want find word , it's definition , couple more columns has related information regarding word m looking for. want dictionary data in nice table.

i have wrote query retrieve data related word mysql database. data 4 different tables.

i have wrote index.php , data.php code posted below. problems>>>>>>

1) when running inded.php file m getting error

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

2) having difficult in writing code data.php file, please give me suggestion. m retrieving data multiple tables confusing.

please me out, m struggling , appreciate help.

thank you

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 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 database     $dbhandle = mysql_connect($hostname, $username, $password)       or die("unable connect mysql");       //select database work     $selected = mysql_select_db("umls",$dbhandle)        or die("could not select examples");         // $_post        $name = mysql_real_escape_string($_post['word']);      //name  null     if ($word==null)         echo "please enter word" ;     else {     // query      $result = mysql_query("select distinct * nstring normalized_string= '$word' group  string, defination, source");     $result_num_rows = mysql_num_rows($result);     //fetch tha data 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 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 connection     mysql_close($dbhandle);     ?>      </table> 

you getting first error since javascript code should inside <script> tag , not outside it..

try this..

<script type="text/javascript">  //notice </script> tag shifted end of javascript code           function get() {               $.post ('data.php', { word: form.name.value },                       function (output) {                      $('#defination') .html(output).show() ;                  });          }  </script>     

and other few errors in data.php

 $name = mysql_real_escape_string($_post['word']);   if ($name==null)  //<----here $word = $name      echo "please enter word </td></tr>"; //close tr , td else { 

and can end , start php tag again

  <?php   $username = "root";   $password = "";   $hostname = "127.0.0.1";    .....     .....     $variable5=$row["semantic_type"];     $variable6=$row["source"];      ?>      <tr>        <td><?php echo $variable3; ?></td>       <td><?php echo $variable4; ?></td>       <td><?php echo $variable5; ?></td>       <td><?php echo $variable6; ?></td>      </tr> 

note: mysql deprecated use mysqli pdo ... learn oop create class instead of procedure based , php framework... codeigniter , zend , yii , on


Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -