SQL數據庫我有一個頁面,index.php
檢索到的URL PHP頁面,用<select>
<options>
充當過濾器。通過Ajax,從SQL數據庫中檢索信息並在同一頁面回顯到<div>
。其中一個被回顯的字段包含另一個頁面的URL,例如a1701.php
。到目前爲止,一切都很完美。包括基於從使用Ajax
但是,我不希望顯示網址,而是希望頁面的內容例如a1701.php
將以與使用<?php include 'a1701.php' ?>
時相同的方式顯示。
我已經閱讀了很多關於SO帖子,但沒有發現任何描述這種情況下(也許我找錯了東西在這種情況下,請指教)。繼其他部分相關職位的建議,我已經試過幾件事包括:
- 使用絕對而不是相對鏈接與
$_SERVER['DOCUMENT_ROOT']
include 'a1701.php';
VSecho "<?php include 'a1701.php'; ?>"
- 使用
<
代替<
等 - 重裝具體
<div>
S(我還沒有真正嘗試這一點,因爲我想不通,我將不得不放在哪裏,使其工作什麼代碼。)
我嘗試了多個網址並檢查了每個網址都是正確的。
index.php
<script>
function filterQuestions() {
\t var selectCount = document.getElementsByTagName("select").length;
\t var str = [];
\t for (var i = 0; i < selectCount; i++) {
\t \t if (document.getElementsByTagName("select")[i].value != "") {
\t \t str[i] = document.getElementsByTagName("select")[i].name+"="+document.getElementsByTagName("select")[i].value; \t \t \t
\t \t }
\t }
\t \t if (window.XMLHttpRequest) {
\t \t \t xmlhttp = new XMLHttpRequest(); \t \t \t
\t \t } else {
\t \t \t xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
\t \t }
\t \t xmlhttp.onreadystatechange = function() {
\t \t \t if (this.readyState == 4 && this.status == 200) {
\t \t \t \t document.getElementById("questionList").innerHTML = this.responseText;
\t \t \t }
\t \t };
\t \t xmlhttp.open("GET","filter.php?"+str.join("&"),true);
\t \t xmlhttp.send();
}
</script>
\t \t <select name="branch" onchange="filterQuestions()">
\t \t \t <option value="All">All branches</option>
\t \t \t <option value="Number">Number</option>
\t \t \t <option value="Trigonometry">Trigonometry</option>
\t \t </select>
\t \t <select name="topic" onchange="filterQuestions()">
\t \t \t <option value="All">All topics</option>
\t \t \t <option value="sinrule">Sine Rule</option>
\t \t \t <option value="cosrule">Cosine Rule</option>
\t \t </select>
filter.php
<?php
$branch = $_GET["branch"];
$topic = $_GET["topic"];
if($branch != "All") {
\t $wherefilter[] = "branch = '".$branch."'";
}
if($topic != "All") {
\t $wherefilter[] = "topic = '".$topic."'";
}
$where = join(" AND ", $wherefilter);
if($where != NULL) {
\t $where = " WHERE $where";
}
mysqli_select_db($link,"generator");
$sql="SELECT question_name, url FROM questions".$where;
$result = mysqli_query($link,$sql);
echo "<table>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['question_name'] . "</td>";
echo "<td>" . $row['url'] . "</td>";
echo "</tr>";
$pagelink = $row['url'] . '.php'; /* URL is correct */
echo"<br>";
echo $pagelink;
echo"<br>";
echo "<?php include '" . $pagelink . "'; ?>";
echo "<br>";
echo "<?php include '" . $pagelink . "'.php; ?>"; /* doesn't work */
include $pagelink; /* doesn't work */
}
echo "</table>";
mysqli_close($link);
?>
a1701.php
包含我想包括的內容。我也嘗試過包括其他內容。
有沒有辦法實現我所追求的?我正朝着正確的方向前進嗎?
如果我理解你正確,你想要a1701.php執行並輸出一些可以插入div的html。是對的嗎? – ryantxr
@ryantrx,這是正確的。 –
@ryantrx,我可能誤解了你的要求,所以澄清: 'a1701.php'不是發送Ajax請求的地方。 'a1701.php'只是我想包含在'index.php'中的內容(數據庫中的一個字段爲每個記錄返回一個url,這個特定記錄的url是'a1701.php')。目前,網址顯示正常,但我想交換此網址的文件的實際內容 - 這一點是我無法工作的部分。 –