/    Sign up×
Community /Pin to ProfileBookmark

Find number of fields in MySQL record

I am having a hard time trying to grasp how to do what I need to do here. I have a Database and inside I have a table (siteIndex) and each record has a list of user friendly names, all the other tables are number based names: 0, 1, 2, 3 and so on… Inside the numbered tables, the fields consist of an epoch time, and then a variable number of fields named d1, d2, d3, d4 and so on… There are also fields named t1, t2, t3, t4 and so on. The reason I say they field names vary in quantity, is that the number of logic sensors (d1 – dX) and temperature sensors (t1 – tX) are different quantities at every site location.

When I go to site.php?id=0 I want that page to look up the siteIndex table, scoop up all the names of the sensors and the quantity that corresponds to the “0” table, then lookup the site table “0” and get the most resent record and display the name in the left column of a table then the corresponding data in the same table but in the right column.

But, if the site only have 5 logic sensors, I only want the table to have that many rows. Some sites have more, some have less.

If there is an easy way to show what my database and tables look like so you can better understand it, let me know.

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@towerboyauthorOct 24.2013 — Or, if there is another way to build the database that would make viewing the data easier, I would be open to that as well. Basically I have a bunch of microcontrollers all over and they are sending update GET requests that are being added to the database table for that site. Here are a few examples of what some sites might send:

Site 0: telemetry.php?id=0&d1=0&d2=0&d3=0&d4=1&d5=0&d6=0&t1=71.15&t2=75.20&t3=86.98&t4=98.42&t5=58.00&t6=58.00&t7= 59.00&ip=10.125.103.58&type=a

Site 1: telemetry.php?id=1&d1=0&d2=1&d3=0&d4=0&t1=71.15&t2=75.20&t3=86.98&t4=98.42&ip=10.125.102.58&type=a

Site 2: telemetry.php?id=2&d1=0&d2=0&d3=0&d4=0&d5=0&d6=0&t1=71.15&t2=75.20&t3=86.98&t4=98.42&t5=58.00&t6=58.00&t7= 59.00&t8=64.03&t9=78.65&ip=10.125.101.58&type=a
×

Success!

Help @towerboy spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...