• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Having problem with counter implementation on PHP page  RSS feed

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm trying to add a counter to a php page which generates an html table. Since the table goes down the page by default, I want to make it go side by side after %33. What am I doing wrong here? please. thanks for your help.
This is my code:

 
Saloon Keeper
Posts: 2153
278
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Mirc Sam wrote: I want to make it go side by side after %33.


Could you explain what you mean by after %33?  Do you want to do something different when the counter is multiples of 33?
 
Ron McLeod
Saloon Keeper
Posts: 2153
278
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And Welcome to the Ranch!
 
Mirc Sam
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks, guys!
What I mean here, normally table goes down the page, you need to scroll down to see the rest. What I am trying to do, after 33 rows (% 33 percent), I want the table continue side by side. So after every 33 rows, the table goes side by side, so can it can be viewed altogether without scrolling down. I hope this clarifies it, you can ask me if not.
 
Mirc Sam
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I made this example on excel. This is what I m trying to achieve. https://imgur.com/a/aHQOkTu
 
Ron McLeod
Saloon Keeper
Posts: 2153
278
Android Angular Framework Eclipse IDE Java Linux MySQL Database Redhat TypeScript
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for posting Java code for a PHP question, but I haven't looked at PHP for a long time, and I didn't want to post anything which wasn't valid PHP code.  Anyway, the concept is the same regardless of the programming language.

I would suggest that rather than create a number of individual tables and then figure-out how to style them to align side-by-side, it is probably better to just create a single table with the proper number of columns that would would need to hold the amount of data that you have to display.  To do this, you would need to know the total number of entries which you have before starting to construct the table, and then based on the maximum number of entries you want to place in a column (in your example 33), calculate the number of column required.

Here's an example using Java.  Instead of generating test data as in my example, your data would come from a database query

In my example, I have 17 entries, and am organizing the data  with a maximum of 5 entries per column, which results in this output:

When rendered in the  browser, it looks like this (I added styling of table, th, td {border: 1px solid black;} to make the row and column boundaries more clear)
 
Mirc Sam
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I use counter on other php pages, and it works. but here since I use a table in a search form, there is something I couldn't figure out to make it work. Nevertheless, I will examine your code.  Thank you, Ron.
 
Marshal
Posts: 6263
420
BSD
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I haven't used PHP also for a while. It isn't the language I like.

However, your logic looks incorrect. Please correct me if I'm wrong in thinking.

Why you set counter to 3 don't get, that's one. More importantly is, it seems that every iteration you set counter to 3, then increment once and during the next iteration again, set to 3 and increment... over and over again.

Am I incorrect?
 
Liutauras Vilda
Marshal
Posts: 6263
420
BSD
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that code even valid? Seems that you have only the loop in the first scope of php tags, which means counter is dangling outside as an illegal code construct.

Poor indentation you have also doesn't help. Please fix that one first and re-post the code so we might see better.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!