user225269
user225269

Reputation: 10893

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>
      <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);
   ?>

Upvotes: 0

Views: 324

Answers (3)

Anthony Forloney
Anthony Forloney

Reputation: 91836

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 \

Upvotes: 1

Sarfraz
Sarfraz

Reputation: 382919

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.

Upvotes: 0

Sairam
Sairam

Reputation: 2898

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/

Upvotes: 0

Related Questions