Jump to content

Organising data from mysql - lost my head!


gibbonuk

Recommended Posts

Ok, i think ive crumbled my brain and lost my knowledge on what to do, so i need some help.

 

Basically, i have a simple mySQL DB, that had 10 tables, each containing one column called "value", and then on a page i did a loop that queried the DB and got each value column from the 10 tables.

 

But then i realised i might need more data tables and so realised it would be much better to have 1 tables and each value column in that one table, meaning only one query needed.

 

But ive got my self in a mess, as on the page the user can select which "value" column they want to look at.

 

So one user may want to look at values between (rows) 0 - 100, but only columns 2,4,8.

 

How do i do it? lol.

 

It was easy before as i just had a loop of 10, with a flag if to carry on or skip depending on the user selection, if the flag shows selected it gets the data from value column in table foo.

 

Hope you understand and can help.

Thanks

 

Link to comment
Share on other sites

Databases are not spreadsheets. Don't spread out same meaning data in columns in one table or use separate tables to hold same meaning data.

 

If you were to post an example showing the meaning and purpose of your data, someone can probably help with how your table(s) should be organized.

Link to comment
Share on other sites

Hi, ok ill try explain what im trying organize.

 

Basically the data is *values* come out of some hardware, thats all done on a server using some software, and then the "data" is inserted into an sql database for use online, charting ETC.

 

So the data being inserted is 10 x Different values every hour. And on a web page i want the user to select which data they want to look at, so a choice of 1 to 10, but its a multiple, could select 1, could select them all. Displaying them is then beyond this, but the data would be pulled from the mysql and placed in arrays.

 

So the way i did it before was one DB, 10 tables each with one column called "value". The 10 lots of values where inserted every 30 mins, and i programmed it so the user could select any amount of the 10 and look at them. I did this by a simple loop from 1 - 10, which per loop check if the user selected this one, if it did it went ahead and queried the database based on the table number from the current loop index and got the column data back and put them into an array. It then continues with the loop until exhausted.

 

But i then released this is currently using 10 queries per page,if i had many users at once this means lots of queries, and the "10 lots of values" maybe increased more over time, meaning more queries.

 

So i though it would be better to have 1 table, with 10 coloumns holding the data to do the same, but only using 1 query, but im having issues getting the "selected" data back and into arrays, and why im here :)

 

Hope this helps.

Andy

Link to comment
Share on other sites

Its ok, ive managed to find my brain (i think).

 

I now have 1 table with 10 columns of data.

 

One query gets the data from 10 columns and then i simply do the standard

 

*half pusedo code.*

while ($row = mysql_fetch_array($result)) {

    for ($i=0 to 10) {

      if $dataselected[$i] == true {

          put the data into arrays.

}

}

}

 

So this works, the question is now, will this be more optimised than the original code of having 10 tables and doing 10 queries?

 

Thanks

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.