Mengapakah hanya hasil pertanyaan pangkalan data pertama dipaparkan dan kefungsian pertanyaan kedua diabaikan?
P粉696891871
P粉696891871 2023-09-06 22:32:01
0
1
474

Output berikut menunjukkan hasil pertanyaan pertama, tetapi bukan pertanyaan kedua. Apabila saya bertanya tanpa menggunakan fungsi, ia berfungsi dengan baik.

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

membalas semua(1)
P粉193307465

Pertanyaan ini semuanya berfungsi dengan baik dan saya mendapat hasil yang saya inginkan:

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

Tetapi apabila saya membina fungsi, saya tidak boleh mendapatkan hasil pertanyaan kedua:

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

Saya mempunyai kategori jadual, iklan dan neueorte. Saya ingin membina pautan pengaki supaya saya mahu mempunyai kategori sebagai teg h3 dan kemudian kumpulan mengikut bandar di mana saya mempunyai bandar tempat iklan diletakkan. Harap saya melakukannya dengan betul, saya baru di halaman ini.

Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan