如何使用这些数据在mysql中创建表?

时间:2013-09-23 10:11:39

标签: php 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放入其中?

1 个答案:

答案 0 :(得分:-1)

你可以将它用于带有json_encode和json_decode

的单个表
<?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>