Here is my code for my page. I am using Dreamweaver CS3 and I know it is a bit rough, but please bear with me I am learning. It seems when I put in your code where I want the value to appear in the table it works, but the rest of my table is truncated and it ignores any other PHP that I have in the table. Hope that makes sense!
<?php
############################################################################
# A Project of TNET Services, Inc. and Saratoga-Weather.org (WD-USA template set)
############################################################################
#
# Project: Sample Included Website Design
# Module: sample.php
# Purpose: Sample Page
# Authors: Kevin W. Reed <[email protected]>
# TNET Services, Inc.
#
# Copyright: (c) 1992-2007 Copyright TNET Services, Inc.
############################################################################
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
############################################################################
# This document uses Tab 4 Settings
############################################################################
require_once("Settings.php");
require_once("common.php");
############################################################################
$TITLE= $SITE['organ'] . " - Daily Records";
$showGizmo = true; // set to false to exclude the gizmo
include("top.php");
############################################################################
?>
</head>
<style type="text/css">
<!--
.style1 {
color: #FFFFFF;
font-weight: bold;
font-size: 14px;
}
.style2 {
font-size: 9px;
font-weight: bold;
}
#main-copy table {
border-top-width: thin;
border-right-width: thin;
border-bottom-width: thin;
border-left-width: thin;
border-top-style: solid;
border-right-style: solid;
border-bottom-style: solid;
border-left-style: solid;
}
.style7 {
font-size: 12px;
font-weight: bold;
}
.style8 {font-size: 12px; }
#main-copy td {
}
-->
</style>
<body>
<?php
############################################################################
include("header.php");
############################################################################
include("menubar.php");
############################################################################
?>
<?php
// select this months numeric value
$thismonth = date("n");
//select file to open
$myFile = "./Records/".$thismonth.".txt";
// open file
$fh = fopen($myFile, 'r');
// load file data into a variable for handling later
$theData = fread($fh, filesize($myFile));
// close file
fclose($fh);
// select day for row search
$thisday = date("j");
//split data file into an array so we can walk around in it \r\n means split contents on new lines we do this so we can loop through each row of the array performing actions as required.
$lookuparray = explode("\n",$theData);
// get a count of array length
$arraycount = count($lookuparray);
?>
<div id="main-copy">
<p>
<h1 align="left">DFW Weather Records/Daily Summary</h1>
<p align="left">(As officially recorded from DFW Airport. Period of record began in September 1898.)</p>
<table width="661" border="1" cellpadding="2" cellspacing="0" bordercolor="#666666">
<tr bgcolor="#000099">
<td colspan="9" bgcolor="#3173b1"><div align="left"><span class="style1">Daily Summary</span></div></td>
</tr>
<tr>
<td colspan="9"><strong><? print(Date("F j, Y")); ?></strong></td>
</tr>
<tr>
<td width="93" rowspan="2" bgcolor="#666666"> </td>
<td colspan="2"><div align="center" class="style8"><strong>Yesterday</strong></div> <div align="center" class="style8"></div></td>
<td colspan="2"><div align="center" class="style8"><strong>Today</strong></div> <div align="center" class="style8"></div></td>
<td colspan="2"><div align="center" class="style8"><strong>Normal</strong></div> <div align="center" class="style8"></div></td>
<td colspan="2"><div align="center" class="style8"><strong>Record</strong></div> <div align="center" class="style8"></div></td>
</tr>
<tr>
<td width="55"><div align="center" class="style2">Low</div></td>
<td width="55"><div align="center" class="style2">High</div></td>
<td width="55"><div align="center" class="style2">Low</div></td>
<td width="55"><div align="center" class="style2">High</div></td>
<td width="55"><div align="center" class="style2">Low</div></td>
<td width="55"><div align="center" class="style2">High</div></td>
<td width="84"><div align="center" class="style2">Low</div></td>
<td width="84"><div align="center" class="style2">High</div></td>
</tr>
<tr>
<td><div align="right"><strong>Temperature:</strong></div></td>
<td><div align="center"><span style="text-align: center;">
<?php
echo strip_units($mintempyest) . $uomTemp; ?>
</span></div></td>
<td><div align="center"><span style="text-align: center;">
<?php
echo strip_units($maxtempyest) . $uomTemp; ?>
</span></div></td>
<td><div align="center"><span class="ajax">
<?php
// What is the URL you are going to get
$URL = 'http://www.wunderground.com/history/airport/KDFW/2009/4/1/DailyHistory.' .
'html?req_city=NA&req_state=NA&req_statename=NA';
// Obtain page into an array
$raw_string = file($URL);
// Search through the array to find the line that has that in it
// There are a number of different ways of doing this including using
// array_search etc...
echo get_value("Min Temperature") . "°F";
exit;
function get_value ($lookfor) {
global $raw_string;
foreach($raw_string as $key => $value ) {
// Does the string exist in this this element?
if ( strpos($value,$lookfor) !== FALSE ) {
// Yep, so the value is in two array elements further
// Find where the data is
// Starts
$ptr1 = strpos($raw_string[$key + 2],'class="b">') + 10;
// Ends
$ptr2 = strpos($raw_string[$key + 2], '</', $ptr1) - $ptr1 ;
// Output the data we found
return (substr($raw_string[$key + 2],$ptr1,$ptr2));
}
}
} ?>
</span></div></td>
<td width="55"><div align="center"><span class="ajax">
<?php
// What is the URL you are going to get
$URL = 'http://www.wunderground.com/history/airport/KDFW/2009/4/1/DailyHistory.' .
'html?req_city=NA&req_state=NA&req_statename=NA';
// Obtain page into an array
$raw_string = file($URL);
// Search through the array to find the line that has that in it
// There are a number of different ways of doing this including using
// array_search etc...
echo get_value2("Max Temperature") . "°F";
exit;
function get_value2 ($lookfor) {
global $raw_string;
foreach($raw_string as $key => $value ) {
// Does the string exist in this this element?
if ( strpos($value,$lookfor) !== FALSE ) {
// Yep, so the value is in two array elements further
// Find where the data is
// Starts
$ptr1 = strpos($raw_string[$key + 2],'class="b">') + 10;
// Ends
$ptr2 = strpos($raw_string[$key + 2], '</', $ptr1) - $ptr1 ;
// Output the data we found
return (substr($raw_string[$key + 2],$ptr1,$ptr2));
}
}
} ?> ?></span></div></td>
<td><div align="center">
<?php
// loop through array starting at the start in arrays thats element zero
for($i=0;$i<$arraycount;$i++){
// if we hit the day we want do something
if ($i=$thisday) {
// split the retrieved line matching the current day for processing.
$perlinearray = explode("\t",$lookuparray[$i]);
// echo out all 11 columns you can work out what to do with it later or if you need to select only a specific column you can use the principals above to work it out :)
echo $perlinearray[9];
// end processing after displaying the line we want
break;
} else {
echo " ";
}
}
?>°F</div></td>
<td><div align="center">
<?php
// loop through array starting at the start in arrays thats element zero
for($i=0;$i<$arraycount;$i++){
// if we hit the day we want do something
if ($i=$thisday) {
// split the retrieved line matching the current day for processing.
$perlinearray = explode("\t",$lookuparray[$i]);
// echo out all 11 columns you can work out what to do with it later or if you need to select only a specific column you can use the principals above to work it out :)
echo $perlinearray[10];
// end processing after displaying the line we want
break;
} else {
echo " ";
}
}
?>°F</div></td>
<td><div align="center">
<?php
// loop through array starting at the start in arrays thats element zero
for($i=0;$i<$arraycount;$i++){
// if we hit the day we want do something
if ($i=$thisday) {
// split the retrieved line matching the current day for processing.
$perlinearray = explode("\t",$lookuparray[$i]);
// echo out all 11 columns you can work out what to do with it later or if you need to select only a specific column you can use the principals above to work it out :)
echo $perlinearray[1];
// end processing after displaying the line we want
break;
} else {
echo " ";
}
}
?>°F (<?php
// loop through array starting at the start in arrays thats element zero
for($i=0;$i<$arraycount;$i++){
// if we hit the day we want do something
if ($i=$thisday) {
// split the retrieved line matching the current day for processing.
$perlinearray = explode("\t",$lookuparray[$i]);
// echo out all 11 columns you can work out what to do with it later or if you need to select only a specific column you can use the principals above to work it out :)
echo $perlinearray[2];
// end processing after displaying the line we want
break;
} else {
echo " ";
}
}
?>)</div></td>
<td width="84"><div align="center">
<?php
// loop through array starting at the start in arrays thats element zero
for($i=0;$i<$arraycount;$i++){
// if we hit the day we want do something
if ($i=$thisday) {
// split the retrieved line matching the current day for processing.
$perlinearray = explode("\t",$lookuparray[$i]);
// echo out all 11 columns you can work out what to do with it later or if you need to select only a specific column you can use the principals above to work it out :)
echo $perlinearray[3];
// end processing after displaying the line we want
break;
} else {
echo " ";
}
}
?>°F (<?php
// loop through array starting at the start in arrays thats element zero
for($i=0;$i<$arraycount;$i++){
// if we hit the day we want do something
if ($i=$thisday) {
// split the retrieved line matching the current day for processing.
$perlinearray = explode("\t",$lookuparray[$i]);
// echo out all 11 columns you can work out what to do with it later or if you need to select only a specific column you can use the principals above to work it out :)
echo $perlinearray[4];
// end processing after displaying the line we want
break;
} else {
echo " ";
}
}
?>)</div></td>
</tr>
<tr>
<td bgcolor="#666666"> </td>
<td colspan="2"><div align="center" class="style7">Yesterday</div></td>
<td colspan="2"><div align="center" class="style7">Today</div></td>
<td colspan="2"><div align="center" class="style7">Record</div></td>
<td colspan="2" rowspan="3" bgcolor="#666666"> </td>
</tr>
<tr>
<td><div align="right"><strong>Rain:</strong></div></td>
<td colspan="2"><div align="center"><span class="ajax"><?php echo strip_units($yesterdayrain) . $uomRain; ?></span></div></td>
<td colspan="2"><div align="center"><span class="ajax"><?php echo strip_units($dayrn) . $uomRain; ?></span></div></td>
<td colspan="2"><div align="center">
<?php
// loop through array starting at the start in arrays thats element zero
for($i=0;$i<$arraycount;$i++){
// if we hit the day we want do something
if ($i=$thisday) {
// split the retrieved line matching the current day for processing.
$perlinearray = explode("\t",$lookuparray[$i]);
// echo out all 11 columns you can work out what to do with it later or if you need to select only a specific column you can use the principals above to work it out :)
echo $perlinearray[5];
// end processing after displaying the line we want
break;
} else {
echo " ";
}
}
?>" (<?php
// loop through array starting at the start in arrays thats element zero
for($i=0;$i<$arraycount;$i++){
// if we hit the day we want do something
if ($i=$thisday) {
// split the retrieved line matching the current day for processing.
$perlinearray = explode("\t",$lookuparray[$i]);
// echo out all 11 columns you can work out what to do with it later or if you need to select only a specific column you can use the principals above to work it out :)
echo $perlinearray[6];
// end processing after displaying the line we want
break;
} else {
echo " ";
}
}
?>)</div></td>
</tr>
<tr>
<td><div align="right"><strong>Snow:</strong></div></td>
<td colspan="2"><div align="center">0.00"</div></td>
<td colspan="2"><div align="center">0.00"</div></td>
<td colspan="2"><div align="center">
<?php
// loop through array starting at the start in arrays thats element zero
for($i=0;$i<$arraycount;$i++){
// if we hit the day we want do something
if ($i=$thisday) {
// split the retrieved line matching the current day for processing.
$perlinearray = explode("\t",$lookuparray[$i]);
// echo out all 11 columns you can work out what to do with it later or if you need to select only a specific column you can use the principals above to work it out :)
echo $perlinearray[7];
// end processing after displaying the line we want
break;
} else {
echo " ";
}
}
?>
(<?php
// loop through array starting at the start in arrays thats element zero
for($i=0;$i<$arraycount;$i++){
// if we hit the day we want do something
if ($i=$thisday) {
// split the retrieved line matching the current day for processing.
$perlinearray = explode("\t",$lookuparray[$i]);
// echo out all 11 columns you can work out what to do with it later or if you need to select only a specific column you can use the principals above to work it out :)
echo $perlinearray[8];
// end processing after displaying the line we want
break;
} else {
echo " ";
}
}
?>)</div></td>
</tr>
</table>
</div>
<!-- end main-copy -->
<?php
############################################################################
include("footer.php");
############################################################################
# End of Page
############################################################################
?>
The table is supposed to look like this www.dfwweather.org/wxrecords3.php
The data in the normal and record fields under temperatures are correct, as well as under the rain and snow record field. I just need to basically get the info for the yesterday and today fields. If I can get one, such as the Low under today to work, I think I can figure out the rest.