2013-09-23 3 views
-3

나는이러한 데이터를 사용하여 mysql에서 테이블을 만드는 방법은 무엇입니까?

$patients = array(); 
$patients[0] = array(

    'first_name' => 'john' , 

    'last_name' => 'doe' , 

    'diseases' => array ('Mood disorders' , 'Thyroid Cancer' , 'Migraine'), 

    'medication' => array (
        'pills' => array ('amoxicillin' , 'Vicodin') , 
        'syrups' => array ('Zantac' , 'Invirase') , 
        'surgeries' => array ('Urinary' , 'Ears' , 'Endocrine') 
       ) 

); 

이 같은 데이터베이스를 가지고 어디 선가 나는 모든 약물과 나는 단지 에코 알약 다른 곳을 에코 예를
이러한 밖으로 다른 장소를 에코.

지금 내가이 테이블을 mysql에 만들면 어떻게 내부 데이터를 넣을 수 있습니까?
제가 약을 만드는 경우 약 pillssurgeries을 어떻게 넣어야합니까?

+0

당신이 JSON 형식으로 넣어 수로 json_encode과 json_decode과 함께 하나의 테이블이 사용 할 수 –

+3

난 당신이 가시 미안 기본적으로 어떻게 데이터베이스를 설계하는 방법을 가르쳐 우리에게 요구하고있어 ... 이것은 매우 광범위한 주제입니다! –

+0

관계를 사용하십시오. 관계형 데이터베이스에 대한 자습서를 읽으십시오. – Kamil

답변

-1

당신이

<?php 
$patients = array(); 
$patients[0] = array(

    'first_name' => 'john' , 

    'last_name' => 'doe' , 

    'diseases' => array ('Mood disorders' , 'Thyroid Cancer' , 'Migraine'), 

    'medication' => array (
        'pills' => array ('amoxicillin' , 'Vicodin') , 
        'syrups' => array ('Zantac' , 'Invirase') , 
        'surgeries' => array ('Urinary' , 'Ears' , 'Endocrine') 
       ) 

); 

$encode = json_encode($patients); 

echo $encode; 

// Output 

//[{"first_name":"john","last_name":"doe","diseases":["Mood disorders","Thyroid Cancer","Migraine"],"medication":{"pills":["amoxicillin","Vicodin"],"syrups":["Zantac","Invirase"],"surgeries":["Urinary","Ears","Endocrine"]}}] 
// sore above string in table 


$decode = json_decode($encode, true); 

echo "<pre>"; 
print_r($decode); 
echo "</pre>"; 

//output 

(
    [0] => Array 
     (
      [first_name] => john 
      [last_name] => doe 
      [diseases] => Array 
       (
        [0] => Mood disorders 
        [1] => Thyroid Cancer 
        [2] => Migraine 
       ) 

      [medication] => Array 
       (
        [pills] => Array 
         (
          [0] => amoxicillin 
          [1] => Vicodin 
         ) 

        [syrups] => Array 
         (
          [0] => Zantac 
          [1] => Invirase 
         ) 

        [surgeries] => Array 
         (
          [0] => Urinary 
          [1] => Ears 
          [2] => Endocrine 
         ) 

       ) 

     ) 

) 
</pre> 
+0

많은 사람에게 감사의 말을 전합니다. 여기서 뭔가를 이해할 수 없습니다. 환자에게 DATA를 입력 할 수 있습니까? 예를 들어 print_r $ 환자)? – asdasd

+0

필자는 patients.json 파일을 의미했습니다. – asdasd

+0

는 $ encode를 1 테이블 필드에 저장합니다. –

관련 문제