Query Question
#1

hi all !


i have a question

i have a "chat" system forum/server with mysql now i have to delete the old message when a new message come
like...


New message
old
old
old
old
old
old
old
old
This get deleted ..


only for no make bigger chat xD so is there a query for do that?

thx in advance
Reply
#2

Make a 2D array variable and store 10 and the size of the string then delete the 10th if it's not empty.


example of 2D array.

pawn Код:
new _Chat[10][256];
Reply
#3

i have to do it in mysql query not in pawno



example : DELETE FROM messages WHERE .................. or LIMIT this i dont know
Reply
#4

Alternatively you could give the rows an ID (auto increment) and ..
Код:
SELECT * FROM `chat` ORDER BY `id` DESC LIMIT 10;
This would only fetch the 10 latest chat messages.
Reply
#5

this delete the new messages ... i want delete old messages
Reply
#6

in php it would look like this:
pawn Код:
$query = "SELECT * FROM `chat`";
$result = mysql_query($query);
for($i=0; $i<mysql_num_rows($result); $i++)
{
  $id = mysql_result($result, $i, 'id');
  if($id >= 10)
  {
    $query2 = "DELETE FROM `chat` WHERE `id`=".$id;
    $result2 = mysql_query($query2);
  }
  else
  {
    $id2 = $id + 1;
    $query2 = "UPDATE `chat` SET `id`=".$id2." WHERE `id`=".$id;
    $result2 = mysql_query($result);
  }
}
(no auto increment)
Reply
#7

say

Код:
Duplicate entry '0' for key 1
this dont increment the id ...
Reply
#8

$query = "SELECT * FROM `chat` ORDER BY `id` DESC";

try that



ps: and add the new entry after this code
Reply
#9

same error .. i try debug it with modify myself the id and when reaches 10 the 10 go down and the old me ssage go frist xD
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)