assgar Posted December 2, 2012 Share Posted December 2, 2012 Hello I am trying to add two records to an array so I can identify which record has a priority 1 or priority 2. This is not working, how do get this to work? <? //get data from database $query = "SELECT a.street, a.city, a.province, b.dob, b.id1_name, b.id1_value, b.id1_priority, b.id2_name, b.id2_value, b.id2_priority FROM pat_address a LEFT JOIN pat_ident b ON a.patient_id = b.patient_id WHERE a.patient_id = '$patient_id' AND a.deleted = 'N' AND b.deleted = 'N' ; $result = mysqli_query ($mysqli, $query); while($row = mysqli_fetch_array($result)) { list($street, $city, $province, $birthday_c, $lang1_code, $id_priority1, $id_name1_c, $id_value1, $id_priority2, $id_name2_c, $id_value2, ) = $row; } //if a priority exists add the data to array $id_array = array();//identify array if(!empty($id_priority1) && $id_priority1 > 0) { $id_array['pri'] = $id_priority1;//priority $id_array['name'] = $id_name1_c; //name $id_array['value'] = $id_value1; //value } if(!empty($id_priority2) && $id_priority2 > 0) { $id_array['pri'] = $id_priority2; //priority $id_array['name'] = $id_name2_c; //name $id_array['value'] = $id_value2; //value } //sort into priority 1 & 2 foreach ($id_array AS $idray) { echo"()".$idray['pri']; switch($idray['pri']) { case'1': $name1 = $idray['name']; $value1 = $idray['value']; $priority1 = $idray['pri']; break; case'2': $name2 = $idray['name']; $value2 = $idray['value']; $priority2 = $idray['pri']; break; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/271509-sort-using-array/ Share on other sites More sharing options...
requinix Posted December 3, 2012 Share Posted December 3, 2012 Look at your highlighted code. Does anything seem wrong? Quote Link to comment https://forums.phpfreaks.com/topic/271509-sort-using-array/#findComment-1397045 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.