Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/266.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在PHP上仅显示一个子id?_Php - Fatal编程技术网

如何在PHP上仅显示一个子id?

如何在PHP上仅显示一个子id?,php,Php,我有这样的想法: <?php foreach($categories as $k => $cat): $blog = $a->getSpend("WHERE hide = 0 && parent_id = $cat->id ORDER BY id DESC"); ?> parent_id=$cat->id这一个显示所有子id,但我只需要显示一个特定的子id,卡在这里,需要您的帮助 预先感谢。 < P>如果你想只针对每个类别选择“blog”,请

我有这样的想法:

<?php foreach($categories as $k => $cat):
$blog = $a->getSpend("WHERE hide = 0 && parent_id = $cat->id  ORDER BY id DESC");
?>

parent_id=$cat->id
这一个显示所有子id,但我只需要显示一个特定的子id,卡在这里,需要您的帮助


预先感谢。

< P>如果你想只针对每个类别选择“blog”,请考虑在查询中使用“限制”:

<?php foreach($categories as $k => $cat): ?>
    <?php
        $blog = $a->getSpend("WHERE hide = 0 && parent_id = $cat->id ORDER BY id DESC LIMIT 1");
    ?>
<?php endforeach ?>

是的,这很酷,但在这个父id中,我有5个类别,我想从中显示id为5的类别。如何仅显示此id而不显示其他id?