[SOLVED] Neophp Query DELETE Last n Records... - Forum

Forum Navigation
You need to log in to create posts and topics.

[SOLVED] Neophp Query DELETE Last n Records...

Hi guys,

No matter how much I search and try, I can't find a way to:

"DELETE FROM mytable WHERE blah = '1' AND blah2 = ? ORDER BY id DESC LIMIT 10";

Yea, I was saying... I need to DELETE  Last 10 items from a table. with some filters...

Not working. any idea?

Same method for select or update works, but for DELTE something is wrong...

Hi..

Try this

"DELETE * FROM mytable WHERE blah = 1 AND blah2 = ? ORDER BY id DESC LIMIT 10";

 

 

noyzen and javadrajabihakami have reacted to this post.
noyzenjavadrajabihakami

Thank you but It's not working. my neofunctions.php give error 500 as before...

I have googled this and seems like query is right. maybe there is problem in neophp code ?

@noyzen it's very difficult to know what's happening exactly in your script with the information you share.
Make sure that the $blah2 value variable contains a valid value. Verify that it is properly assigned and has the expected data type.
Try executing the script without that SQL variable. I think the problem could be there.

noyzen has reacted to this post.
noyzen

Thank you guys for help,

@luishp I have tried without variable, almost tried anything possible :)

Well, I found this kind of code is working:

"DELETE FROM mytable WHERE field1 = 'test' AND field2 = ? AND id IN (SELECT id FROM mytable ORDER BY id ASC LIMIT 2)";

That one works, but in Answer subroutine I get empty [data] callback variable, but it works.

It's getting more wired when exact same code but with LIMIT 1 is not working. everything above LIMIT 2 is ok!
(I have checked database and records are fine there)

I'm still trying to find how to solve the problem. I let you guys know...

OKAY, Problem solved.

This is the sql query code that you need to remove one last item - or last n items:

"DELETE FROM mytable WHERE id IN (SELECT id FROM mytable WHERE field1 = 'test' AND field2 = ? ORDER BY id ASC LIMIT 1)";

This code works for me. (Still in callback [data] variable I get nothing insted of usual "true")

Regards.

luishp has reacted to this post.
luishp