First off let me start by stating I am a complete newbie so I appreciate the help anyone can give me (as well as advice)

I am toying with a fantasy soccer site (just for a bunch of friends) and I am trying to set up some dynamic pages to help make this a little more interactive. In the past I have been able to put information into excel and read it in PHP to create a html table - This is fine and it works but I am thinking of possibly changing the game sim engine and thus the output information

The output file is a text file non-deliminated it will always be the same as far as the colums included (http://www.wiwag.hostei.com/s1.php)<----- an example - The thing that will change will be the numbers in the columns

I can get this read into a nice clean formatted table easily enough with some flags and such (http://www.wiwag.hostei.com/ss1.php)

What I am trying to figure out what to do is to make the roster page (as seen above)and make each player name be a clickable link that will take you to a player profile page that takes all of the table information for each player and re displays the information in a formatted way of just the selected player (http://www.oflm.co.uk/teams/viewPlayer.php?id=1) similar to this idea

As of now the information that is generated by the game is all text based there are no associated databases everything is text based so the game sims the matches and outputs text of updated rosters and such.....

Any ideas on how to go about this would be greatly appreciated.... And if it is easier to use MySQL to perform some of this I have it on my machine locally as well as on a host - but would need to know what commands to give to extract correct information

Thsnk you all in advance

Recommended Answers

All 6 Replies

Hello, you told that you could use an advice too. What you are describing is a database issue. Of course you could use a csv as a database / table file … but this will make your life difficult. There aren’t “magic” commands in SQL (MySQL) that we could share with you and solve any problem you might face. Take a day or two and try some basic SQL … just search “PHP tutorial Mysql”… and you will get some very basic tutorials. Hoped I helped…

Member Avatar for iamthwee

^Echo the above.

Or if that's a steep learning curve perhaps an xml file.

The point is, all you're doing is having a link in each line of the table.

When you click on that link it opens another page with the relevant information on it.

Thank you for the replies.. I am not looking for the coding just help in the direction to go to get the information... It seems it is an MySQL issue - But the question I still have is where do I find linking for each table line ?

Well for starters, your file is technically delimited by the space character. Since your rows are not identified with a unique id, I will assume that the user name is a unique field and thus could be used as your key.

When you build you table, link the usernames to an additional page in the sense of profile.php?user=S_Una

On the profile page, you will need to read through the entire file looking for a line whose first column contains a matching username. This is where flat file databases become slow. The bigger the file the more comparisons that need to occur. If your file is going to remain small then leaving it as you have it is probably sufficient. However, writing data to it via PHP will be more difficult.

//Open the file as an SplFileObject
//This does not read the entire file into memory so it is very efficient
//However you must iterate line by line
$file = new SplFileObject('yourfile.ext');

//Set the file object to be read as a CSV file
//Doesn't matter the file is not comma delimited we will set the delimiter to a space charachter
$file->setFlags(SplFileObject::READ_CSV);

//Change the delimiter
$file->setCsvControl(' ');

//Get the username passed from the url string
$user = $_GET['user'];

//Start iterating over the file line by line
foreach( $file as $line ){
  //OPTIONAL - Change the keys to lowercase so they are identical
  if ( strtolower($user) == strtolower($line[0]) ){
    //If we fine the matching line, set it to $row variable
    //Break out of the loop since we are done.
    $row = $line;
    break;
  }
}

//Display all of the user's data
print_r($row);

This is untested but should give you a quick overview of how it would work.

Ok.. I appreciate the help again.. So let me just ask a couple of questions then to help me clarify and as noted I have no problem reading it if someone can point me to it..

It sounds like I want to do this in a database, No prob can do that - I guess the questions I have are:

1 Since this is a "dynamic" league (information updated after each sim) how do I update the table information each week (do I use mysql update or import to overwrite the existing data,,

2. And than I output to a php file which reads the tables and prints the html (in concept)

What I am still not getting with the code example is how to create the links and the table relationship....

I could manually possibly add a "id" field but for the meantime I would go with what is generated as the game would always update the information the same way...

So I create a web page lets say viewSquad.php?abbr=anf <---- which will give me the team overview. I than create a new page called lets say viewPlayer.php?id=143 <----- can be number or name - I would just need to figure out how to make the relationship between the 2 pages ?

From my view you just need to change in ss1.php.
I assume that there is a primary key in the database table such as id. If not create it.
The code will be in this form

for($i=0;$i<//number of records//;$i++)
{
echo "<a href=viewplayer.php?id=$res['id']>player name</a>
}

By now you have got the idea.
You need to fetch the result from the query.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.