以下輸出顯示了第一個查詢的結果,但沒有顯示第二個查詢的結果。當我不使用函數進行查詢時,它可以正常工作。
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粉1933074652023-09-07 13:54:06
這些查詢都正常工作,我得到了想要的結果:
$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標籤,然後按城市分組,其中有放置廣告的城市。希望我做得對,我是這個頁面的新手。