Hi

I am struggling with some code and was wondering any someone could please help me. My php skills are VERY limited and only get stuff done by reading forums like this and watching YouTube videos :-[. I am enjoying learning so that is why I am sticking with it and not reverting back to html which I am pretty well accomplished at.

I have a phpMyAdmin database with 75 entries. My site has pagination setup where it shows 10 entries per page. I have setup one column in my database with enum and the values are 0, 1, 2, with the header 'active'

My query code is:

$sql = "SELECT * FROM videos WHERE active='1' AND title LIKE '%$q%' ORDER BY title";

Now my pages are only showing entries from the database where the active enum column is showing 1 (45 entries / 5 pages) which is fine, however my pagination is still showing 3 blank pages because for some reason it is picking up the entries that have the enum 0 or 2. So even though the entries with 0 and 2 are not showing, the pagination is still picking them up.

My guess is because in my sql I have SELECT * which is selecting all the entries and only displaying the active='1'. But how do I not get it to select the entries that have 0 and 2?

I am sorry if I have not been able to clearly convey my problem but if anyone has understood my problem please could you point me in the right direction, thank you very much.

Robert

    How does your pagination work? How does it determine how many pages to show?

    (Incidentally, '0', '1', and '2' are strange values to use for an enum: usually you'd use strings that mean something).

      Thank you Weedpacket for the reply and apologies but the code I entered above was not complete:

      $page_number *= $per_page_records;
      $sql  = "SELECT * FROM videos WHERE active='1' ORDER BY title LIMIT {$page_number},{$per_page_records}";

      I was told to use enum by a friend but being honest he doesn't have a great deal of php knowledge - Just more than me. What would you recommend I use?

      One question I have is if I wanted to make active='1 AND 2' but not 0. I have tried AND but that doesn't work. What would be the correct 'term' (if that's the right word) to use in that instance?

      Thanks again

        But that doesn't say anything about how you calculate the total number of pages to display. At some point you're running that query, and you'd have to be getting the number of pages needed to display them all somehow.

        At the moment it looks like you're getting the total number of pages from somewhere else before you even know what you'll be displaying on them (let alone how much you'll be displaying).

        Re enum: https://dev.mysql.com/doc/refman/8.0/en/enum.html

          Robert, with all due respect, I haven't seen any pagination code whatsoever ... you're only showing us the code that selects the records to be shown.

          I have a fairly nice pagination class ... if I ever stick it up on Github I'll link it for you.

            The OP solved this elsewhere, but didn't bother to revisit the other forums he posted on.

              Write a Reply...