0

I have written a small piece of code to grab information from mysql database

the query I'm using:

SELECT id, title FROM mydb ORDER BY id DESC limi 0,4;

this code works perfectly on my local webserver but when I upload it to a public server it works but the id associated with all the results is the same and is equal to some wiered number like 201454672 which is wrong.

I checked the database everything there is okay, the data in place and their ids are true only select produces the wrong ID, everything else is okay

what the heck could cause this problem ?

6
  • 3
    Have your tried changing your limi to limit? Commented Mar 21, 2014 at 4:50
  • 1
    this is a typo mistake in here, it is not the case with the real code, anyway I have tried different simple queries to get the ID, they all produce the same wrong ID, I'm sure the problem is not from the query itself Commented Mar 21, 2014 at 5:09
  • Why don't post results from server database for show create table mydb? Did you check if there are any triggers defined on this table? Commented Mar 21, 2014 at 5:25
  • +---------+--------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------+--------------+------+-----+---------+----------------+ | id | int(11) | NO | PRI | NULL | auto_increment | | topic | varchar(100) | NO | | NULL | | | content | text | NO | | NULL | | | date | date | NO | | NULL | | | views | int(11) | NO | | NULL | | +---------+--------------+------+-----+---------+--------------- Commented Mar 21, 2014 at 5:31
  • I don't know how to check for the triggers and what could possible bring them cause I never create any additional things Commented Mar 21, 2014 at 5:32

2 Answers 2

1

As i can found in your query you made a silly mistake.Please correct it. Change

SELECT id, title FROM mydb ORDER BY id DESC limi 0,4;

to

SELECT id, title FROM mydb ORDER BY id DESC limit 0,4;

If it is still not working then change Datatype of id to BIGINT and try.

Sign up to request clarification or add additional context in comments.

2 Comments

this is a typo mistake when I wrote this question, unfortionatly that's not the problem
change Datatype of id to BIGINT and try.
0

Please check the table structure. Verify the Size of id field.

It seems that the data in you live server has id value beyond its limit.

For data type and its limit, refer MySQL Wiki

1 Comment

the size is int(11) it's okay because the ids stored are 1 and 2 and 3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.