We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 8439
    • 89 Posts
    Hi,

    I’ve been asked to see if MODx can satisfy these needs ...

    A local football team (soccer for the Americans among you) wants a cheap website with a league table on the home page. What’s the simplest way to do this?

    Obviously just filling in a table by hand but that is clunky (12 or so rows, 4 columns).

    I had thought of keeping the table in Excel and cutting and pasting a block of cells but in FCKedit that pastes everything into a single cell. This approach would be satisfactory if we could get it to work, tinymce?.

    Clearly keeping the data in a database and providing an edit screen would do the job but how much effort would that involve?

    Hints, tips,TFMs to R, sample code ... all welcomed.

    Ed
      • 12844
      • 59 Posts
      Just thinking aloud here...

      Would it be desirable to have two fields for each team in a form (goals For and Against) which would be submitted after every weeks action? I’m sure it wouldn’t be too hard to implement a system which takes those figures and adds them to their respective table entries in a database. Then the league table itself could be formed with some code which would look at all those results and calculate the wins and points for each team.

      Sample database table structure:

      Table: (teamname)
      [table]
      [tr][td]GameID [/td][td]For [/td][td]Against [/td][/tr]
      [tr][td]1[/td][td]3[/td][td]1[/td][/tr]
      [tr][td]2[/td][td]1[/td][td]2[/td][/tr]
      [/table]

      Or would that be over-complicating things? As it’s supposed to be a cheap website, probably.

      So... keeping just the up-to-date league table data in the database would do the job.

      Sample database table structure:

      Table: (leaguetable)
      [table]
      [tr][td]TeamName [/td][td]For [/td][td]Against [/td][td]Points [/td][/tr]
      [tr][td]Arsenal[/td][td]7[/td][td]1[/td][td]6[/td][/tr]
      [tr][td]Chelsea[/td][td]4[/td][td]2[/td][td]6[/td][/tr]
      [/table]

      A simple form could be prefilled with this data, ready for editing each week (maybe with the use of up and down buttons for each value?). When it’s submitted the new values simply overwrite the old ones.

      This is pretty easy to do with basic PHP database functions, but I know the MODx API can do stuff with databases as well.

      (Waits for more posts by people who know what they’re on about.)
        • 727
        • 502 Posts
        If you want to keep it as simple as possible then I would do it like this:

        Create a template variable that is a text area called "table"
        Each time the data changes save it from Excel in CSV format and paste it into the template variable
        Write a snippet to process the CSV data and convert it into a pretty looking table

        Processing CSV data in PHP is very easy. You can use the explode function, for example:

        list($team, $matchesplayed, $for, $against, $goaldiff, $points) = explode(",", $line);
        


        Most of the effort with this approach would be to format the table so it looks pretty.

        I hope this helps.

        Andy
          • 28042 ☆ A M B ☆
          • 24,524 Posts
          Even better, you can use this:

          http://il.php.net/fgetcsv
            Studying MODX in the desert - http://sottwell.com
            Tips and Tricks from the MODX Forums and Slack Channels - http://modxcookbook.com
            Join the Slack Community - http://modx.org