get_var( $wpdb->prepare( "SELECT COUNT(*) FROM " . $wpdb->prefix . "mmjverify" ) );
$myrec = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "mmjverify " );
$result = (isset($myrec)) ? true : false;
if(!$result) {
$error .= "No Patients in database";
echo $error;
}
else {
$patient_list = '';
$patient_list .= 'There are '.$patient_count.' Patients in the database';
$patient_list .= '
';
$patient_list .= '
';
$patient_list .= '
ID
';
$patient_list .= '
First Name
';
$patient_list .= '
Last Name
';
$patient_list .= '
Birthdate
';
$patient_list .= '
Issue Date
';
$patient_list .= '
Exp Date
';
$patient_list .= '
Edit/Delete
';
$patient_list .= '
';
$patient_list .= '
';
foreach ($myrec as $patient) {
$editid = intval($patient->id);
$first_name = $patient->first_name;
$last_name = $patient->last_name;
$dob = $patient->dob;
$converted_dob = date("m-d-Y", strtotime($dob));
$issue_date = $patient->issue_date;
$converted_issue = date("m-d-Y", strtotime($issue_date));
$exp_date = $patient->exp_date;
$converted_exp = date("m-d-Y", strtotime($exp_date));
$patient_list .= '
';
$patient_list .= '
'.$editid.'
';
$patient_list .= '
'.$first_name.'
';
$patient_list .= '
'.$last_name.'
';
$patient_list .= '
'.$converted_dob.'
';
$patient_list .= '
'.$converted_issue.'
';
$patient_list .= '
'.$converted_exp.'
';
$patient_list .= '
';
$patient_list .= '
';
$patient_list .= '
';
}
$patient_list .= '
';
echo $patient_list;
}
}
else {
if(!empty ($editid)) {
if(empty ($search)) {
$search .= 'id = ' . '\''. $editid . '\'';
}
else {
$search .= ' AND id = ' . '\''. $editid . '\'';
}
}
if(!empty ($last_name)) {
if(empty ($search)) {
$search .= 'last_name = ' . '\''. $last_name . '\'';
}
else {
$search .= ' AND last_name = ' . '\''. $last_name . '\'';
}
}
if(!empty ($converted_s_dob)) {
if(empty ($search)) {
$search .= 'dob = ' . '\''. $converted_s_dob . '\'';
}
else {
$search .= ' AND dob = ' . '\''. $converted_s_dob . '\'';
}
}
if(!empty ($converted_s_issue)) {
if(empty ($search)) {
$search .= 'issue_date = ' . '\''. $converted_s_issue . '\'';
}
else {
$search .= ' AND issue_date = ' . '\''. $converted_s_issue . '\'';
}
}
if(!empty ($search)) {
$patient_count = $wpdb->get_var( $wpdb->prepare( "SELECT COUNT(*) FROM " . $wpdb->prefix . "mmjverify WHERE " . $search ) );
if ( $patient_count > 1 ) {
$myrec = $wpdb->get_results("SELECT * FROM " . $wpdb->prefix . "mmjverify WHERE " . $search );
}
elseif ( $patient_count == 1 ) {
$myrec = $wpdb->get_row("SELECT * FROM " . $wpdb->prefix . "mmjverify WHERE " . $search );
}
$result = (isset($myrec)) ? true : false;
if(!$result) {
$error .= "This Patient does not exist";
}
}
if(!empty ($error)) {
echo ''.$error.'
'; // set up error div for jQuery/Ajax
}
elseif ( $patient_count == 1 ) {
$patientform = '';
$patientform .= 'Edit a Patient
';
$patientform .= '';
echo $patientform;
}
elseif ( $patient_count > 1 )
{
$patient_list = '';
$patient_list .= 'There are '.$patient_count.' Patients that match this description';
$patient_list .= '';
$patient_list .= '
';
$patient_list .= '
ID
';
$patient_list .= '
First Name
';
$patient_list .= '
Last Name
';
$patient_list .= '
Birthdate
';
$patient_list .= '
Issue Date
';
$patient_list .= '
Exp Date
';
$patient_list .= '
Edit/Delete
';
$patient_list .= '
';
$patient_list .= '
';
foreach ($myrec as $patient) {
$editid = intval($patient->id);
$first_name = $patient->first_name;
$last_name = $patient->last_name;
$dob = $patient->dob;
$converted_dob = date("m-d-Y", strtotime($dob));
$issue_date = $patient->issue_date;
$converted_issue = date("m-d-Y", strtotime($issue_date));
$exp_date = $patient->exp_date;
$converted_exp = date("m-d-Y", strtotime($exp_date));
$patient_list .= '
';
$patient_list .= '
'.$editid.'
';
$patient_list .= '
'.$first_name.'
';
$patient_list .= '
'.$last_name.'
';
$patient_list .= '
'.$converted_dob.'
';
$patient_list .= '
'.$converted_issue.'
';
$patient_list .= '
'.$converted_exp.'
';
$patient_list .= '
';
$patient_list .= '
';
$patient_list .= '
';
}
$patient_list .= '
';
echo $patient_list;
}
}
}
else {
$error = "What the heck happened?";
echo ''.$error.'
'; // set up error div for jQuery/Ajax
}
?>