Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

echo a table of links that build and run dynamic sql 1

Status
Not open for further replies.

knifey

Technical User
Nov 14, 2006
180
GB
Hi,
I am very new to php (but not programming) and have just inherited an nhs php website that links to an Access patient db via odbc for patient searching, adding records, etc.
The current setup displays a list of matching patients on screen by table echoing (name, dob, patient number, etc). I would like the patient numbers to be links which will build sql statements with the only variable being the patient number (e.g. SELECT * FROM tbl WHERE tbl.patNum=$patientNumber). So the user can fetch the patients details by clicking the link rather than retyping the patient number each time.
I've seen something similar with url's on this thread:
Can someone nudge me in the right direction to accomplish the same but with links that build and run sql dynamically when clicked?
Any advice or pointers would be much appreciated.
K
 
an nhs php website that links to an Access patient db via odbc for patient searching, adding records, etc.

now that explains a lot about the NHS IT projects ...

anyway ...

the easiest way to achieve this is to create a wee function
Code:
function getPatientLink($id){
   return 'path/to/patientIDScript.php?patientID=' . urlencode($id);
}

then in your loop that outputs the table do something like this

Code:
foreach ($row as odbc_fetch($query)):
    ... table output code ...
    echo "<td><a class='dontunderlineme' href='" . getPatientLink($row['patient_id']) . "' >{$row['patient_lastname']}, {$row['patient_firstname']}</a></td>";
endforeach;

and then a receiving script something like this

Code:
//test for authenticated access

// test for presence of ID
if(!isset($_GET['patientID'])) die('must provide valid patient ID');

//test to make sure that the authenticated user is authorised to access this patient record 
/*
do something here
*/

//all authorised and authenticated now
$sql = <<<SQL
SELECT          *
FROM            patient_table
WHERE          `patient_id` = '%s'
SQL;
$query = sprintf($sql, mysql_real_escape_string(trim($_GET['patientID']))); //or use some other appropriate escaping mechanism for access via odbc
 
Hi jpadie,
Ahh sprintf, what a great function. My mind boggles with the uses I could put this to.
Thanks again,
K
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top