我使用下面的代码通过POST写入一个名为posts.txt的文件:
<?php
if (isset($_POST['username']) && isset($_POST['score'])) {
$fp = fopen("posts.txt", "r");
$size = filesize("posts.txt");
if ($size > 0) {
$script = fread($fp, $size);
} else {
$script = "";
}
fclose($fp);
$script = '<div style="width : 300px; position : relative"><font face="helvetica, geneva, sans serif" size="6"><b>' . $_POST['score'] . '</b></font><font face="helvetica, geneva, sans serif" size="4"><i> scored by ' . $_POST['username'] . '</i> <em> on '. $_POST['date'] . '</em></font><br><img src="Bar.png" /></div>' . $script;
$f = fopen("posts.txt", "w");
fwrite($f, $script);
fclose($f);
echo "<html><head><title>Success!</title></head><body>Submission Posted!</body></html>";
}
else {
echo "<html><head><title>POST Request Error</title></head><body>Most set method to POST and params to be 'username' and 'score'</body></html>";
}
?>如果你能告诉我如何根据$_POST['score']以升序排列不同的“帖子”,我将不胜感激。我是一个全新的php新手,因为你可以从这个问题中看出,所以请用你最简单的术语来解释它。此外,提供的任何代码都会提供两倍的帮助!
发布于 2011-01-08 12:17:09
您将希望开始使用mysql,而不是将帖子保存在文件中。然后,您可以将记录存储在数据库中,以所需的任何顺序查询数据库中的结果集。
https://stackoverflow.com/questions/4632167
复制相似问题