Why are only the results of the first database query displayed and the functionality of the second query ignored?
P粉696891871
P粉696891871 2023-09-06 22:32:01
0
1
439

The following output shows the results of the first query, but not the second query. When I query without using a function, it works fine.

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

reply all(1)
P粉193307465

These queries all work fine and I get the results I want:

$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 />';
        }
       }

But when I build a function, I can't get the results of the second query:

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');

I have the categories, ads and neueorte tables. I want to build footer links so I want to have the categories as h3 tags and then group by city where I have the city where the ad is placed. Hope I'm doing it right, I'm new to this page.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!