Celkový počet vzkazů uživatele
12 príspevkov
Archív diskusného fóra
Fórum je uzavreté a slúži iba na čítanie. Niektoré informácie môžu byť zastarané.
-
Každý uživatel dává do fór vzkazy. Já potřebuju, aby se mu někde zobrazilo, kolik už celkem přidal vzkazů. Využívám fóra (ony to nejsou fóra ale to je fuk) tohoto typu: <!doctype html public "-//w3c//dtd html 3.2//en"> <!-- /* This chat has been created by Nicola Delbono <key5@key5.com> */ /* you can modify and/or use the code for free. Pleeease keep these three lines */ /* into your customized chat */ --> <!-- Tested on WinNT4.0 SP4 --> <head> <title>Vzkazy</title> <meta name="GENERATOR" content="Arachnophilia 4.0"> <meta name="FORMATTER" content="Arachnophilia 4.0"> <!-- Arachnophilia is free but !careware! --> <!-- http://www.arachnoid.com/arachnophilia/index.html --> </head> <?php include 'http://www.superbecko.wz.cz/central/grafika.txt';?> <? $person = str_replace ("\n"," ", $person); $person = str_replace ("<", " ", $person); $person = str_replace (">", " ", $person); $person = stripslashes ($person); ?><form action="vzkazy.php3" method="post"> <p align="center"><big><b>Vzkazy</b></big><br> <input type="text" name="nadpis" size="50"><br> <textarea name="message" rows="3" cols="38"></textarea><br> <input type="submit" value=" Odeslat "> </form> </p> <hr> <? session_start(); /* the $chat_file_ok is a txt file (or whatever else) I use for */ /* messages storage */ $chat_file_ok = "msg.txt"; /* $chat_lenght is the number of messages displayed */ $chat_lenght = 1000; /* $max_file_size is the maximum file size the msg.txt file can reach */ /* assuming that any chatter doesn't write a message longer than */ /* $max_single_msg_lenght (this case: 100,000 bytes = 100Kb) */ $max_single_msg_lenght = 100000; $max_file_size = $chat_lenght * $max_single_msg_lenght; /* check if file size is over maximum (set with $max_file_size ) */ $file_size= filesize($chat_file); /* if file size is more than allowed then */ /* reads last $chat_lenght messages (last lines of msg.txt file) */ /* and stores them in $lines array */ /* then deletes the "old" msg.txt file and create a new msg.txt */ /* pushing the "old" messages stored in $lines array into the */ /* "new" msg.txt file using $msg_old. */ /* Note: this is done in order to avoid huge msg.txt file size. */ if ($file_size > $max_file_size) { /* reads file and stores each line $lines' array elements */ $lines = file($chat_file_ok); /*get number of lines */ $a = count($lines); $u = $a - $chat_lenght; for($i = $a; $i >= $u ;$i--){ $msg_old = $lines[$i] . $msg_old; } $deleted = unlink($chat_file_ok); $fp = fopen($chat_file_ok, "a+"); $fw = fwrite($fp, $msg_old); fclose($fp); } /* the following is because every message has to be */ /* placed into one single line in the msg.txt file. */ /* You can render \n (new lines) with "<br>" html tag anyway. */ $msg = str_replace ("\n"," ", $message); /* if the user writes something... */ /* the new message is appended to the msg.txt file */ /* REMEMBER: the message is appended, hence, if */ /* you want the last message to be displayed as the */ /* first one, you have to */ /* 1. store the lines (messages) into the array */ /* 2. read the array in reverse order */ /* 3. post the messages in the output file (the chat) */ /* I added these three lines in order to avoid buggy html code and slashes */ $msg = str_replace ("\n"," ", $message); $msg = str_replace ("<", " ", $msg); $msg = str_replace (">", " ", $msg); $msg = str_replace ("blb", "*", $msg); $msg = str_replace ("deb", "*", $msg); $msg = stripslashes ($msg); if ($msg != ""){ $fp = fopen($chat_file_ok, "a+"); $fw = fwrite($fp, "\n<b>$nadpis </b>(". $_SESSION['first_name'] ." ". $_SESSION['last_name'] .")<br> $msg<br><hr>"); fclose($fp); } $lines = file($chat_file_ok); $a = count($lines); $u = $a - $chat_lenght; /* reads the array in reverse order and outputs to chat */ for($i = $a; $i >= $u ;$i--){ echo $lines[$i] . "<br>"; } ?> </body> Vím zatím jen to, že v DB budu muset udělat sloupec kam se to bude psát. A ten se bude jmenovat "vzkazy" Díky předem za odpovědi Maikis:-)))
-
A ještě jeden dotaz: Jak u tohoto "fóra zjistim, kolik vzkazů tam je? Potřebuji to ale zobrazit na úplně jiné stránce..
-
IMHO všechny informace o vzkazech zapisovat do DB (stačí třeba jen datum ,čas a autor), když zbytek dáváš do texťáku a pak pomocí mysl_num_rows() sečíst podmínkou jen vzkazy dotyčného nebo bez podmínky vzkazy ode všech.
-
Sorry >> mysql_num_rows()
-
nečetl jsem si ten zdroják, ale předpokládám, že máš nějakou tabulku jako forum se sloupci id, uzivatel, text, datum... a dalsimi tak potom neni nic jednodužšího než zavolat dotaz select count(*) from forum where 1 na zjištění celkového počtu příspěvků a select count(*) from forum where uzivatel = 'franta' na zjištění počtu příspěvků uživatele franty to s tím frantou bylo jen takové zjednodušení, v praxi spíše než jméno tam budeš dávat "odkaz" na toho uživatele, třeba číselné id...
-
Každá zpráva obsahuje <hr> nešlo by prostě jenom nějak sečíst, kolik je v souboru msg.txt těchto tagů? Jenom jestli to nějak nejde
-
". $_SESSION['first_name'] ." ". $_SESSION['last_name'] ." Tohle mi funguje všude v pohodě ale tohle ne: ". $_SESSION['username'] ." čím to může být? username funguje jen při přihlášení a jinak vůbec ne:( zobrazí se tam místo něj jen volné místo:(
-
Máš $_SESSION['username'] nějak naddefinováno, co má obsahovat? Z toho dlouhého skriptu se mi to nějak nepodařilo vyčíst. Hned po session_start() bych to definoval: $_SESSION["username"] = "nějaká hodnota";
-
a proč nějaká hodnota? ona je potřeba? jaká? potřebuju aby to prostě ve fóru zobrazilo jeho username
-
venuj sa tomu trosku viacej, naprogramuj si vlastny zdrojak...
-
>> a proč nějaká hodnota? ona je potřeba? jaká? potřebuju aby to prostě ve fóru zobrazilo jeho username Však ti to říkám: $_SESSION["username"] = $username;
-
Maikis: Jestli je to <hr> vždz na samostatné řádce, tak: <?php $data=File("msg.txt"); $pocet_hr=0; for($i=0;$i<Count($data);$i++) { if($data[$i]=="<hr>") $pocet_hr++; }