0

これをどのように表現すればよいかよくわからないので、さらに説明が必要な場合は、最善を尽くして説明できます。

ここにコードがあります

$file = "shout.txt";
$filed = file_get_contents($file);
preg_match_all('|<div class=\'date\'>(?P<date>.*?)&nbsp;.*<a.*>(?P<user>.*)</a>|i', $filed, $matches);

$shoutlines = file($shout_file);

$aTemp = array();
foreach($matches['user'] as $user) {
    $aTemp[] = "'" . mysql_real_escape_string($user) . "'";
}
$user = implode(",", $aTemp);

$getlevel = $db->query("SELECT * FROM accounts WHERE username IN ( ".$user." )"); 
$isadmin = $db->query("SELECT * FROM accounts WHERE username = '".$_SESSION['username']."'");
$admin = $isadmin->fetch_assoc();
while($status = $getlevel->fetch_assoc()){
    //output the html
    for($i = 0; $i < (1000); $i++)
    {
        if(isset($shoutlines[$i]))
        {
            if ($admin['admin'] == 1 && $status['sblevel'] != Admin && $status['sblevel'] != Banned){
                $delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a><a href='javascript: ban({$status['id']});' class='ban' onclick=\"return confirm('Are you sure you want to ban this user?');\">o</a>";
            }
            if ($admin['admin'] == 1 && $status['sblevel'] != Admin && $status['sblevel'] == Banned){
                $delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a><a href='?index=shout&unban&user=".$shout['username']."' class='ban' onclick=\"return confirm('Are you sure you want to unban this user?');\">&oslash;</a>";
            }
            if ($admin['admin'] == 1 && $status['sblevel'] == Admin){
                $delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a>";
            }
            if ($admin['sblevel'] == Moderator && $status['sblevel'] != Admin && $status['sblevel'] != Moderator){
                $delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a><a href='?index=shout&ban&user=".$shout['username']."' class='ban' onclick=\"return confirm('Are you sure you want to ban this user?');\">o</a>";
            }
            if ($status['sblevel'] == Moderator  && $status['sblevel'] != Admin){
                $delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a>";
            }
            $shoutline = preg_replace('/<\/div>\n/', ' ', $shoutlines[$i], 1);
            echo showSmileys($shoutline) . $delete . "</div>";
        }
    }
}

問題は、投稿したすべてのユーザーのすべての投稿が複製されることです..これは while ループにあるためだと思いますが、それを行う方法がわかりません。ユーザーは管理者/モッドであり、投稿の横に削除/禁止ボタンが配置されている場合は、削除できるようにします。現在のところ、すべての投稿の横に削除ボタンを配置し、その横に削除および禁止ボタンを付けてすべてを複製しています。

4

1 に答える 1

1

メッセージの繰り返しを避けるための最も簡単な変更を次に示します。あなたはauthor()、shout_file から行を取得して作成者 ID を返す関数を提供する必要があります。

while($status = $getlevel->fetch_assoc()){
    //output the html
    for($i = 0; $i < (1000); $i++)
    {
        if(isset($shoutlines[$i]))
        {
            if (author($shoutlines[$i]) != $status['id']) {
                continue;
            }
            if ($admin['admin'] == 1 && $status['sblevel'] != Admin && $status['sblevel'] != Banned){
                $delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a><a href='javascript: ban({$status['id']});' class='ban' onclick=\"return confirm('Are you sure you want to ban this user?');\">o</a>";
            }
            if ($admin['admin'] == 1 && $status['sblevel'] != Admin && $status['sblevel'] == Banned){
                $delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a><a href='?index=shout&unban&user=".$shout['username']."' class='ban' onclick=\"return confirm('Are you sure you want to unban this user?');\">&oslash;</a>";
            }
            if ($admin['admin'] == 1 && $status['sblevel'] == Admin){
                $delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a>";
            }
            if ($admin['sblevel'] == Moderator && $status['sblevel'] != Admin && $status['sblevel'] != Moderator){
                $delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a><a href='?index=shout&ban&user=".$shout['username']."' class='ban' onclick=\"return confirm('Are you sure you want to ban this user?');\">o</a>";
            }
            if ($status['sblevel'] == Moderator  && $status['sblevel'] != Admin){
                $delete = "<a href='javascript: delete_shoutline({$i});' title='Delete' class='delete' onclick=\"return confirm('Are you sure you want to delete this message?');\">x</a>";
            }
            $shoutline = preg_replace('/<\/div>\n/', ' ', $shoutlines[$i], 1);
            echo showSmileys($shoutline) . $delete . "</div>";
            unset($shoutlines[$i]);
        }
    }
}

作成者からのメッセージごとに「このユーザーを禁止」を繰り返すため、これはおそらく最善の方法ではありません。禁止/禁止解除のオプションを各ユーザーの最初に 1 回配置してから、各行で「削除」することをお勧めします。

于 2012-12-10T20:50:09.133 に答える