Jump to content

Sort Using Array


assgar

Recommended Posts

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;
				  }   
			  }
?> 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.