Choose a name from multiple results

Hello all,

I would appreciate any help on this since I am new to php. Thanks in advance.

My users can search a database for a last name, since there are many same last names in my DB I want my user to be able to choose from the results list the actual name they want and then display the persons details to them.
For example my quesry is the following:

$query=("SELECT name, last_name, gender, fathers_name, mothers_name, dob, insurance);

First I want to display the list of results with only the name, last_name, and fathers name to the screen and let the user click on the name they want and then display the rest of the information (ie mothers name, dob, insurance etc).

The output data should be something like this:

Lastname, Name, Fathers Name

Smith John, James
Smith Jim, Bob
Smith Jane, Henry

When a user click on a name above then the detailed info for that name will display like:

Lastname, Name, Fathers Name, mothers name, dob, insurance

Thanks in advance for any help

hello dimlaz, save below code and run. than click on name which is in red color. i hope you are looking for this type of out put. [php] // save as demo.php .name{ cursor:pointer; color:#FF0000;} <? $userdetail = array( 0=>array('lastname'=>'Smith','name'=>'John','fathername'=>'James','mothername'=>'rosey','dob'=>'03 March 1990','insurance'=>'yes'), 1=>array('lastname'=>'Smith','name'=>'Jim','fathername'=>'Bob','mothername'=>'boby','dob'=>'05 March 1996','insurance'=>'No'), 2=>array('lastname'=>'Smith','name'=>'Jane','fathername'=>'Henry','mothername'=>'Juliya','dob'=>'05 June 1996','insurance'=>'Yes'), );

echo ‘

Lastname   Name   Father Name
’;
echo ‘
Mother Name   DOB   Insurance
’;
echo ‘
’;
for($i=0;$i<count($userdetail);$i++)
{
echo ‘
’;
echo ‘
’.$userdetail[$i][‘lastname’].’ ‘.$userdetail[$i][‘name’].’ ‘.$userdetail[$i][‘lastname’].’ 
‘;
echo ‘
’;
echo $userdetail[$i][‘mothername’].’ ‘.$userdetail[$i][‘dob’].’ '.$userdetail[$i][‘insurance’];
echo ‘
’;
echo ‘
’;
echo ‘
’;
}
?>
[/php]
i hope this will helpful for you
reply your feedback
SR

Hi,

Thank you for the quick reply. Since I am new to php I dont undesrtand how can I use the results from my SELECT database statement —> $query=("SELECT name, last_name, gender, fathers_name, mothers_name, dob, insurance);

to display the information and then let the user click on the name they want. Can you please show me this also, thank you very much for your help.

Hello dimlaz,
first create a databse than run the below Sql for creating a table “demo” and insert two record in it.

CREATE TABLE IF NOT EXISTS `demo` ( `id` int(11) NOT NULL auto_increment, `name` varchar(255) NOT NULL, `lastname` varchar(255) NOT NULL, `fathername` varchar(255) NOT NULL, `mothername` varchar(255) NOT NULL, `dob` date NOT NULL, `insurance` varchar(255) NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=3 ;


– Dumping data for table demo

INSERT INTO demo (id, name, lastname, fathername, mothername, dob, insurance) VALUES
(1, ‘John’, ‘Smith’, ‘James’, ‘Rosey’, ‘1993-03-15’, ‘Yes’),
(2, ‘Jim’, ‘Smith’, ‘Bob’, ‘boby’, ‘1998-03-15’, ‘No’);

Than save below code and run.
Note: before run this code please change your database connection detail.

[php] .name{ cursor:pointer; color:#FF0000;} <?

$con = mysql_connect(“localhost”,“username”,“password”); // replace username and password with your database usename and password
if (!$con)
{
die('Could not connect: ’ . mysql_error());
}

mysql_select_db(“dbname”, $con); //remove dbname with your database name

$result = mysql_query(“SELECT * FROM demo”);

echo ‘

Lastname   Name   Father Name
’;
echo ’
  Mother Name   DOB   Insurance
’;
echo ‘
’;
$i=0;
while($row = mysql_fetch_array($result))
{
echo ‘
’;
echo ‘
’.$row[‘lastname’].’ ‘.$row[‘name’].’ ‘.$row[‘lastname’].’ 
‘;
echo ‘
’;
echo $row[‘mothername’].’ ‘.$row[‘dob’].’ '.$row[‘insurance’];
echo ‘
’;
echo ‘
’;
echo ‘
’;
$i++;
}

mysql_close($con);
?>
[/php]
I hope this will helpful for you.
Reply your feedback
SR

Hello again,

I tried it but I cant get it to work. Below is all my code that I use. I have a form that the user types in the lastname and hits a Serach button.

If you could please help I would appreciate it.

Thanks

Code:

echo "

.name{ cursor:pointer; color:#FF0000;} ";

$username=“user”;
$password=“pass”;
$database=“dbname”;
mysql_connect(‘url’,$username,$password);
@mysql_select_db($database) or die( “Unable to select database”);
mysql_set_charset(‘utf8’);
if($_POST[‘find_patient’]) {
$input_lastname=$_POST[‘txt_lastname’];
$result=mysql_query(“SELECT name, last_name, gender, fathers_name, mothers_name, dob, insurance, first_visit_date, address, city, p_code, country, fathers_work_phone, fathers_cell_phone, mothers_cell_phone, home_phone, email, patient_notes FROM patient WHERE last_name=’$input_lastname’”);
echo “

Lastname   Name   Father Name
”;
echo "
  Mother Name   DOB   Insurance
";
echo “
”;
$i=0;
while($row = mysql_fetch_array($result))
{
echo “
”;
echo “
”.$row[“last_name”]." “.$row[“name”].” “.$row[“lastname”].” 
“;
echo “
”;
echo $row[“mothers_name”].” “.$row[“dob”].” ".$row[“insurance”];
echo “
”;
echo “
”;
echo “
”;
$i++;
}
mysql_close();}
hello dimlaz, use below code i hope this will fulfill your requirement. one more thing please replace db connection detail [php] .name{ cursor:pointer; color:#FF0000;} <? if(!empty($_POST['lastname'])) { $con = mysql_connect("localhost","dbusername","dbpassword"); // replace username and password with your database usename and password if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("dbname", $con); //remove dbname with your database name $selectsql = "SELECT * FROM demo where lastname='".$_POST['lastname']."'"; $result = mysql_query($selectsql); echo '
Lastname   Name   Father Name
'; echo '
  Mother Name   DOB                 Insurance
'; echo '
'; $i=0; while($row = mysql_fetch_array($result)) { echo '
'; echo '
'.$row['lastname'].'         '.$row['name'].'     '.$row['fathername'].' 
'; echo '
'; echo '             '.$row['mothername'].'             '.$row['dob'].'      '.$row['insurance']; echo '
'; echo '
'; echo '
'; $i++; } mysql_close($con); } else { echo ''; echo '

Search patient by LastName

'; echo ''; echo ''; echo ''; } ?> [/php]

i hope this will helpful for you.
Reply your feedback
SR

Thank you very much for the help and your time.

hello dimlaz, i hope your problem finally gone. Ask and post other issues. Enjoy.. :) :D ~~SR~~
Sponsor our Newsletter | Privacy Policy | Terms of Service