Jump to content

Pulling information from a file


afoster

Recommended Posts

I am trying to pull information from a file as noted on the code posted below. What I want to do is convert the team number to a team name but I keep getting an error msg.  I am just starting to learn php and I keep getting an error msg when I try to run the script.  any assistance would be much appreciated.  Here is the code I am working with:

 

<?php

// Change this file to match your tournament picks file

$file = "playerpicks08_newer.ttw";

echo "<body bgcolor=#e3e3e3>";

echo "<center>";

echo "<font size=4 color=#ff0000 face=tahoma><b>Tournament Tracker 2008  " ;

echo "<br>";

if (file_exists($file)) {

  $data = file_get_contents($file);

  $num =

    preg_match_all("/PLAYERID=(.*),PLAYERINFO1=(.*),PLAYERINFO2=(.*),PLAYERINFO3=(.*),PLAYERINFO4=(.*),PLAYERINFO5=(.*),G1=.*,G63=(.*),TIEBREAKER=(.*),PLAYERCOMMENT=(.*),SUBMITTED=(.*),/i", $data, $matches);

  echo "<font size=2 color=#000000>Total Number of Submitted Player Picks: ";

  echo $num, "<br>";

  echo "<div align=center>";

  echo "<center>";

  echo "<table border=1 cellpadding=2 cellspacing=1 bgcolor=#ffffff>";

  echo "<tr>";

  echo "<td align=center><b>Player</b></td>";

//  echo "<td align=center><b>PLAYERINFO1</b></td>";

//  echo "<td align=center><b>PLAYERINFO2</b></td>";

  echo "<td align=center><b>Email</b></td>";

//  echo "<td align=center><b>PLAYERINFO4</b></td>";

//  echo "<td align=center><b>PLAYERINFO5</b></td>";

    echo "<td align=center><b>Champion</b>";

  echo "<td align=center><b>Tiebreaker</b>";

//  echo "<td align=center><b>PLAYERCOMMENT</b></td>";

  echo "<td align=center><b>  Submitted  </b></td>";

  echo "</tr>";

 

      echo "<tr>";

      echo "<td align=center>" . $matches[1][$i] . "</td>";

//      echo "<td align=center>" . $matches[2][$i] . "</td>";

//      echo "<td align=center>" . $matches[3][$i] . "</td>";

      echo "<td align=center>" . $matches[4][$i] . "</td>";

//      echo "<td align=center>" . $matches[5][$i] . "</td>";

//      echo "<td align=center>" . $matches[6][$i] . "</td>";

$teamname = "";

        for ($i=0; $i<$num; $i++) {

          for ($x=0; $x<$num; $x++) {

    $teamnumber = $matches[7][$x];

    switch val($teamnumber);

        case 0;

            $teamname = "N Carolina";

            break;

        case 16;

            $teamname = "Kansas";

        echo "<td align=center>" . $teamname .  "</td>";

     

          echo "<td align=center>" . $matches[8][$i] . "</td>";

//      echo "<td align=center>" . $matches[9][$i] . "</td>";

      echo "<td align=center>" . $matches[10][$i] . "</td>";

   

      echo "</tr>";

  }

  echo "</table>";

  echo "</center>";

  echo "</div>";

}else{

  echo "<h3><font size=6>There are no entries at this time : (</h3></center>";

}

?>

 

Here is the error msg:  Parse error: syntax error, unexpected T_FOR in /home/fredsfol/public_html/data/subpicksrev_2008.php on line 38

Link to comment
Share on other sites

not exactly sure if this is going to help or not, however I did notice something skimming through real quick..

right around

if (file_exists($file)) {

about 2 lines down from it you have $num = but no quotes, and no deffinition to it and no ;.. later on down in line 38 or there about it calls for $num

 

this may or may not help in the over all, but atleast its worth mentioning :)

Link to comment
Share on other sites

not exactly sure if this is going to help or not, however I did notice something skimming through real quick..

right around

if (file_exists($file)) {

about 2 lines down from it you have $num = but no quotes, and no deffinition to it and no ;.. later on down in line 38 or there about it calls for $num

 

this may or may not help in the over all, but atleast its worth mentioning :)

 

Thanks for the quick response. I should have stated in my original post, that the code as is was pulling the information requested prior to trying to convert the team number to team name, so I don't believe that the $num without quotes is the problem here. What that does is state that there are x number of players that have submitted.

Link to comment
Share on other sites

Please wrap your code in


tags and distinguish which line is 38.

 

My Apologies, first time posting and unfamiliar with protocol.

 

<?php
// Change this file to match your tournament picks file
$file = "playerpicks08_newer.ttw";
echo "<body bgcolor=#e3e3e3>";
echo "<center>";
echo "<font size=4 color=#ff0000 face=tahoma>Tournament Tracker 2008  " ;
echo "
";
if (file_exists($file)) {
   $data = file_get_contents($file);
   $num =
    preg_match_all("/PLAYERID=(.*),PLAYERINFO1=(.*),PLAYERINFO2=(.*),PLAYERINFO3=(.*),PLAYERINFO4=(.*),PLAYERINFO5=(.*),G1=.*,G63=(.*),TIEBREAKER=(.*),PLAYERCOMMENT=(.*),SUBMITTED=(.*),/i", $data, $matches);
   echo "<font size=2 color=#000000>Total Number of Submitted Player Picks: ";
   echo $num, "
";
   echo "<div align=center>";
   echo "<center>";
   echo "<table border=1 cellpadding=2 cellspacing=1 bgcolor=#ffffff>";
   echo "<tr>";
   echo "<td align=center>Player</td>";
//   echo "<td align=center>PLAYERINFO1</td>";
//   echo "<td align=center>PLAYERINFO2</td>";
   echo "<td align=center>Email</td>";
//   echo "<td align=center>PLAYERINFO4</td>";
//   echo "<td align=center>PLAYERINFO5</td>";
    echo "<td align=center>Champion";
   echo "<td align=center>Tiebreaker";
//   echo "<td align=center>PLAYERCOMMENT</td>";
   echo "<td align=center>  Submitted  </td>";
  echo "</tr>";

      echo "<tr>";
      echo "<td align=center>" . $matches[1][$i] . "</td>";
//      echo "<td align=center>" . $matches[2][$i] . "</td>";
//      echo "<td align=center>" . $matches[3][$i] . "</td>";
      echo "<td align=center>" . $matches[4][$i] . "</td>";
//      echo "<td align=center>" . $matches[5][$i] . "</td>";
//      echo "<td align=center>" . $matches[6][$i] . "</td>";
$teamname = "";
        for ($i=0; $i<$num; $i++) {
          for ($x=0; $x<$num; $x++) {
    $teamnumber = $matches[7][$x];
    switch val($teamnumber);
        case 0;
            $teamname = "N Carolina";
            break;
        case 16;
            $teamname = "Kansas";
        echo "<td align=center>" . $teamname .  "</td>";
       
          echo "<td align=center>" . $matches[8][$i] . "</td>";
//      echo "<td align=center>" . $matches[9][$i] . "</td>";
      echo "<td align=center>" . $matches[10][$i] . "</td>";
     
      echo "</tr>";
   }
   echo "</table>";
   echo "</center>";
   echo "</div>";
}else{
   echo "<h3><font size=6>There are no entries at this time : (</h3></center>";
}
?>

 

Line 38 is as follows:  switch val($teamnumber);

Link to comment
Share on other sites

Is val a function you wrote? Either way, your switch syntax is wrong, and once fixed you will have lot's of unmatched braces. Here it is fixed (i think):

 

<?php
// Change this file to match your tournament picks file
$file = "playerpicks08_newer.ttw";
echo "<body bgcolor=#e3e3e3>";
echo "<center>";
echo "<font size=4 color=#ff0000 face=tahoma>Tournament Tracker 2008  " ;
echo "
";
if (file_exists($file)) {
   $data = file_get_contents($file);
   $num =
    preg_match_all("/PLAYERID=(.*),PLAYERINFO1=(.*),PLAYERINFO2=(.*),PLAYERINFO3=(.*),PLAYERINFO4=(.*),PLAYERINFO5=(.*),G1=.*,G63=(.*),TIEBREAKER=(.*),PLAYERCOMMENT=(.*),SUBMITTED=(.*),/i", $data, $matches);
   echo "<font size=2 color=#000000>Total Number of Submitted Player Picks: ";
   echo $num, "
";
   echo "<div align=center>";
   echo "<center>";
   echo "<table border=1 cellpadding=2 cellspacing=1 bgcolor=#ffffff>";
   echo "<tr>";
   echo "<td align=center>Player</td>";
//   echo "<td align=center>PLAYERINFO1</td>";
//   echo "<td align=center>PLAYERINFO2</td>";
   echo "<td align=center>Email</td>";
//   echo "<td align=center>PLAYERINFO4</td>";
//   echo "<td align=center>PLAYERINFO5</td>";
    echo "<td align=center>Champion";
   echo "<td align=center>Tiebreaker";
//   echo "<td align=center>PLAYERCOMMENT</td>";
   echo "<td align=center>  Submitted  </td>";
  echo "</tr>";

      echo "<tr>";
      echo "<td align=center>" . $matches[1][$i] . "</td>";
//      echo "<td align=center>" . $matches[2][$i] . "</td>";
//      echo "<td align=center>" . $matches[3][$i] . "</td>";
      echo "<td align=center>" . $matches[4][$i] . "</td>";
//      echo "<td align=center>" . $matches[5][$i] . "</td>";
//      echo "<td align=center>" . $matches[6][$i] . "</td>";
$teamname = "";
        for ($i=0; $i<$num; $i++) {
          for ($x=0; $x<$num; $x++) {
    $teamnumber = $matches[7][$x];
    switch(val($teamnumber)){
        case 0;
            $teamname = "N Carolina";
            break;
        case 16;
            $teamname = "Kansas";
    }
        echo "<td align=center>" . $teamname .  "</td>";
        }
       
          echo "<td align=center>" . $matches[8][$i] . "</td>";
//      echo "<td align=center>" . $matches[9][$i] . "</td>";
      echo "<td align=center>" . $matches[10][$i] . "</td>";
}    
      echo "</tr>";
   }
   echo "</table>";
   echo "</center>";
   echo "</div>";
}else{
   echo "<h3><font size=6>There are no entries at this time : (</h3></center>";
}
?>

 

 

Link to comment
Share on other sites

Is val a function you wrote? Either way, your switch syntax is wrong, and once fixed you will have lot's of unmatched braces. Here it is fixed (i think):

 

<?php
// Change this file to match your tournament picks file
$file = "playerpicks08_newer.ttw";
echo "<body bgcolor=#e3e3e3>";
echo "<center>";
echo "<font size=4 color=#ff0000 face=tahoma>Tournament Tracker 2008  " ;
echo "
";
if (file_exists($file)) {
   $data = file_get_contents($file);
   $num =
    preg_match_all("/PLAYERID=(.*),PLAYERINFO1=(.*),PLAYERINFO2=(.*),PLAYERINFO3=(.*),PLAYERINFO4=(.*),PLAYERINFO5=(.*),G1=.*,G63=(.*),TIEBREAKER=(.*),PLAYERCOMMENT=(.*),SUBMITTED=(.*),/i", $data, $matches);
   echo "<font size=2 color=#000000>Total Number of Submitted Player Picks: ";
   echo $num, "
";
   echo "<div align=center>";
   echo "<center>";
   echo "<table border=1 cellpadding=2 cellspacing=1 bgcolor=#ffffff>";
   echo "<tr>";
   echo "<td align=center>Player</td>";
//   echo "<td align=center>PLAYERINFO1</td>";
//   echo "<td align=center>PLAYERINFO2</td>";
   echo "<td align=center>Email</td>";
//   echo "<td align=center>PLAYERINFO4</td>";
//   echo "<td align=center>PLAYERINFO5</td>";
    echo "<td align=center>Champion";
   echo "<td align=center>Tiebreaker";
//   echo "<td align=center>PLAYERCOMMENT</td>";
   echo "<td align=center>  Submitted  </td>";
  echo "</tr>";

      echo "<tr>";
      echo "<td align=center>" . $matches[1][$i] . "</td>";
//      echo "<td align=center>" . $matches[2][$i] . "</td>";
//      echo "<td align=center>" . $matches[3][$i] . "</td>";
      echo "<td align=center>" . $matches[4][$i] . "</td>";
//      echo "<td align=center>" . $matches[5][$i] . "</td>";
//      echo "<td align=center>" . $matches[6][$i] . "</td>";
$teamname = "";
        for ($i=0; $i<$num; $i++) {
          for ($x=0; $x<$num; $x++) {
    $teamnumber = $matches[7][$x];
    switch(val($teamnumber)){
        case 0;
            $teamname = "N Carolina";
            break;
        case 16;
            $teamname = "Kansas";
    }
        echo "<td align=center>" . $teamname .  "</td>";
        }
       
          echo "<td align=center>" . $matches[8][$i] . "</td>";
//      echo "<td align=center>" . $matches[9][$i] . "</td>";
      echo "<td align=center>" . $matches[10][$i] . "</td>";
}    
      echo "</tr>";
   }
   echo "</table>";
   echo "</center>";
   echo "</div>";
}else{
   echo "<h3><font size=6>There are no entries at this time : (</h3></center>";
}
?>

 

 

 

When trying to run the modified script, I get the following error msg:  Parse error: syntax error, unexpected '}' in /home/fredsfol/public_html/data/picks_submitted.php on line 62

 

Line 62 is:  }else{

Link to comment
Share on other sites

sorry...one too many in there:

 

<?php
// Change this file to match your tournament picks file
$file = "playerpicks08_newer.ttw";
echo "<body bgcolor=#e3e3e3>";
echo "<center>";
echo "<font size=4 color=#ff0000 face=tahoma>Tournament Tracker 2008  " ;
echo "
";
if (file_exists($file)) {
   $data = file_get_contents($file);
   $num =
    preg_match_all("/PLAYERID=(.*),PLAYERINFO1=(.*),PLAYERINFO2=(.*),PLAYERINFO3=(.*),PLAYERINFO4=(.*),PLAYERINFO5=(.*),G1=.*,G63=(.*),TIEBREAKER=(.*),PLAYERCOMMENT=(.*),SUBMITTED=(.*),/i", $data, $matches);
   echo "<font size=2 color=#000000>Total Number of Submitted Player Picks: ";
   echo $num, "
";
   echo "<div align=center>";
   echo "<center>";
   echo "<table border=1 cellpadding=2 cellspacing=1 bgcolor=#ffffff>";
   echo "<tr>";
   echo "<td align=center>Player</td>";
//   echo "<td align=center>PLAYERINFO1</td>";
//   echo "<td align=center>PLAYERINFO2</td>";
   echo "<td align=center>Email</td>";
//   echo "<td align=center>PLAYERINFO4</td>";
//   echo "<td align=center>PLAYERINFO5</td>";
    echo "<td align=center>Champion";
   echo "<td align=center>Tiebreaker";
//   echo "<td align=center>PLAYERCOMMENT</td>";
   echo "<td align=center>  Submitted  </td>";
  echo "</tr>";

      echo "<tr>";
      echo "<td align=center>" . $matches[1][$i] . "</td>";
//      echo "<td align=center>" . $matches[2][$i] . "</td>";
//      echo "<td align=center>" . $matches[3][$i] . "</td>";
      echo "<td align=center>" . $matches[4][$i] . "</td>";
//      echo "<td align=center>" . $matches[5][$i] . "</td>";
//      echo "<td align=center>" . $matches[6][$i] . "</td>";
$teamname = "";
        for ($i=0; $i<$num; $i++) {
          for ($x=0; $x<$num; $x++) {
    $teamnumber = $matches[7][$x];
    switch(val($teamnumber)){
        case 0;
            $teamname = "N Carolina";
            break;
        case 16;
            $teamname = "Kansas";
    }
        echo "<td align=center>" . $teamname .  "</td>";
        }
       
          echo "<td align=center>" . $matches[8][$i] . "</td>";
//      echo "<td align=center>" . $matches[9][$i] . "</td>";
      echo "<td align=center>" . $matches[10][$i] . "</td>";
      echo "</tr>";
   }
   echo "</table>";
   echo "</center>";
   echo "</div>";
}else{
   echo "<h3><font size=6>There are no entries at this time : (</h3></center>";
}
?>

 

again, should get rid of the errors, but you may need to play with it a little to make it output what you want

Link to comment
Share on other sites

sorry...one too many in there:

 

<?php
// Change this file to match your tournament picks file
$file = "playerpicks08_newer.ttw";
echo "<body bgcolor=#e3e3e3>";
echo "<center>";
echo "<font size=4 color=#ff0000 face=tahoma>Tournament Tracker 2008  " ;
echo "
";
if (file_exists($file)) {
   $data = file_get_contents($file);
   $num =
    preg_match_all("/PLAYERID=(.*),PLAYERINFO1=(.*),PLAYERINFO2=(.*),PLAYERINFO3=(.*),PLAYERINFO4=(.*),PLAYERINFO5=(.*),G1=.*,G63=(.*),TIEBREAKER=(.*),PLAYERCOMMENT=(.*),SUBMITTED=(.*),/i", $data, $matches);
   echo "<font size=2 color=#000000>Total Number of Submitted Player Picks: ";
   echo $num, "
";
   echo "<div align=center>";
   echo "<center>";
   echo "<table border=1 cellpadding=2 cellspacing=1 bgcolor=#ffffff>";
   echo "<tr>";
   echo "<td align=center>Player</td>";
//   echo "<td align=center>PLAYERINFO1</td>";
//   echo "<td align=center>PLAYERINFO2</td>";
   echo "<td align=center>Email</td>";
//   echo "<td align=center>PLAYERINFO4</td>";
//   echo "<td align=center>PLAYERINFO5</td>";
    echo "<td align=center>Champion";
   echo "<td align=center>Tiebreaker";
//   echo "<td align=center>PLAYERCOMMENT</td>";
   echo "<td align=center>  Submitted  </td>";
  echo "</tr>";

      echo "<tr>";
      echo "<td align=center>" . $matches[1][$i] . "</td>";
//      echo "<td align=center>" . $matches[2][$i] . "</td>";
//      echo "<td align=center>" . $matches[3][$i] . "</td>";
      echo "<td align=center>" . $matches[4][$i] . "</td>";
//      echo "<td align=center>" . $matches[5][$i] . "</td>";
//      echo "<td align=center>" . $matches[6][$i] . "</td>";
$teamname = "";
        for ($i=0; $i<$num; $i++) {
          for ($x=0; $x<$num; $x++) {
    $teamnumber = $matches[7][$x];
    switch(val($teamnumber)){
        case 0;
            $teamname = "N Carolina";
            break;
        case 16;
            $teamname = "Kansas";
    }
        echo "<td align=center>" . $teamname .  "</td>";
        }
       
          echo "<td align=center>" . $matches[8][$i] . "</td>";
//      echo "<td align=center>" . $matches[9][$i] . "</td>";
      echo "<td align=center>" . $matches[10][$i] . "</td>";
      echo "</tr>";
   }
   echo "</table>";
   echo "</center>";
   echo "</div>";
}else{
   echo "<h3><font size=6>There are no entries at this time : (</h3></center>";
}
?>

 

again, should get rid of the errors, but you may need to play with it a little to make it output what you want

 

I think it's getting close. The error msg is now:  Fatal error: Call to undefined function: val() in /home/fredsfol/public_html/data/picks_submitted.php on line 43

 

Here is line 43:  switch(val($teamnumber)){

Link to comment
Share on other sites

Yeah, I asked about that one earlier. I assume it's just a type, replace that line with this:

switch($teamnumber){

 

I actually tried that before my last post, and what I got was the team name all across the page, with the tiebreaker and date of submission. No player name or email was displayed.  If I could attach a screen dump, I would but evidently it has not been enabled?

Link to comment
Share on other sites

sounds like it's working, i just didn't know how the ECHOs should be ordered/which loops to have them in...try this on for size:

 

<?php
// Change this file to match your tournament picks file
$file = "playerpicks08_newer.ttw";
echo "<body bgcolor=#e3e3e3>";
echo "<center>";
echo "<font size=4 color=#ff0000 face=tahoma>Tournament Tracker 2008</font>\n";
if (file_exists($file)) {
  $data = file_get_contents($file);
  $num = preg_match_all("/PLAYERID=(.*),PLAYERINFO1=(.*),PLAYERINFO2=(.*),PLAYERINFO3=(.*),PLAYERINFO4=(.*),PLAYERINFO5=(.*),G1=.*,G63=(.*),TIEBREAKER=(.*),PLAYERCOMMENT=(.*),SUBMITTED=(.*),/i", $data, $matches);
  echo "<font size=2 color=#000000>Total Number of Submitted Player Picks: {$num}\n";
  echo "<div align=center>";
  echo "<center>";
  echo "<table border=1 cellpadding=2 cellspacing=1 bgcolor=#ffffff>";
  echo "<tr>";
  echo "<td align=center>Player</td>";
//  echo "<td align=center>PLAYERINFO1</td>";
//  echo "<td align=center>PLAYERINFO2</td>";
  echo "<td align=center>Email</td>";
//  echo "<td align=center>PLAYERINFO4</td>";
//  echo "<td align=center>PLAYERINFO5</td>";
  echo "<td align=center>Champion";
  echo "<td align=center>Tiebreaker";
//  echo "<td align=center>PLAYERCOMMENT</td>";
  echo "<td align=center>  Submitted  </td>";
  echo "</tr>";

  for ($i=0; $i<$num; $i++) {
    echo "<tr>";
    echo "<td align=center>" . $matches[1][$i] . "</td>";
//    echo "<td align=center>" . $matches[2][$i] . "</td>";
//    echo "<td align=center>" . $matches[3][$i] . "</td>";
    echo "<td align=center>" . $matches[4][$i] . "</td>";
//    echo "<td align=center>" . $matches[5][$i] . "</td>";
//    echo "<td align=center>" . $matches[6][$i] . "</td>";
    echo "<td align=center>";
    switch($matches[7][$i]){
      case 0:  echo "N Carolina"; break;
      case 16: echo "Kansas"; break;
      default: echo "[unknown Name]";
    }
    echo "</td>";
    echo "<td align=center>" . $matches[8][$i] . "</td>";
//    echo "<td align=center>" . $matches[9][$i] . "</td>";
    echo "<td align=center>" . $matches[10][$i] . "</td>";
    echo "</tr>";
  }
  echo "</table>";
  echo "</center>";
  echo "</div>";
}else{
   echo "<h3><font size=6>There are no entries at this time : (</h3></center>";
}
?>

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.