Script posting info from txt file get undefined offset error

  • deanski
  • Born
  • Born
  • deanski
  • Posts: 4

Post 3+ Months Ago

Please keep in mind that I am a total novice when it comes to anything but basic html programming.
I apparently became the website admin for my company and need a little help with an "undefined offset" error Im getting on one of the pages.

The last admin had written a page that pulls info from a .txt file that is uploaded to an ftp site.
Each morning users in another department enter data in a very basic text format and use a batch file to upload the .txt

Here is what is written for the part that is working:

Code: [ Select ]
<?
//1024x768

//define the date in a nice presentable format for patrons
$date = date('l F j, Y');

function is_even($number) {
  return(!($number & 1)); // 0 = even, 1 = odd
}

// Get a file into an array.
$lines = file('data.txt');

//create holders for data once we cycle thru the logic
//$schedule = array();
$harness = array();
$thoroughbred = array();

// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
  //echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
    
    //1st lets split the data up a bit
    $l = explode("-",$line);
    $time = $l[0];
    $track = $l[1];

    $check = strstr($track,"(");
    if($check) {
        $track = substr($track, 0, -4);
        $harness[$track] = $time;
    }
    else
        $thoroughbred[$track] = $time;
    //$schedule[$time] = "$track";

}
?>

<html>
<head>
<title>Track Schedule - <? print $date; ?></title>
<meta http-equiv="refresh" content="900">

<link rel="stylesheet" type="text/css" media="screen,projection" href="style.css" />
<link rel="stylesheet" type="text/css" media="print" href="print.css" />

</head>
<body>

<?
print "<div id=\"date\">$date</div>";
?>

<div id="container">

<!--<div class="greeting">Welcome to ***** Raceway!</div>-->


<div id="tracks">

    <table class="harness" cellpadding="0" cellspacing="0">
        <tr>
            <td colspan="2" class="heading">Harness</td>
        </tr>
        <?
        $i = 0;
        foreach($harness as $k => $t) {
            print "<tr";
            if(is_even($i)) print " class=\"odd\"";
            else print " class=\"even\"";
            print "><td>$t</td><td>$k</td></tr>";
            $i++;
        }
        ?>
    </table>

    <table class="thoroughbred" cellpadding="0" cellspacing="0">
        <tr>
            <td colspan="2" class="heading">Thoroughbred</td>
        </tr>
        <?
        $i = 0;
        foreach($thoroughbred as $k => $t) {
            print "<tr";
            if(is_even($i)) print " class=\"odd\"";
            else print " class=\"even\"";
            print "><td>$t</td><td>$k</td></tr>";
            $i++;
        }
        ?>
    </table>

</div>

<!--
<div class="footer">
    Today’s Tracks – Harness &amp; Thoroughbred
</div>

-->

</div>

</body>
</html>
  1. <?
  2. //1024x768
  3. //define the date in a nice presentable format for patrons
  4. $date = date('l F j, Y');
  5. function is_even($number) {
  6.   return(!($number & 1)); // 0 = even, 1 = odd
  7. }
  8. // Get a file into an array.
  9. $lines = file('data.txt');
  10. //create holders for data once we cycle thru the logic
  11. //$schedule = array();
  12. $harness = array();
  13. $thoroughbred = array();
  14. // Loop through our array, show HTML source as HTML source; and line numbers too.
  15. foreach ($lines as $line_num => $line) {
  16.   //echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
  17.     
  18.     //1st lets split the data up a bit
  19.     $l = explode("-",$line);
  20.     $time = $l[0];
  21.     $track = $l[1];
  22.     $check = strstr($track,"(");
  23.     if($check) {
  24.         $track = substr($track, 0, -4);
  25.         $harness[$track] = $time;
  26.     }
  27.     else
  28.         $thoroughbred[$track] = $time;
  29.     //$schedule[$time] = "$track";
  30. }
  31. ?>
  32. <html>
  33. <head>
  34. <title>Track Schedule - <? print $date; ?></title>
  35. <meta http-equiv="refresh" content="900">
  36. <link rel="stylesheet" type="text/css" media="screen,projection" href="style.css" />
  37. <link rel="stylesheet" type="text/css" media="print" href="print.css" />
  38. </head>
  39. <body>
  40. <?
  41. print "<div id=\"date\">$date</div>";
  42. ?>
  43. <div id="container">
  44. <!--<div class="greeting">Welcome to ***** Raceway!</div>-->
  45. <div id="tracks">
  46.     <table class="harness" cellpadding="0" cellspacing="0">
  47.         <tr>
  48.             <td colspan="2" class="heading">Harness</td>
  49.         </tr>
  50.         <?
  51.         $i = 0;
  52.         foreach($harness as $k => $t) {
  53.             print "<tr";
  54.             if(is_even($i)) print " class=\"odd\"";
  55.             else print " class=\"even\"";
  56.             print "><td>$t</td><td>$k</td></tr>";
  57.             $i++;
  58.         }
  59.         ?>
  60.     </table>
  61.     <table class="thoroughbred" cellpadding="0" cellspacing="0">
  62.         <tr>
  63.             <td colspan="2" class="heading">Thoroughbred</td>
  64.         </tr>
  65.         <?
  66.         $i = 0;
  67.         foreach($thoroughbred as $k => $t) {
  68.             print "<tr";
  69.             if(is_even($i)) print " class=\"odd\"";
  70.             else print " class=\"even\"";
  71.             print "><td>$t</td><td>$k</td></tr>";
  72.             $i++;
  73.         }
  74.         ?>
  75.     </table>
  76. </div>
  77. <!--
  78. <div class="footer">
  79.     Today’s Tracks – Harness &amp; Thoroughbred
  80. </div>
  81. -->
  82. </div>
  83. </body>
  84. </html>


As you can probably tell, this is for a Racetrack site, to list the track times and if a particular track is closed.
I thought it would be cool if this info was also available on our website.
Since I know almost nothing about how to write this type of script etc I wanted to see if I could copy and paste this into an existing page.

It worked for the most part, however, sometimes I get an error on the page saying-
"Undefined offset: 1 in /home/trackname/public_html/simulcasting.php on line 46"

Sometimes I get the error, sometimes not.
Here is the way the page looks with the code pasted in:

Code: [ Select ]
<table width="100%">
    <tr>
        <td valign="top">

        <h1>SIMULCASTING</h1>

        <table width="650">
            <tr>
                <td valign="top" width="100%">
                
                    <p>The horse racing does not stop after the live meet ends at *****. Year round simulcasting is available daily from tracks across the country. Enjoy all the major North American tracks,
                    Thoroughbred and Standardbred, in our Cubhouse! Doors open for simulcasting at 11:30AM.</p>
                
                    <ul>
                        <li><a href="/pdf/HPSimulcastCalendar.pdf" target="_blank">Schedule <img src="/img/icons/link_pdf.png" height="14" width="14" class="icon" alt="Adobe PDF" /></a></li>
                        <li><a href="http://racing.*****.com/" target="_blank">Harness Entries/Results <img src="/img/icons/link_go.png" height="14" width="14" class="icon" alt="External Link" /></a></li>
                        <li><a href="/Simulcasting/Links">Track/Industry Links</a></li>
                        <li><a href="http://www.*****.com/premium/eqpCarryoverCorner.cfm" target="_blank">Carryovers <img src="/img/icons/link_go.png" height="14" width="14" class="icon" alt="External Link" /></a></li>
                    </ul>
                
                <?
//1024x768

//define the date in a nice presentable format for patrons
$date = date('l F j, Y');

function is_even($number) {
  return(!($number & 1)); // 0 = even, 1 = odd
}

// Get a file into an array.
$lines = file('/home/trackname/public_html/trackschedule/data.txt');

//create holders for data once we cycle thru the logic
//$schedule = array();
$harness = array();
$thoroughbred = array();

// Loop through our array, show HTML source as HTML source; and line numbers too.
foreach ($lines as $line_num => $line) {
  //echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
    
    //1st lets split the data up a bit
    $l = explode("-",$line);
    $time = $l[0];
    $track = $l[1];


    $check = strstr($track,"(");
    if($check) {
        $track = substr($track, 0, -4);
        $harness[$track] = $time;
    }
    else
        $thoroughbred[$track] = $time;//
    $schedule[$time] = "$track";

}
?>

<html>
<head>
<title>Track Schedule - <? print $date; ?></title>
<meta http-equiv="refresh" content="900">

<link rel="stylesheet" type="text/css" media="screen,projection" href="style.css" />
<link rel="stylesheet" type="text/css" media="print" href="print.css" />

</head>
<body>

<?
print "<div id=\"date\">$date</div>";
?>

<div id="container">

<!--<div class="greeting">Welcome to ***** Raceway!</div>-->


<div id="tracks">

    <table class="harness" cellpadding="0" cellspacing="0">
        <tr>
            <td colspan="2" class="heading">Harness</td>
        </tr>
        <?
        $i = 0;
        foreach($harness as $k => $t) {
            print "<tr";
            if(is_even($i)) print " class=\"odd\"";
            else print " class=\"even\"";
            print "><td>$t</td><td>$k</td></tr>";
            $i++;
        }
        ?>
    </table>

    <table class="thoroughbred" cellpadding="0" cellspacing="0">
        <tr>
            <td colspan="2" class="heading">Thoroughbred</td>
        </tr>
        <?
        $i = 0;
        foreach($thoroughbred as $k => $t) {
            print "<tr";
            if(is_even($i)) print " class=\"odd\"";
            else print " class=\"even\"";
            print "><td>$t</td><td>$k</td></tr>";
            $i++;
        }
        ?>
    </table>

</div>

<!--
<div class="footer">
    Today’s Tracks – Harness &amp; Thoroughbred
</div>

-->

</div>

</body>
</html>
                
                
                </td>
            </tr>
        </table>

        
        </td>
    </tr>
</table>
  1. <table width="100%">
  2.     <tr>
  3.         <td valign="top">
  4.         <h1>SIMULCASTING</h1>
  5.         <table width="650">
  6.             <tr>
  7.                 <td valign="top" width="100%">
  8.                 
  9.                     <p>The horse racing does not stop after the live meet ends at *****. Year round simulcasting is available daily from tracks across the country. Enjoy all the major North American tracks,
  10.                     Thoroughbred and Standardbred, in our Cubhouse! Doors open for simulcasting at 11:30AM.</p>
  11.                 
  12.                     <ul>
  13.                         <li><a href="/pdf/HPSimulcastCalendar.pdf" target="_blank">Schedule <img src="/img/icons/link_pdf.png" height="14" width="14" class="icon" alt="Adobe PDF" /></a></li>
  14.                         <li><a href="http://racing.*****.com/" target="_blank">Harness Entries/Results <img src="/img/icons/link_go.png" height="14" width="14" class="icon" alt="External Link" /></a></li>
  15.                         <li><a href="/Simulcasting/Links">Track/Industry Links</a></li>
  16.                         <li><a href="http://www.*****.com/premium/eqpCarryoverCorner.cfm" target="_blank">Carryovers <img src="/img/icons/link_go.png" height="14" width="14" class="icon" alt="External Link" /></a></li>
  17.                     </ul>
  18.                 
  19.                 <?
  20. //1024x768
  21. //define the date in a nice presentable format for patrons
  22. $date = date('l F j, Y');
  23. function is_even($number) {
  24.   return(!($number & 1)); // 0 = even, 1 = odd
  25. }
  26. // Get a file into an array.
  27. $lines = file('/home/trackname/public_html/trackschedule/data.txt');
  28. //create holders for data once we cycle thru the logic
  29. //$schedule = array();
  30. $harness = array();
  31. $thoroughbred = array();
  32. // Loop through our array, show HTML source as HTML source; and line numbers too.
  33. foreach ($lines as $line_num => $line) {
  34.   //echo "Line #<b>{$line_num}</b> : " . htmlspecialchars($line) . "<br />\n";
  35.     
  36.     //1st lets split the data up a bit
  37.     $l = explode("-",$line);
  38.     $time = $l[0];
  39.     $track = $l[1];
  40.     $check = strstr($track,"(");
  41.     if($check) {
  42.         $track = substr($track, 0, -4);
  43.         $harness[$track] = $time;
  44.     }
  45.     else
  46.         $thoroughbred[$track] = $time;//
  47.     $schedule[$time] = "$track";
  48. }
  49. ?>
  50. <html>
  51. <head>
  52. <title>Track Schedule - <? print $date; ?></title>
  53. <meta http-equiv="refresh" content="900">
  54. <link rel="stylesheet" type="text/css" media="screen,projection" href="style.css" />
  55. <link rel="stylesheet" type="text/css" media="print" href="print.css" />
  56. </head>
  57. <body>
  58. <?
  59. print "<div id=\"date\">$date</div>";
  60. ?>
  61. <div id="container">
  62. <!--<div class="greeting">Welcome to ***** Raceway!</div>-->
  63. <div id="tracks">
  64.     <table class="harness" cellpadding="0" cellspacing="0">
  65.         <tr>
  66.             <td colspan="2" class="heading">Harness</td>
  67.         </tr>
  68.         <?
  69.         $i = 0;
  70.         foreach($harness as $k => $t) {
  71.             print "<tr";
  72.             if(is_even($i)) print " class=\"odd\"";
  73.             else print " class=\"even\"";
  74.             print "><td>$t</td><td>$k</td></tr>";
  75.             $i++;
  76.         }
  77.         ?>
  78.     </table>
  79.     <table class="thoroughbred" cellpadding="0" cellspacing="0">
  80.         <tr>
  81.             <td colspan="2" class="heading">Thoroughbred</td>
  82.         </tr>
  83.         <?
  84.         $i = 0;
  85.         foreach($thoroughbred as $k => $t) {
  86.             print "<tr";
  87.             if(is_even($i)) print " class=\"odd\"";
  88.             else print " class=\"even\"";
  89.             print "><td>$t</td><td>$k</td></tr>";
  90.             $i++;
  91.         }
  92.         ?>
  93.     </table>
  94. </div>
  95. <!--
  96. <div class="footer">
  97.     Today’s Tracks – Harness &amp; Thoroughbred
  98. </div>
  99. -->
  100. </div>
  101. </body>
  102. </html>
  103.                 
  104.                 
  105.                 </td>
  106.             </tr>
  107.         </table>
  108.         
  109.         </td>
  110.     </tr>
  111. </table>


I think it might have something to do with the fact that the Harness/ Thoroughbred tracks appear in two different columns in the original page and (I believe) the page I'm putting this data on is set up to only have one column.

I've got a couple good books and will be doing some reading on how to write php scripts, so I don't expect anyone to write the whole page for me.
However, if there is a quick way to solve this problem I would appreciate any help. :)
(Was not aware that I would be managing the website when I took this job but its always fun to learn new things!)

Please let me know if there is any additional data that should be posted here.
Thanks in advance for any info I can get! :)
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

Post Information

  • Total Posts in this topic: 1 post
  • Users browsing this forum: No registered users and 100 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.