【发布时间】:2014-02-26 02:42:35
【问题描述】:
这里的任何帮助都会令人难以置信:
所需的工作流程:用户浏览 sql 行(第 1 页),仅显示选择性数据。单击一行后,它会路由(第 2 页上的脚本)到显示该行所有数据的页面(第 3 页)。并且该页面保存在目录中。
第 1 页 (index.php)
<?php
include("db.php");
$query="SELECT * FROM `stories` WHERE id
BETWEEN 1 AND 200 order by RAND() LIMIT 50";
$result=mysqli_query($connection,$query);
?>
<?php
while ($data = mysqli_fetch_assoc($result)):
$id = $data['id'];
$title = $data['title'];
?>
<li onclick="location.href='create_page.php?id=<?php echo $id; ?>';">
<h3><?php echo $title; ?></h3>
</li>
<?php
endwhile;
mysqli_close($connection);
?>
第 2 页 (create_page.php)
<?php
include("db.php");
$_GET['id'];
$query="SELECT * FROM `stories` WHERE id=$_GET[id]";
$result=mysqli_query($connection,$query);
while ($data = mysqli_fetch_assoc($result)):
$id = $data['id'];
$author = $data['author'];
$title = $data['title'];
$page_path = $data['page_path'];
if(is_null($page_path)){$page_path = "#";}
$data2 = file_get_contents("single-page.php");
$data2 = str_replace($title2, $title, $data2);
$data2 = str_replace($author2, $author, $data2);
file_put_contents($page_path, $data2);
endwhile;
mysqli_close($connection);
?>
第 3 页(单页.php)
<!DOCTYPE HTML>
<html>
<head>
<title>
<?php echo $title2; ?>
</title>
</head>
<body>
<?php echo $title2; ?>
<?php echo $author2; ?>
</body>
</html>
用户单击行后,脚本开始运行,但冻结(我检查过,页面源在浏览器中为空白)。参数“ID”在 url (. . .php?id= . .) 中,但之后没有。 'page_path' 是 sql 表中的一列(对每一行都是唯一的),并指示要保存页面的位置。 id 是唯一的 auto_num 列。还有,文件和文件夹权限都是777。
提前谢谢你!
替代方法:
<?php
// Start the buffering //
ob_start();
?>
Your page content bla bla bla bla ...
<?php
echo '1';
// Get the content that is in the buffer and put it
In your file //
file_put_contents('yourpage.html',
ob_get_contents());
?>
【问题讨论】:
-
尝试打印 mysqli_query('----') 或 die('query not executed') 之类的错误。在第二页中 GET[id]-->更改为 GET[' id']
-
当我将 [id] 更改为 ['id'] 时,dreamweaver 中出现语法错误
标签: php mysql get file-get-contents str-replace