开发者

retrieve mysql data

I have this code for listing mysql records and putting it into a table according to the address inputted. My problem is, how to do just the same but this time, making use of textboxes to project the contents of the record corresponding to the same data inputted. I'm just a beginner with no talent. Maybe you could give me some idea on how to do it.

       mysql_select_db("hospital", $con);

        $result = mysql_query("SELECT * FROM t2 WHERE ADDRESS='{$_POST["address"]}'");
         echo "<table border='1'>
     <tr>
     <th>HospNum</th>
     <th>RoomNum</th>
     <th>LastName</th>
     <th>FirstName</th>
    <th>MidName</th>
    <th>Address</th>
      <th>TelNum</th>
      &开发者_JAVA技巧lt;th>Nurse</th>
      </tr>";

      while($row = mysql_fetch_array($result))
   {
  echo "<tr>";
     echo "<td>" . $row['HOSPNUM'] . "</td>";
  echo "<td>" . $row['ROOMNUM'] . "</td>";
   echo "<td>" . $row['LASTNAME'] . "</td>";
   echo "<td>" . $row['FIRSTNAME'] . "</td>";
    echo "<td>" . $row['MIDNAME'] . "</td>";
      echo "<td>" . $row['ADDRESS'] . "</td>";
       echo "<td>" . $row['TELNUM'] . "</td>";
        echo "<td>" . $row['NURSE'] . "</td>";

  echo "</tr>";
     }
    echo "</table>";

 mysql_close($con);
   ?>


As a suggestion, I do not think displaying the values inside of a textbox is the best idea. With that being said, you achieve your results by performing the following

while($row = mysql_fetch_array($result)) {
 echo "<input type=\"text\" value='" . $row['HOSPNUM'] . "'><br />";
 echo "<input type=\"text\" value='" . $row['ROOMNUM'] . "'><br />";
 ....
}

You would need to escape the " inside of the text boxes by using PHP's escape special character \


You need to search from your present tables and use AJAX to notify the user.

I would suggest you look into a framework in PHP which would help you a LOT since you are just starting your projects. List of frameworks can be found at http://www.phpframeworks.com/


As far as i could understand your question, you want to retrieve data from mysql based on the input of the text boxes. This is how you can go about it:

<form action="yourpage.php">
  <input type="text" name="text1">
  <input type="text" name="text2">
  <input type="text" name="text3">
</form>

Now you can retrieve data from mysql using where clause.

select * from table where text1 = 'text1' and  text2 = 'text2' and  text3 = 'text3'

Note: You need to change the names in form and query as per your requirement.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜