Jump to content

Making the script echo only specific results


samanj

Recommended Posts

Hello community,

I am working on a database of specialties in the hospital I work.

The doctor's referral requests are sent to a mySQL database and I have, with the help of online guidance, produced a working php script that displays the information I need it to.

However, I need it a little bit more specific.

I intend to make multiple copies of this file for each specialty, so that when they open the file they only have the requests for that particular specialty.

My question is, with reference to my code below, can I make echo information so that online, for instance, if 'specialty1 = gastroenterology' (as in, that particular specialty that that referral request is for), then only the rows on the database that have that particular text are displayed only?

Hope that makes sense.

Code below for your reference and assistance is highly appreciated.

<!DOCTYPE html>
<html>
<head>
<title>Specialty Referral Form</title>
<style>
table {
border-collapse: collapse;
width: 100%;
color: #000000;
font-family: arial;
font-size: 10px;
text-align: center;
}
th {
background-color: #588c7e;
color: white;
}
tr:nth-child(even) {background-color: #f2f2f2}
</style>
</head>
<body>
<table>
<tr>
<th>Patient Details</th>
<th>Hospital Number</th>
<th>Date of Birth</th>
<th>Referred by:</th>
<th>New/Repeat Visit to Patient</th>
<th>Specialty</th>
<th>Admission Date</th>
<th>Too Ill for Clinic?</th>
<th>Diagnosis Aware?</th>
<th>Question</th>
<th>History</th>
<th>Medications</th>
<th>Examination</th>
<th>Results</th>
<th>WorkingDiagnosis</th>
<th>Investigation(s) Requested</th>
</tr>

<?php

$conn = mysqli_connect("localhost", "view", "", "referral");

// Check connection

if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$sql = "SELECT patientdetails, hospitalnumber, DoB, referral, admission, specialty1, admissiondate, illness, awareness, question, history, medications, examination, results, workingdiagnosis, investigations FROM referralform";
$result = $conn->query($sql);

if ($result->num_rows > 0) {

// output data of each row
while ($row = $result->fetch_assoc()) {
echo "<tr><td>" . $row["patientdetails"]. "</td><td>" . $row["hospitalnumber"] . "</td><td>" . $row["DoB"] . "</td><td>" 
. $row["referral"] . "</td><td>" . $row["admission"] . "</td><td>" . $row["specialty1"] . "</td><td>" . $row["admissiondate"] . "</td><td>"
. $row["illness"] . "</td><td>" . $row["awareness"] . "</td><td>" . $row["question"] . "</td><td>" . $row["history"] . "</td><td>"
 . $row["medications"] . "</td><td>" . $row["examination"] . "</td><td>" . $row["results"] . "</td><td>" . $row["workingdiagnosis"] . "</td><td>"
  . $row["investigations"]. "</td></tr>";
}
echo "</table>";
} else { echo "0 results"; }
$conn->close();
?>
</table>
</body>
</html>

I guess what I am looking for is something like echo specialty1 IF it writes a particular specialty and only that specialty.

Thank you.

Edited by samanj
Link to comment
Share on other sites

23 minutes ago, samanj said:

make multiple copies of this file for each specialty

no. you would use one file, that accepts a specialty id as an input, then uses a query with a WHERE clause in it to match the requested specialty information.

the specialties should be defined in a database table, with an id and a name. this will assign an id to each specialty. you would query this table to retrieve all the specialties to produce some sort of navigation/selection menu. when the visitor to the page picks a specialty via the navigation/selection menu, the submitted specialty id would be used in the code in the single file to cause the correct data to be retrieved and used to display the contents on the page.

Link to comment
Share on other sites

Ok thank you for the replies, it got the mental circuits in the brain working!

This is what I have been able to find and tweak based on both of your guidances (work in progress for all of the rows needed):

<!DOCTYPE html>
<html>
<head>
<title>Specialty Referral Form</title>
<style>
table {
width: 100%;
color: #000000;
font-family: arial;
font-size: 10px;
text-align: center;
}
th {
background-color: #588c7e;
color: white;
}
tr:nth-child(even) {background-color: #f2f2f2}
</style>
</head>
<body>
<table>
</tr>


<?php
$link = mysqli_connect("localhost", "root", "", "referral"); 
  
if($link === false){ 
    die("ERROR: Could not connect. " 
                . mysqli_connect_error()); 
} 
  
$sql = "SELECT * FROM referralcard WHERE hospitalnumber='345678'"; 
if($res = mysqli_query($link, $sql)){ 
    if(mysqli_num_rows($res) > 0){ 
        echo "<table>"; 
            echo "<tr>";  
                echo "<th>patientdetails</th>"; 
                echo "<th>hospitalnumber</th>"; 
                echo "<th>history</th>"; 
                echo "<th>comments</th>"; 
            echo "</tr>"; 
        while($row = mysqli_fetch_array($res)){ 
            echo "<tr>"; 
                echo "<td>" . $row['patientdetails'] . "</td>"; 
                echo "<td>" . $row['hospitalnumber'] . "</td>"; 
                echo "<td>" . $row['history'] . "</td>"; 
                echo "<td>" . $row['comments'] . "</td>"; 
            echo "</tr>"; 
        } 
        echo "</table>"; 
        mysqli_free_result($res); 
    } else{ 
        echo "No Matching records are found."; 
    } 
} else{ 
    echo "ERROR: Could not able to execute $sql. "  
                                . mysqli_error($link); 
} 
  
mysqli_close($link); 
?> 

I appreciate you want propose that I make one file for all the different specialties.

My question is probably even more specific now, but any advice on how I can tailor this part:

$sql = "SELECT * FROM referralcard WHERE hospitalnumber='345678'"; 

i.e. the hospital number, in a text box, where I can type the number I want and that number appear as the hospital number I want where '345678' is currently in the code.

Then press submit to have the single row result I am looking for.

Would this be more in the realm of merging a html text box with php coding (e.g. is it using the POST function?)

Hope this makes sense.

Thanks as always.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.