通过升序PHP安排文本

时间:2011-01-08 03:28:19

标签: php

我正在使用此代码通过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完全不熟悉,因为您可以从问题中分辨出来,所以请用最简单的术语解释一下。此外,提供的任何代码都有两倍的帮助!!

1 个答案:

答案 0 :(得分:1)

您将需要开始使用mysql而不是将帖子保留在文件中。然后,您可以将记录存储在数据库中,以任意顺序查询数据库中的结果集。

相关问题