I have a court case number, complaint number and court division I need to check if exist in table. If it does exist, I need to retrieve the case_id.
If it does not exist, I need to insert the three fields (generating an autonumber case_id) and retrieve the case_id
This is what I came up with, it works, but I can't help but to think there may be a function I'm not aware of.
$sql5 = "SELECT case_id FROM crt_case WHERE case_no = '$case_no' AND cpt_no = '$cpt_no' AND crt_div = '$division'";
$result5 = mysql_query($sql5) or die(mysql_error());
if (mysql_num_rows($result5)!= 0)
{
$row5 = mysql_fetch_assoc($result5);
$case_id = $row5['case_id'];
}
else
{
$sql3 = "INSERT INTO crt_case (case_id, case_no, cpt_no, crt_div) VALUES ('', '$case_no', '$cpt_no', '$division')";
$result3 = mysql_query($sql3) or die(mysql_error());
$case_id = mysql_insert_id();
}
If it does not exist, I need to insert the three fields (generating an autonumber case_id) and retrieve the case_id
This is what I came up with, it works, but I can't help but to think there may be a function I'm not aware of.
$sql5 = "SELECT case_id FROM crt_case WHERE case_no = '$case_no' AND cpt_no = '$cpt_no' AND crt_div = '$division'";
$result5 = mysql_query($sql5) or die(mysql_error());
if (mysql_num_rows($result5)!= 0)
{
$row5 = mysql_fetch_assoc($result5);
$case_id = $row5['case_id'];
}
else
{
$sql3 = "INSERT INTO crt_case (case_id, case_no, cpt_no, crt_div) VALUES ('', '$case_no', '$cpt_no', '$division')";
$result3 = mysql_query($sql3) or die(mysql_error());
$case_id = mysql_insert_id();
}