Jump to content

PHP Array / Graphics


tarmer

Recommended Posts

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 easier

I 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>
Link to comment
Share on other sites

 

 

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?

Link to comment
Share on other sites

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 by tarmer
Link to comment
Share on other sites

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.