Best way to manage 35 variables?

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
Tchapman
Forum Newbie
Posts: 11
Joined: Wed Dec 01, 2010 3:38 am

Best way to manage 35 variables?

Post by Tchapman »

I have been sorting out how to manage around 35-40 variables between a wifi device and end users over the internet. To do this I set up a MYSQL db on my website, and have some test code in php that will update and get from the db based on what is coming in from the POST commands.

Currently I am using for testing something like this from the microprocessor device that talks to wifi via UART:

POST$/dbaccess.php?

Then the processor sends out whatever it wants to send based on what needs to happen. Below it just sends out a lot of test vars and data:

Code: Select all

ser.str(2, string("A=1&B=2&C=3&D=-2500555123&E=5&F=6&G=7&H=8&I=9&J=10&K=11&L=12&M=13&N=14&O=15&P=16&Q=17&R=18&S=19&T=20&U=21&V=22&W=23&X=24&Y=25&Z=26")) 
The php at the site does some updating to several locations on the database, and echos all the variables back to the wifi device just so I can monitor that it is getting it in tact.

The plan is to have the sifi device updating the db as anything changes on it, and the end user can monitor the values and understand what is going on, plus the the user can update the variables, and the wifi can get the changes and store them.

Is using the example above of sending all ( or in some cases just some) variables using a scheme like a-z considered practical or is there a better way to do it? I need to keep things ultra simple for now since I am just starting.
Last edited by Tchapman on Sat Dec 04, 2010 7:33 am, edited 1 time in total.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Best wat to manage 35 variables?

Post by Christopher »

Tchapman wrote:Is using the example above of sending all ( or in some cases just some) variables using a scheme like a-z considered practical or is there a better way to do it? I need to keep things ultra simple for now since I am just starting.
I'm not sure that practical has anything to do with it. Clear variables names are mainly to improve maintenance and reduce errors. If the letters A-Z are clear and maintainable as parameter names then this scheme is fine.
(#10850)
Tchapman
Forum Newbie
Posts: 11
Joined: Wed Dec 01, 2010 3:38 am

Re: Best way to manage 35 variables?

Post by Tchapman »

Thanks. I guess I am trying to see if there is a more elegant way to send the variables back and forth. This method works and I do intend to change the names to make it easier to remember what is what.
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: Best way to manage 35 variables?

Post by Christopher »

Elegant is a little subjective. Some programmers might prefer for you to post JSON or XML in a single variable. Others might think using HTTP params is cleaner because it is one less thing to parse. Other factors may also affect your decision.
(#10850)
Post Reply