Note that there are some explanatory texts on larger screens.

plurals
  1. POFixture generator in PHP or MySQL
    primarykey
    data
    text
    <p>I am trying to generate fixtures for a sports website. I have a table called Members, with relevant columns being member_id and league_id. The league_id will be passed from a form on the previous page as the variable $leagueid.</p> <p>I'm pulling out all the member ID's relating to that league ID using...</p> <pre><code>$result = mysql_query("SELECT member_id FROM Members WHERE league_id = '$leagueid'") </code></pre> <p>I now need to generate fixtures for all these member ID's and then insert that data into the MySQL table 'Fixtures'. Each row of data in that table needs to include:-</p> <p>player1 - member_id of the first player<br> player2 - member_id of the second player<br> week - integer showing which week the match will be played<br> league_id</p> <p>However, there are some special conditions that also need to be applied.</p> <ol> <li><p>Every 3rd week needs to remain free (i.e. weeks 3,6,9,12 etc). No matches can be scheduled on these weeks</p></li> <li><p>There needs to be an option (which will be selected and passed from a form on the previous page as a checkbox variable called $double) which will double up the matches. This means that after generating one complete round of fixtures, you need to take the generated list, swap ID's for players 1 and 2, and duplicate them all. So 1 round of fixtures could look like this....</p></li> </ol> <p>Week 1</p> <p>1 vs 2<br> 3 vs 4</p> <p>Week 2</p> <p>1 vs 3<br> 2 vs 4</p> <p>Week 3</p> <p>1 vs 4<br> 2 vs 3</p> <p>Then you would swap the ID's and add on another set...</p> <p>Week 4</p> <p>2 vs 1<br> 4 vs 3</p> <p>Week 5</p> <p>3 vs 1<br> 4 vs 2</p> <p>Week 6</p> <p>4 vs 1<br> 3 vs 2</p> <p>What I'm looking for is some code that will generate all these fixtures while keeping in mind all the special conditions that I've listed.</p> <p>I know this is all possible in PHP but I also think I can do it using one SQL query instead, which might be a lot cleaner. Can anyone help me out?? Thanks!!</p> <p>P.S. I know I'm using mysql and not mysqli. I am currently trying to transfer over to mysqli but I'm having some problems which I have posted on a separate question that I have yet to get a correct answer to.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload