使用php从sql表中获取比较name列的数据

mdfafbf1  于 2021-06-21  发布在  Mysql
关注(0)|答案(0)|浏览(171)

我需要通过使用php和mysql匹配数组中的名称来获取mysql表的值。我在下面提供我的数组列表:

$rootArr=array(
    array('cat_id'=>'2',
          'cat_name'=>'Context Of Organization'),
    array('cat_id'=>'3',
          'cat_name'=>'Leadership'));

我只有上述给定的数据,我需要与下表进行比较。
db\ U文件夹:

id           name                        parent_id

 328         COO                          22

 329         Other Documents              328

 330         Forms & Templates            328

 331         SOPs                         328

 332         FAQs                         328  

 333         LEAD                          22

 334         Other Documents              333

 335         Forms & Templates           333

 336         SOPs                        333

 337         FAQs                        333

在这里,我需要与这个表的数组值进行比较,并相应地获取数据。 'cat_name'=>'Context Of Organization' 等于 COO 名称列值来自 db_folder 表相似 'cat_name'=>'Leadership' 等于 LEAD 名称列值来自 db_folder table。
这里将显示数组值的时间 Context Of Organization 它将与name列值匹配 COO 把它的孩子带来 ids and name 表示此记录的附加值应为 name=COO,Other_Documents_id=329,Forms_id=330,sop_id=331,faq_id=332 等等。我的预期产出如下。

$rootArr=[
    {'cat_id':2,
     'cat_name':'Context Of Organization',
     'name':'COO',
     'Other_Documents_id':329,
     'Forms_id':330,
     'sop_id':331,
     'faq_id':332},
    {'cat_id':3,
     'cat_name':'Leadership',
     'name':'LEAD',
     'Other_Documents_id':334,
     'Forms_id':335,
     'sop_id':336,
     'faq_id':337}]

我的最终输出数组应该如上所示。

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题