$res=mysql_query("SELECT code_type,code,date,provider_id FROM billing WHERE encounter='$encounter' AND pid='$pid'");
while($row=mysql_fetch_array($res)){
$code_type=$row['code_type'];
$code=$row['code'];
$date=$row['date'];
$provider=$row['provider_id'];
$standard_code=$code_type.":".$code;
$res1=mysql_query("SELECT procedure_type_id FROM procedure_type WHERE standard_code='$standard_code'");
while($row1=mysql_fetch_array($res1)){
$procedure_type_id=$row1['procedure_type_id'];
mysql_query("INSERT INTO procedure_order(procedure_type_id,date_ordered,provider_id,date_collected,order_priority,order_status
,patient_instructions,patient_id,encounter_id) VALUES('$procedure_type_id','$date','$provider','$date','high','pending','$complaints','$pid','$encounter_id')")
or die(mysql_error());
}
}

The above query saves(inserts) more than once in the database. what can be the cause especially in the while loops ? please help me rectify.

I think, you are requesting the query to be executed; for as long as there are matching records in the database, just as stated in your code, right here;

while($row1=mysql_fetch_array($res1))

The code will insert records for as long as $res1 is returning records.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.