-2

I have a table with 2 columns and multiple data are there. Now I'm able to fetch data from table and print all data at a time but I want to display data in fixed number of rows for example: in Five Rows and then next data and so on.

DATABASE:PostgreSQL 9.5.12 running on localhost:5432
Frontend: PHP

ADyson
  • 57,178
  • 14
  • 51
  • 63
  • Try `LIMIT` and `OFFSET` – CannedMoose Apr 19 '18 at 09:39
  • yes, but with LIMIT and OFFSET, it shows fix number of row data, but i want to display data in a loop of five rows where rows number is fix. – Amit Chaturvedi Apr 19 '18 at 09:43
  • What do you mean by loop? A loop is an executable statement. – CannedMoose Apr 19 '18 at 09:45
  • I think you'll need to give us an example of some source data, and what the resulting output should look like. Your description alone is not clear. Also post any code you've tried so far, please. – ADyson Apr 19 '18 at 09:45
  • Thanks for Your Reply. in my concern, page height is fix, if i display all data then it page size will change so i want to display my table data in fix number of rows , something like data will display in loop in – Amit Chaturvedi Apr 19 '18 at 09:47
  • can you share your mail id so i'll send screen shot of page so the purpose will be cleared ? – Amit Chaturvedi Apr 19 '18 at 10:00
  • Again, provide an actual example of the output. e.g. If you have 23 rows, how will you decide to place it into 5 rows? It's not clear what the rules are - to write code we need general rules to apply to all cases, the numbers above are just an example of one scenario. Alternatively, if your page height is fixed, simply add a scrollable div within it to hold your table, and then you don't have to worry about this idea at all. – ADyson Apr 19 '18 at 10:00
  • And no, I won't give my email to random strangers, no offence. Besides you can edit your question here to include code, data and links to pictures (e.g. hosted at imgur or somewhere like that), and then _everyone_ can help - which is the whole point of SO. We're not here to do private consultancy, it's a public forum where people volunteer and build a public base of knowledge for future readers, not just the person asking. – ADyson Apr 19 '18 at 10:01
  • Web page will display in kiosk Mode F11 and screen will be wall mounted so scrollable div is of no use... and below this table of 5 rows, ticker is also there through with we display rss feed... – Amit Chaturvedi Apr 19 '18 at 10:06
  • here you can find screen shot.... https://imgur.com/a/M1JkB – Amit Chaturvedi Apr 19 '18 at 11:06
  • so...are you asking how to only fetch the first 5 rows from your database? Or are you asking to format X number of rows to always display in 5 rows? It's not clear from your description. – ADyson Apr 19 '18 at 13:39
  • only for first 5 rows , i can use LIMIT clause but my concern is that i want to display all data but 5 rows at a time only. for example 1st time from 1 to 5, in 2nd time 6 to 10, in 3rd time 11 to 15 and so on.... – Amit Chaturvedi Apr 20 '18 at 06:52
  • Does the page refresh the data automatically? Maybe you can maintain a session variable to tell you what iteration you are on and how many records are there in total. – ADyson Apr 20 '18 at 08:28

1 Answers1

0

If your only concern is you have a fixed height page and don't want to change height of page all you need to do is have a parent fixed height with overflow-y set to scroll.

for eaxmple:

<div style="height:300px; overflow-y:scroll">
    <table>
        <!-- Any number of rows here -->
    </table>
</div>
tornados
  • 86
  • 5