为什么只显示第一个数据库查询的结果,而忽略了第二个查询的功能?
P粉696891871
P粉696891871 2023-09-06 22:32:01
0
1
468

以下输出显示了第一个查询的结果,但没有显示第二个查询的结果。当我不使用函数进行查询时,它可以正常工作。

function builtFooter($catactive, $catlink)
{
    global $conn;
    $sql = "SELECT catid, catname_de AS name, catlink as link, extern, extlink FROM categories WHERE catactive=? AND catlink!=? ORDER BY catsort";
    $stmt = $conn->prepare($sql);
    $stmt->bind_param("ss", $catactive, $catlink);
    $stmt->execute();
    $result = $stmt->get_result();
    while ($cat = $result->fetch_assoc()) {
        $resArr[] = $cat;
        echo '

' . $cat['name'] . '

'; $cities = "SELECT COUNT(a.ad_id) AS ANZ,a.region, b.city, b.citylink FROM ads a, neueorte b WHERE a.zeigen=? AND a.gesperrt=? AND FIND_IN_SET(?, a.portale) AND a.catid=? AND b.po_id=a.region GROUP BY a.region ORDER BY ANZ DESC LIMIT 0,50"; $stmt = $conn->prepare($cities); $zeigen = 'ja'; $gesperrt = 'no'; $category = $cat['catid']; $stmt->bind_param("ssss", $zeigen, $gesperrt, $portalnumber, $category); $stmt->execute(); $result = $stmt->get_result(); while ($city = $result->fetch_assoc()) { $resArr[] = $city; echo ' ' . $city['city'] . '
'; } } } builtFooter('yes', 'markt');
P粉696891871
P粉696891871

全部回复(1)
P粉193307465

这些查询都正常工作,并且我得到了想要的结果:

$catactive = 'yes';
$catlink = 'markt';
$sql = "SELECT catid, catname_de AS name, catlink as link, extern, extlink FROM categories WHERE catactive=? AND catlink!=? ORDER BY catsort";
        $stmt = $conn->prepare($sql); 
        $stmt->bind_param("ss", $catactive, $catlink);
        $stmt->execute();
        $result = $stmt->get_result();
        while ($cat = $result->fetch_assoc()) {    
            $resArr[] = $cat;
           echo '<h3><a href="'.$cat['link'].'" title="'.$cat['name'].' bei $portalname">'.$cat['name'].'</a></h3>';
        
        $cities = "SELECT COUNT(a.ad_id) AS ANZ,a.region, b.city, b.citylink FROM ads a, neueorte b WHERE a.zeigen=? AND a.gesperrt=? AND FIND_IN_SET(?, a.portale) AND a.catid=? AND b.po_id=a.region GROUP BY a.region ORDER BY ANZ DESC LIMIT 0,50";
        $stmt = $conn->prepare($cities); 
        $zeigen = 'ja';
        $gesperrt = 'no';
        $category = $cat['catid'];
        $stmt->bind_param("ssss", $zeigen, $gesperrt, $portalnumber, $category);
        $stmt->execute();
        $r = $stmt->get_result();
        while ($city = $r->fetch_assoc()) {    
            $resArr[] = $city;
            echo' '.$city['city'].' <br />';
        }
       }

但是当我构建一个函数时,我无法得到第二个查询的结果:

function builtFooter($catactive,$catlink){
        global $conn;
            $sql = "SELECT catid, catname_de AS name, catlink as link, extern, extlink FROM categories WHERE catactive=? AND catlink!=? ORDER BY catsort";
            $stmt = $conn->prepare($sql); 
            $stmt->bind_param("ss", $catactive, $catlink);
            $stmt->execute();
            $result = $stmt->get_result();
            while ($cat = $result->fetch_assoc()) {    
                $resArr[] = $cat;
               echo '<h3><a href="/sexkontakte/'.$cat['link'].'" title="'.$cat['name'].' bei $portalname">'.$cat['name'].'</a></h3>';
            
            $cities = "SELECT COUNT(a.ad_id) AS ANZ,a.region, b.city, b.citylink FROM ads a, neueorte b WHERE a.zeigen=? AND a.gesperrt=? AND FIND_IN_SET(?, a.portale) AND a.catid=? AND b.po_id=a.region GROUP BY a.region ORDER BY ANZ DESC LIMIT 0,50";
            $stmt = $conn->prepare($cities); 
            $zeigen = 'ja';
            $gesperrt = 'no';
            $category = $cat['catid'];
            $stmt->bind_param("ssss", $zeigen, $gesperrt, $portalnumber, $category);
            $stmt->execute();
            $r = $stmt->get_result();
            while ($city = $r->fetch_assoc()) {    
                $resArr[] = $city;
                echo' '.$city['city'].' <br />';
    }
    }
       }
       builtFooter('yes','markt');

我有categories、ads和neueorte这些表。我想构建页脚链接,所以我想将类别作为h3标签,然后按城市分组,其中有放置广告的城市。希望我做得对,我是这个页面的新手。

热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板