Search Facility - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Search Facility

munky344munky344 Posts: 12Member
Hi there,

I need some help please. I'm a newbie so please be patient!.

I have created the following database:

CREATE TABLE patientdemo (id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY, firstname VARCHAR(30), lastname VARCHAR(30), identitynumber VARCHAR(30)); INSERT INTO patientdemo (firstname, lastname, identitynumber) VALUES ( "Alexa", "McDonald", "1234567890987"), ( "Devie", "Slater", "987654321124" )

I then created an HTML form which has two section. It has a section where users can enter information they want to search for and then a table where I would like information to display in once the search has been preformed.



Search for patient:


First Name:


Last Name:


Identity Number:



















I then wrote a search.php form that handles the code to display the search result.

<?php
// Connect to DB
mysql_connect("localhost","root");
mysql_select_db("patient");

$firstname = mysql_real_escape_string($_POST['firstname']);
$lastname = mysql_real_escape_string ($_POST['lastname']);
$identitynumber = mysql_real_escape_string ($_POST['identitynumber']);

// Perform the fulltext search
$query = "SELECT id, firstname, lastname, identitynumber
FROM patientdemo";

$result = mysql_query($query);

// If results were found, output them
if (mysql_num_rows($result) > 0) {
printf //Display in the following HTML Table
("












");
}
else {
printf("No results found");
}
?>

So anyway , the problem is that I want to be able to search for information using the input boxes on the HTML form , and then the info must display in the table (also on the HTML form). How would I go about this.

Once again I'm a newbie so patients please.

Thanking you in advance.

Patient Report
First Name Last Name Identity Number

Patient Report
First Name Last Name Identity Number

Comments

  • munky344munky344 Posts: 12Member
    Hi there

    I'm much closer with this too but not quite there. Any advice?

    Cheers





    <?php

    // Connect to database
    $conn = mysql_connect('localhost','root') or trigger_error("SQL", E_USER_ERROR);
    $db = mysql_select_db('patient',$conn) or trigger_error("SQL", E_USER_ERROR);

    if(isset($_POST['submit'])){

    $firstname = mysql_real_escape_string($_POST['firstname']);
    $lastname = mysql_real_escape_string ($_POST['lastname']);
    $identitynumber = mysql_real_escape_string ($_POST['identitynumber']);

    if(isset($firstname)){
    $where .= "firstname = ";
    $where .= $firstname;
    }
    if(isset($lastname)){
    if(isset($firstname)){
    $where .= " AND ";
    }
    $where .= "lastname = ";
    $where .= $lastname;
    }
    if(isset($identitynumber)){
    if(isset($firstname) OR isset($lastname)){
    $where .= " AND ";
    }
    $where .= "identitynumber = ";
    $where .= $identitynumber;
    }

    $sql = mysql_query("SELECT id, firstname, lastname, identitynumber FROM patientdemo WHERE $where");

    if(mysql_num_rows($sql)>0){
    WHILE($row = mysql_fetch_array($sql)){
    $display .= "";
    $display .= $row['firstname'];
    $display .= "";
    $display .= $row['lastname'];
    $display .= "";
    $display .= $row['identitynumber'];
    $display .= "";
    }
    }else{
    $display = "No Results Found!";
    }

    }
    ?>
    : Hi there,
    :
    : I need some help please. I'm a newbie so please be patient!.
    :
    : I have created the following database:
    :
    : CREATE TABLE patientdemo (id INT(4) NOT NULL AUTO_INCREMENT PRIMARY
    : KEY, firstname VARCHAR(30), lastname VARCHAR(30), identitynumber
    : VARCHAR(30)); INSERT INTO patientdemo (firstname, lastname,
    : identitynumber) VALUES ( "Alexa", "McDonald", "1234567890987"), (
    : "Devie", "Slater", "987654321124" )
    :
    : I then created an HTML form which has two section. It has a section
    : where users can enter information they want to search for and then a
    : table where I would like information to display in once the search
    : has been preformed.
    :
    :
    :
    : Search for patient:

    :


    : First Name:
    :

    : Last Name:
    :

    : Identity Number:
    :

    :


    :
    :
    :
    :
    :


    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    : I then wrote a search.php form that handles the code to display the
    : search result.
    :
    : <?php
    : // Connect to DB
    : mysql_connect("localhost","root");
    : mysql_select_db("patient");
    :
    : $firstname = mysql_real_escape_string($_POST['firstname']);
    : $lastname = mysql_real_escape_string ($_POST['lastname']);
    : $identitynumber = mysql_real_escape_string
    : ($_POST['identitynumber']);
    :
    : // Perform the fulltext search
    : $query = "SELECT id, firstname, lastname, identitynumber
    : FROM patientdemo";
    :
    : $result = mysql_query($query);
    :
    : // If results were found, output them
    : if (mysql_num_rows($result) > 0) {
    : printf //Display in the following HTML Table
    : ("
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    :
    : ");
    : }
    : else {
    : printf("No results found");
    : }
    : ?>
    :
    : So anyway , the problem is that I want to be able to search for
    : information using the input boxes on the HTML form , and then the
    : info must display in the table (also on the HTML form). How would I
    : go about this.
    :
    : Once again I'm a newbie so patients please.
    :
    : Thanking you in advance.
    :


    :
    Patient Report
    First NameLast NameIdentity Number

    :
    Patient Report
    First NameLast NameIdentity Number
  • tradmtradm Posts: 49Member
    : Hi there
    :
    : I'm much closer with this too but not quite there. Any advice?
    :
    : Cheers
    :
    :
    :
    :
    :
    : <?php
    :
    : // Connect to database
    : $conn = mysql_connect('localhost','root') or trigger_error("SQL",
    : E_USER_ERROR);
    : $db = mysql_select_db('patient',$conn) or trigger_error("SQL",
    : E_USER_ERROR);
    :
    : if(isset($_POST['submit'])){
    :
    : $firstname = mysql_real_escape_string($_POST['firstname']);
    : $lastname = mysql_real_escape_string ($_POST['lastname']);
    : $identitynumber = mysql_real_escape_string
    : ($_POST['identitynumber']);
    :
    : if(isset($firstname)){
    : $where .= "firstname = ";
    : $where .= $firstname;
    : }
    : if(isset($lastname)){
    : if(isset($firstname)){
    : $where .= " AND ";
    : }
    : $where .= "lastname = ";
    : $where .= $lastname;
    : }
    : if(isset($identitynumber)){
    : if(isset($firstname) OR isset($lastname)){
    : $where .= " AND ";
    : }
    : $where .= "identitynumber = ";
    : $where .= $identitynumber;
    : }
    :
    : $sql = mysql_query("SELECT id, firstname, lastname, identitynumber
    : FROM patientdemo WHERE $where");
    :
    : if(mysql_num_rows($sql)>0){
    : WHILE($row = mysql_fetch_array($sql)){
    : $display .= "";
    : $display .= $row['firstname'];
    : $display .= "";
    : $display .= $row['lastname'];
    : $display .= "";
    : $display .= $row['identitynumber'];
    : $display .= "";
    : }
    : }else{
    : $display = "No Results Found!";
    : }
    :
    : }
    : ?>
    : : Hi there,
    : :
    : : I need some help please. I'm a newbie so please be patient!.
    : :
    : : I have created the following database:
    : :
    : : CREATE TABLE patientdemo (id INT(4) NOT NULL AUTO_INCREMENT PRIMARY
    : : KEY, firstname VARCHAR(30), lastname VARCHAR(30), identitynumber
    : : VARCHAR(30)); INSERT INTO patientdemo (firstname, lastname,
    : : identitynumber) VALUES ( "Alexa", "McDonald", "1234567890987"), (
    : : "Devie", "Slater", "987654321124" )
    : :
    : : I then created an HTML form which has two section. It has a section
    : : where users can enter information they want to search for and then a
    : : table where I would like information to display in once the search
    : : has been preformed.
    : :
    : :
    : :
    : : Search for patient:

    : :


    : : First Name:
    : :

    : : Last Name:
    : :

    : : Identity Number:
    : :

    : :


    : :
    : :
    : :
    : :
    : :


    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : : I then wrote a search.php form that handles the code to display the
    : : search result.
    : :
    : : <?php
    : : // Connect to DB
    : : mysql_connect("localhost","root");
    : : mysql_select_db("patient");
    : :
    : : $firstname = mysql_real_escape_string($_POST['firstname']);
    : : $lastname = mysql_real_escape_string ($_POST['lastname']);
    : : $identitynumber = mysql_real_escape_string
    : : ($_POST['identitynumber']);
    : :
    : : // Perform the fulltext search
    : : $query = "SELECT id, firstname, lastname, identitynumber
    : : FROM patientdemo";
    : :
    : : $result = mysql_query($query);
    : :
    : : // If results were found, output them
    : : if (mysql_num_rows($result) > 0) {
    : : printf //Display in the following HTML Table
    : : ("
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : :
    : : ");
    : : }
    : : else {
    : : printf("No results found");
    : : }
    : : ?>
    : :
    : : So anyway , the problem is that I want to be able to search for
    : : information using the input boxes on the HTML form , and then the
    : : info must display in the table (also on the HTML form). How would I
    : : go about this.
    : :
    : : Once again I'm a newbie so patients please.
    : :
    : : Thanking you in advance.
    : :
    :
    :

    Have a look at the attached script, remember to change the database connection parameters before running it.

    : :
    Patient Report
    First NameLast NameIdentity Number

    : :
    Patient Report
    First NameLast NameIdentity Number
Sign In or Register to comment.