tarmer Posted September 23, 2014 Share Posted September 23, 2014 Hello, I hope you guys can help me out (at least point me in the write direction) - I am very green and am trying to work my way thru this as best I can - I am not a programmer, But am trying to learn a few things to make this task easierI run an fantasy soccer site - And right now all the stats are stored in excel files (manually updated) and then exported to csv files - I have a php file that turns them into a table and shows the results..http://tonyarmer.net/WSL/LIGA/Valencia.php (as you see it outputs the page with the csv information. Now this is all fine (but a lot of work) as every week the numbers change and they have to be added in the excel file and updated and re-exported - My question is in 2 parts... First part - The rows that show up in the link above are constant and unchanging - the numbers in those rows will update and change all the time, as a game is played the associated numbers will have to be added to to update the player statistics. I have thought about putting all this in mySQL and updating it that way and trying to pull from the database - I see what I could use as the tables (from what is listed in the csv file) but not sure the direction to take there (any thoughts)Second Part (I have posted the code below) - This is a very poorly written piece of code but it does work - What I am trying to figure out is, How can I re-write (or add) to the code to make the player name as a clickable link that will take you to another page that shows more detail, City of birth, height, weight and I would move the stats to this page as well - Now I know doing this in mySQL would help (If I had any idea of what to do, which would include adding the weekly stats together to get totals).... But how could this be handled in just php with a csv file - ANY HELP would be greatly appreciated <body> <body style="background-color: transparent;"> <table border="0" width="100%" cellspacing="1" cellpadding="2" bgcolor=" 1F4B6B" > <tr>'; echo '<tr>'; // put exploded first line in as <th> element for ($j = 0; $j <= $columns; $j++) { $data[$j] = str_replace('"','',$data[$j]); echo '<th>' . $data[$j] . '</th>'; } // end first table row echo '</tr>'; $win = 0; // run through remaining lines for ($i = 1; $i <= sizeof($lines)-1; $i++) { // explode line $data = explode(",", $lines[$i]); // start new row echo '<tr class="' . $bg[$win] . '">'; // put exploded data in as <td> element for ($j = 0; $j <= $columns; $j++) { $data[$j] = str_replace('"','',$data[$j]); if ($j == 0) echo '<td><img src="' . $flag_dir . $countries[$data[$j]] . '.jpg" alt="' . $data[$j] . '" /></td>'; else echo '<td>' . $data[$j] . '</td>'; } // end row echo '</tr>'; $win == 1 ? $win = 0 : $win = 1; } // close table tag echo '</table>'; ?> <hr> <H2>CUPS</H2> <img src='http://www.tonyarmer.net/WSL/LIGA/55.png' /></a> Champions Cup x0 <img src='http://www.tonyarmer.net/WSL/LIGA/1.png' /></a>WSL Cup x0 <img src='http://www.tonyarmer.net/WSL/LIGA/cltrophy.png' /></a>Liga Cup x0 <hr> Quote Link to comment Share on other sites More sharing options...
Ch0cu3r Posted September 23, 2014 Share Posted September 23, 2014 Second Part (I have posted the code below) ... But how could this be handled in just php with a csv file - ANY HELP would be greatly appreciated You'd modify the code in the for loop here to make the players name a link // put exploded data in as <td> element for ($j = 0; $j <= $columns; $j++) { $data[$j] = str_replace('"','',$data[$j]); if ($j == 0) echo '<td><img src="' . $flag_dir . $countries[$data[$j]] . '.jpg" alt="' . $data[$j] . '" /></td>'; else echo '<td>' . $data[$j] . '</td>'; } Basically When $j is equal to 1 then $data[$j] will contain the players name. You'd wrap that variable in a anchor tag to make it a link. Example ... // players country flag if ($j == 0) { echo '<td><img src="' . $flag_dir . $countries[$data[$j]] . '.jpg" alt="' . $data[$j] . '" /></td>'; } // the players name column - output it as a link elseif($j == 1) { echo '<td><a href="player_details.php?player=' . urlencode($data[$j) . '" alt="View ' . htmlentities($data[$j]) . ' Info">' . htmlentities($data[$j]) . '</a></td>'; } else echo '<td>' . $data[$j] . '</td>'; ... In player_details.php you'd use $player = urldecode($_GET['player']); to get the players name. But where are the players details kept? Or have you not implemented that yet? Quote Link to comment Share on other sites More sharing options...
tarmer Posted September 23, 2014 Author Share Posted September 23, 2014 Thank You for the update and direction - It is much appreciated - the players details would probably be kept in a seperate php or html file (it has not been implemented as it is a "new" thought on this Quote Link to comment Share on other sites More sharing options...
tarmer Posted September 23, 2014 Author Share Posted September 23, 2014 (edited) You'd modify the code in the for loop here to make the players name a link // put exploded data in as <td> element for ($j = 0; $j <= $columns; $j++) { $data[$j] = str_replace('"','',$data[$j]); if ($j == 0) echo '<td><img src="' . $flag_dir . $countries[$data[$j]] . '.jpg" alt="' . $data[$j] . '" /></td>'; else echo '<td>' . $data[$j] . '</td>'; } Basically When $j is equal to 1 then $data[$j] will contain the players name. You'd wrap that variable in a anchor tag to make it a link. Example ... // players country flag if ($j == 0) { echo '<td><img src="' . $flag_dir . $countries[$data[$j]] . '.jpg" alt="' . $data[$j] . '" /></td>'; } // the players name column - output it as a link elseif($j == 1) { echo '<td><a href="player_details.php?player=' . urlencode($data[$j) . '" alt="View ' . htmlentities($data[$j]) . ' Info">' . htmlentities($data[$j]) . '</a></td>'; } else echo '<td>' . $data[$j] . '</td>'; ... In player_details.php you'd use $player = urldecode($_GET['player']); to get the players name. But where are the players details kept? Or have you not implemented that yet? Where exactly would this go - I tried changing this : // start new row echo '<tr class="' . $bg[$win] . '">'; // put exploded data in as <td> element for ($j = 0; $j <= $columns; $j++) { $data[$j] = str_replace('"','',$data[$j]); if ($j == 0) echo '<td><img src="' . $flag_dir . $countries[$data[$j]] . '.jpg" alt="' . $data[$j] . '" /></td>'; else echo '<td>' . $data[$j] . '</td>'; } to this // start new row echo '<tr class="' . $bg[$win] . '">'; // put exploded data in as <td> element for ($j = 0; $j <= $columns; $j++) { $data[$j] = str_replace('"','',$data[$j]); // players country flag if ($j == 0) { echo '<td><img src="' . $flag_dir . $countries[$data[$j]] . '.jpg" alt="' . $data[$j] . '" /></td>'; } // the players name column - output it as a link elseif($j == 1) { echo '<td><a href="player_details.php?player=' . urlencode($data[$j) . '" alt="View ' . htmlentities($data[$j]) . ' Info">' . htmlentities($data[$j]) . '</a></td>'; } else echo '<td>' . $data[$j] . '</td>'; But it was giving me a 500 Internal Server Error - Any thoughts ? - Is it because it was looking for the "echo '<td><a href="player_details.php?player='" that has not been created yet ? Not the problem - as I tried it without this href Thanks again for all Edited September 23, 2014 by tarmer Quote Link to comment Share on other sites More sharing options...
CroNiX Posted September 23, 2014 Share Posted September 23, 2014 Did you check the server logs? I see a syntax error where you are creating the links (missing closing ]): urlencode($data[$j) Quote Link to comment Share on other sites More sharing options...
tarmer Posted September 23, 2014 Author Share Posted September 23, 2014 No.. I did not - Thank you for pointing that out - I really appreciate all the help here Quote Link to comment Share on other sites More sharing options...
tarmer Posted September 23, 2014 Author Share Posted September 23, 2014 Any idea where i can find this information - I fixed the above error and it still gives me a 500 error Quote Link to comment Share on other sites More sharing options...
tarmer Posted September 23, 2014 Author Share Posted September 23, 2014 figured it out - was missing closing } - But now does not read the entire file Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.