CodeIgniter Forums
MySQL ORDER BY FIELD does not working in CI 2.1.0 - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: MySQL ORDER BY FIELD does not working in CI 2.1.0 (/thread-52620.html)



MySQL ORDER BY FIELD does not working in CI 2.1.0 - El Forum - 06-19-2012

[eluser]foska[/eluser]
Code:
Error Number: 1305

FUNCTION ******.FIELD does not exist

SELECT `id`, `image`, `sex` FROM `users` WHERE `id` IN (28,35,40,34,33) ORDER BY FIELD (id,28,35,40,34,33)
here using $this->db->query();
Need help in this...




MySQL ORDER BY FIELD does not working in CI 2.1.0 - El Forum - 06-19-2012

[eluser]foska[/eluser]
hm... probably it`s hosting problem


MySQL ORDER BY FIELD does not working in CI 2.1.0 - El Forum - 06-19-2012

[eluser]prakash[/eluser]
do you want the results in order by id? if so use

Code:
SELECT `id`, `image`, `sex` FROM `users` WHERE `id` IN (28,35,40,34,33) ORDER BY id




MySQL ORDER BY FIELD does not working in CI 2.1.0 - El Forum - 06-19-2012

[eluser]foska[/eluser]
[quote author="prakash" date="1340102509"]do you want the results in order by id? if so use

Code:
SELECT `id`, `image`, `sex` FROM `users` WHERE `id` IN (28,35,40,34,33) ORDER BY id

[/quote] Yes, but I want to save original ordering, as in "where in" section


MySQL ORDER BY FIELD does not working in CI 2.1.0 - El Forum - 06-19-2012

[eluser]prakash[/eluser]
if your number of records are less you can go with

Code:
SELECT `id`, `image`, `sex` FROM `users` WHERE `id` IN (28,35,40,34,33) ORDER BY id='28',id='35',id='40',id='34',id='33'



MySQL ORDER BY FIELD does not working in CI 2.1.0 - El Forum - 06-19-2012

[eluser]foska[/eluser]
it was problem in space between FIELD and ()... Now working Smile