Query Question - Printable Version
+- SA-MP Forums Archive (
https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (
https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (
https://sampforum.blast.hk/forumdisplay.php?fid=12)
+---- Forum: Help Archive (
https://sampforum.blast.hk/forumdisplay.php?fid=89)
+---- Thread: Query Question (
/showthread.php?tid=256493)
Query Question -
iJumbo - 21.05.2011
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
Re: Query Question -
Zh3r0 - 21.05.2011
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.
Re: Query Question -
iJumbo - 21.05.2011
i have to do it in mysql query not in pawno
example : DELETE FROM messages WHERE .................. or LIMIT this i dont know
Re: Query Question -
woot - 21.05.2011
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.
Re: Query Question -
iJumbo - 21.05.2011
this delete the new messages ... i want delete old messages
Re: Query Question -
Sascha - 21.05.2011
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)
Re: Query Question -
iJumbo - 21.05.2011
say
Код:
Duplicate entry '0' for key 1
this dont increment the id ...
Re: Query Question -
Sascha - 21.05.2011
$query = "SELECT * FROM `chat` ORDER BY `id` DESC";
try that
ps: and add the new entry after this code
Re: Query Question -
iJumbo - 21.05.2011
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