How to display different table in different page on PHP?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
hike37
Forum Newbie
Posts: 3
Joined: Tue Mar 29, 2011 12:35 am

How to display different table in different page on PHP?

Post by hike37 »

I have a PHP web-page contains few dynamic tables.

For example, I have 5 different categories of database tables: Math, Physic, Chemistry, Biology, and History.
I retrieve them onto my PHP page, and for loop them into 5 different HTML tables for categories:
Math Table, Physic Table, Chemistry Table, Biology Table, and History Table

Now, I would like to do paging on each categories. First page is Math table. There is a [Next] button at the end to click and goes to second page which is Physic categories with record-set display on table again. Second page has [Previous] and [Next] button for navigation again.


From:
----------
| Math |
----------
----------
| Physic |
----------
----------
| Chem |
----------
----------
| Bio |
----------
----------
|History |
----------

Switch into:
---------- ---------- ---------- ---------- ----------
| Math | | Physic | | Chem | | Bio | |History |
---------- ---------- ---------- ---------- ----------
page 1 page 2 page 3 page 4 page 5

But, if ANY table's record is empty:

---------- ---------- ----------
| Math | | Chem | | Bio |
---------- ---------- ----------
page 1 page 2 page 3

I would like to make them in ONE PHP web-page, is it possible? I have tried to display them into 5 separated Table tag on ONE page. Now I would like to separate each category into different page.

Next, how can I read empty record-set return Table and do not displaying it?
For example, Math table has records, but Physic table has no record, so my [Next button] on Math category will be posting the page=2 and find Chemistry page as Chemistry table has records.

I need the guidance urgently. I am using PHP and MySQL only, can I doing this without JavaScript or Java related script?
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: How to display different table in different page on PHP?

Post by social_experiment »

You would have to count the amount of records prior to creating the "pages" and from this determine which table will be eligible for display. The links vir also have to contain the name of the table somewhere in the url so you use it to determine which table is to be displayed.

Code: Select all

<?php
 // something similar to this
  echo '<a href="page.php?tableName=Math">Math table</a>';
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
hike37
Forum Newbie
Posts: 3
Joined: Tue Mar 29, 2011 12:35 am

Re: How to display different table in different page on PHP?

Post by hike37 »

social_experiment wrote:You would have to count the amount of records prior to creating the "pages" and from this determine which table will be eligible for display. The links vir also have to contain the name of the table somewhere in the url so you use it to determine which table is to be displayed.
Sorry, I would like to know how to do DYNAMIC paging in following situation:

You can see that I have 5 subjects, and I saved them as 5 tables in my MySQL database.

Each subject has more than 10 teachers: [ subjectRecordID ] , [ teacherID ] , [ teacherName ] , [ teachingDay ]

On my web page, I can display all teacher from Math, Physics, Chemistry, etc into 5 HTML Tables.

Now, I have a user control for user select the [ Day ] to view which teacher is teaching on what day: [ Monday ] , [ Tuesday ] , ... ... , [ Sunday ]

From [ Day ] selection, some records are empty, for example: Monday has no any lesson for Physics teachers to teach the class.

Hence, the web page will only displaying 4 tables.

Back to my question, instead of display all records in ONE single web page. I want make it to dynamic paging. Allow user to select [ Monday ] , and see [ Math ] together with [ Math teacher ] records ( teacher name ) on FIRST page, next page is [ Chemistry ] records, and so on.

I do not want to fix a static link for my Next Page button or Previous Page button. This is because I may adding teacher records anytime and in future may have [ Physics ] teacher on [ Monday ].
User avatar
social_experiment
DevNet Master
Posts: 2793
Joined: Sun Feb 15, 2009 11:08 am
Location: .za

Re: How to display different table in different page on PHP?

Post by social_experiment »

hike37 wrote:I would like to know how to do DYNAMIC paging in following situation
The example i gave is indeed dynamic.
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
hike37
Forum Newbie
Posts: 3
Joined: Tue Mar 29, 2011 12:35 am

Re: How to display different table in different page on PHP?

Post by hike37 »

social_experiment wrote:
hike37 wrote:I would like to know how to do DYNAMIC paging in following situation
The example i gave is indeed dynamic.
Sorry, I don't get it from your solution. Can you be kindly elaborate into step-by-step? Such as which part do I need to add IF statement, and how in the URL link shall I dynamic call the variable, etc?
Post Reply