我想循環搜索標籤並收集所有與該標籤相關的帖子。爲此我知道我需要使用while
或foreach
循環。PHP雖然循環搜索多個MySQL查詢
變量以聚集:$tag = trim($_GET['tag']);
然後,我會通過標籤表像這樣來搜索:
$stmt = $mysqli->prepare('SELECT post_id FROM tags WHERE tag = ?');
$stmt->bind_param('s', $tag);
$stmt->execute();
$stmt->bind_result($post_id);
$stmt->store_result();
$rows = $stmt->num_rows;
$stmt->fetch();
$stmt->close();
這可能會返回多行,因爲它是通過所有的搜索有標籤的帖子,例如「旅行」。
隨後,在收集相關的post_id
標籤的帖子,我搜索的職位表將其輸出到用戶之前獲得所有關於文章的信息:
$stmt = $mysqli->prepare('SELECT title FROM posts WHERE id = ?');
$stmt->bind_param('i', $post_id);
$stmt->execute();
$stmt->bind_result($title);
$stmt->store_result();
$rows_posts = $stmt->num_rows;
$stmt->fetch();
$stmt->close();
我的問題是,這只是將工作對於一個職位和我不知道如何循環搜索,所以具有相同標記的多個帖子被返回。
這是尋找有前途的人冠軍。我在哪裏放置'$ stmt-> get_result()'部分。我沒有收到任何回覆,並且當前頁面無法加載。但是現在它在'$ stmt-> close()'之後,所以我猜這是可以預期的。 – Harry 2014-10-04 19:58:27