0

there is an in parameter as page. all i want to do is expel 1 from it and multiply by 10. but it gives me an error every time.

IF !a THEN

  SELECT * 
  from entry 
  WHERE topic_foreign_id = ( 
    select topic_id 
    from topic 
    where topic_name = topicName
  )
  ORDER BY entry_time ASC 
  LIMIT 10 OFFSET page;

ELSE

  SELECT * 
  from entry
  WHERE topic_foreign_id = ( 
    select topic_id 
    from topic 
    where topic_name = topicName
  )
  ORDER BY entry_time ASC;

END IF

this lines of code works great but when i want to make an aritmetic operation in first SQL query myAdmin throws an error everytime.

SELECT * 
from entry 
WHERE topic_foreign_id = ( 
  select topic_id 
  from topic 
  where topic_name = topicName
) 
ORDER BY entry_time ASC 
LIMIT 10 OFFSET 10 * ( page - 1); //throws error
Hogan
  • 69,564
  • 10
  • 76
  • 117
Gai Kuroda
  • 80
  • 1
  • 12

1 Answers1

0

--- EDITED ---

LIMIT doesn't seem to like calculations. Try using a variable and use that value in your stored procedure

DECLARE v_page_offset INT DEFAULT 0;
SET v_page_offset = 10*(page-1);

Then later

LIMIT 10 OFFSET v_page_offset;
Jacques Amar
  • 1,803
  • 1
  • 10
  • 12