Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php/mysql]Shoutbox
zaba12
post 26.04.2006, 13:29:17
Post #1





Grupa: Zarejestrowani
Postów: 223
Pomógł: 0
Dołączył: 29.08.2003
Skąd: Gliwice

Ostrzeżenie: (10%)
X----


Witam chciałbym sie zapytac jak dorobic skrypt zeby usuwal wpisy jak bedzie ich np 25 lub co tydzien nie chodzi mi o cron'a

  1. <?
  2.  
  3. function shoutbox()
  4. {
  5. $query = "SELECT * FROM shoutbox order by id DESC limit 10";
  6. $result = mysql_query ($query);
  7. while ($row = mysql_fetch_array($result)) {
  8. $id = $row['id'];
  9. $date = $row['date'];
  10. $autor = $row['autor'];
  11. $text = $row['text'];
  12. echo '<table cellpadding="2" cellspacing="0" border="0" class="table0" width="100%">
  13. <tr>
  14. <td class="row1" width="100%"><span class="gensmall" style="font-size:9px; font-family: Tahoma, Verdana, Arial, Helvetica, sans-serif">['.$date.']</span><span class="gensmall"> '.$autor.': &nbsp;'.$text.'</span></td>
  15.  
  16. </tr>
  17. </table>
  18. <hr size="1">';
  19.  }
  20.  
  21. }
  22.  
  23. function shoutbox_add()
  24. {
  25.  echo '
  26.  <form name="add" action="shout.php" method="post">
  27. <table><tr><td>Wiadomość:</td><td><input type="text" name="message" style="height:17px;font-size:9px;width:360px;" size="60" maxlength="500" value="" class="post"></td>
  28. <td>Autor:</td><td><input type="text" name="autor" style="height:17px;font-size:9px;width:100px;" size="30" maxlength="200" value="" class="post"></td><td><input type="hidden" name="s" value="ok" /><input type="submit" value="Dodaj" class="button" /></td></tr></table>
  29. </form>
  30. ';
  31. }
  32.  
  33. function shoutbox_add_ok()
  34. { global $message,$autor,$theme;
  35. $message = preg_replace_callback("#([\n ])([a-z]+?)://([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)#si", "bbcode_autolink", $message);$message = preg_replace("#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]*)?)#i", " <a href=\"http://www.\\2.\\3\\4\" target=\"_blank\">www.\\2.\\3\\4</a>", $message);
  36. usmieszki();
  37. if (!$message OR !$autor){
  38. echo 'Nie wypełniłeś wszystkich pól';
  39. } else {
  40. $query = "INSERT INTO shoutbox VALUES (NULL, NOW(),'$autor','$message')";
  41. mysql_query ($query);
  42. if($query)
  43. {
  44. echo "<script>self.location.href=\" shout.php\";</script>";
  45. }
  46. else
  47. {
  48. echo '<br>Wystąpił nieznany błąd podczas dodawania.<br><br>';
  49. }
  50. }
  51. }
  52.  
  53. function bbcode_autolink($str){$lnk=$str[3];if(strlen($lnk)>30){if(substr($lnk,0,3)=='www'){$l=9;}else{$l=5;}$lnk=substr($lnk,0,$l).'(...)'.substr($lnk,strlen($lnk)-8);}return ' <a href="'.$str[2].'://'.$str[3].'" target="_blank">'.$str[2].'://'.$lnk.'</a>';}
  54. function usmieszki() {
  55. global $theme,$message;
  56. $message = str_replace (';)', '<img src="theme/'.$theme.'/usmieszki/super.gif" border="0">', $message);
  57. $message = str_replace ('biggrin.gif', '<img src="theme/'.$theme.'/usmieszki/d.gif" border="0">', $message);
  58. $message = str_replace (':)', '<img src="theme/'.$theme.'/usmieszki/super1.gif" border="0">', $message);
  59. $message = str_replace (':/', '<img src="theme/'.$theme.'/usmieszki/tak_jakos.gif" border="0">', $message);
  60. $message = str_replace (':spac', '<img src="theme/'.$theme.'/usmieszki/spiacy.gif" border="0">', $message);
  61. $message = str_replace (':strach', '<img src="theme/'.$theme.'/usmieszki/strach.gif" border="0">', $message);
  62. $message = str_replace (':zly', '<img src="theme/'.$theme.'/usmieszki/strach.gif" border="0">', $message);
  63. $message = str_replace (':zygi', '<img src="theme/'.$theme.'/usmieszki/zygi.gif" border="0">', $message);
  64. $message = str_replace (':co', '<img src="theme/'.$theme.'/usmieszki/co.gif" border="0">', $message);
  65. $message = str_replace (':okulary', '<img src="theme/'.$theme.'/usmieszki/okulary.gif" border="0">', $message);
  66. $message = str_replace (':lewo', '<img src="theme/'.$theme.'/usmieszki/lewo.gif" border="0">', $message);
  67. $message = str_replace (':serce', '<img src="theme/'.$theme.'/usmieszki/serce.gif" border="0">', $message);
  68. $message = str_replace ('!', '<img src="theme/'.$theme.'/usmieszki/za.gif" border="0">', $message);
  69. $message = str_replace ('?', '<img src="theme/'.$theme.'/usmieszki/he.gif" border="0">', $message);
  70. // tutaj cenzura... nastepnym razem proszę usuwać wulgaryzmy z kodu! /tiraeth/
  71. return $message;
  72. }
  73.  
  74. ?>
Go to the top of the page
+Quote Post
soska66
post 27.04.2006, 19:09:48
Post #2





Grupa: Zarejestrowani
Postów: 132
Pomógł: 1
Dołączył: 3.02.2005

Ostrzeżenie: (0%)
-----


pewnie mozna inaczej ale ja u siebie na stronce mam taki myk

w tabeli wpisow mozesz wstawic dodatkowe pole, ktore bedzie przechowywalo numer tygodnia, w ktorym wpis zostal dodany - funkcja date("W",time());

a potem

  1. <?php
  2. $week=date("W",time());
  3. mysql_query("DELETE FROM wpisy where tydzien='$week-2'");
  4. ?>


czyli jesli wpis byl dodany np w tygodniu 17, to zostanie usuniety w poniedzialek tygodnia 20. Mozesz sobie odjac wtedy ile chcesz tych tygodni

ja to co prawda w innym celu wykorzystuje smile.gif mi jest na reke, ze skrypt dziala z koncem tygodnia ( w moim przypadku chodzi o premiery filmowe) smile.gif

Ten post edytował soska66 27.04.2006, 19:11:51
Go to the top of the page
+Quote Post
Hacker
post 28.04.2006, 14:54:22
Post #3





Grupa: Zarejestrowani
Postów: 225
Pomógł: 0
Dołączył: 1.11.2005

Ostrzeżenie: (0%)
-----


tak jak mówi soska66 tylko że zamiast = w zapytaniu daj < i dodaj 1 do tygodnia od którego mają być usuwane albo z dokładną datą i wrzucasz to do function shoutbox() na samym początku. A z 25-cioma o co Ci chodzi ma zostawiać ostanie 25 czy o co??
(moderatorzy -> Przedszkole pls)

Ten post edytował Hacker 28.04.2006, 14:55:48


--------------------
(\.../)This is Bunny
(O.o)Copy Bunny into your signature to help him...
(> <)...on his way to world domination
Go to the top of the page
+Quote Post
zaba12
post 28.04.2006, 19:38:13
Post #4





Grupa: Zarejestrowani
Postów: 223
Pomógł: 0
Dołączył: 29.08.2003
Skąd: Gliwice

Ostrzeżenie: (10%)
X----


nie niema zostac ! ma usunac te 25 limit ! ze po 25 postach w shoutboxie on bedzie usuwal automatycznie i robil pusta liset
Go to the top of the page
+Quote Post
Hacker
post 29.04.2006, 08:24:36
Post #5





Grupa: Zarejestrowani
Postów: 225
Pomógł: 0
Dołączył: 1.11.2005

Ostrzeżenie: (0%)
-----


  1. <?php
  2.  
  3. function shoutbox_add_ok()
  4. { global $message,$autor,$theme;
  5. $message = preg_replace_callback("#([\n ])([a-z]+?)://([a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]+)#si", "bbcode_autolink", $message);$message = preg_replace("#([\n ])www\.([a-z0-9\-]+)\.([a-z0-9\-.\~]+)((?:/[a-z0-9\-\.,\?!%\*_\#:;~\\&$@\/=\+]*)?)#i", " <a href=\"http://www.\\2.\\3\\4\" target=\"_blank\">www.\\2.\\3\\4</a>", $message);
  6. usmieszki();
  7. if (!$message OR !$autor){
  8. echo 'Nie wypełniłeś wszystkich pól';
  9. } else {
  10. $q = 'SELECT COUNT(id) as ile FROM shoutbox'
  11. $r = mysql_query ($query);
  12. $ile = mysql_fetch_array($r, 'MYSQL_ASSOC')
  13. if($ile['ile']==25)
  14. {
  15. $q = 'DELETE FROM shoutbox'
  16. $r = mysql_query ($query);
  17. }
  18. $query = "INSERT INTO shoutbox VALUES (NULL, NOW(),'$autor','$message')";
  19. $result = mysql_query ($query);
  20. if($result)
  21. {
  22. echo "<script>self.location.href=\" shout.php\";</script>";
  23. }
  24. else
  25. {
  26. echo '<br>Wystąpił nieznany błąd podczas dodawania.<br><br>';
  27. }
  28. }
  29. }
  30. ?>


Ten post edytował Hacker 29.04.2006, 08:25:12


--------------------
(\.../)This is Bunny
(O.o)Copy Bunny into your signature to help him...
(> <)...on his way to world domination
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 24.07.2025 - 17:16