Jump to content

Recommended Posts

I am working on a site with snooker results. Each match is one row in a MySQL table, and somehow needs to contain the breaks (scores) that were made in each match. I am expecting the site to have many users, so I want to find an efficient way to do this.

 

Let's say a match has 5 breaks in it, 50, 60, 70, 80 and 90. Another match only has 3: 20, 30, 40. I thought of storing them in the database as follows: '20;30;40' and then using PHP Implode to create an array when retrieving them. I want to, however, also be able to make a high break list, which would display 90, 80, 70, 60, 50, 40, 30, 20.

 

I am however stuck on a way to combine the data from multiple matches and combine them into one list and then sort that list from high to low. Does anyone have any tips for this?

Link to comment
https://forums.phpfreaks.com/topic/225725-organizing-content-of-multiple-arrays/
Share on other sites

Assuming you have a matches table with an id and match details, then create a breaks table with a break id, related match id and 1 score per row.  So each match would have 1 row in the matches table but multiple rows in the breaks table (1 for each break).

 

If you want scores for a specific match then:

SELECT * FROM breaks WHERE match_id = 1 ORDER BY break_id ASC

 

If you want a high break list then:

SELECT * FROM breaks ORDER BY score DESC

 

By joining with the matches table you can get the match details (date, location, etc.).

The problem I see with this is the system will get very slow if I end up with 1000 matches and 10 breaks per match. It will be slow to do 'SELECT * FROM breaks WHERE MatchID="$ID"' for a table with 10.000 rows. Is there any way to avoid this?

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.