-3

我有一个这样的数据库,

$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里面?

4

1 回答 1

-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>
于 2013-09-23T10:19:41.530 回答