I've managed to make some progress on this which you can see at
http://www.golfbettingguide.com/cont...uide-test2.php
Enter two golfers names eg Tiger Woods and Vijay Singh and the results display correctly.
However enter just one golfer in the first box and the table truncates before any of the finishing positions get output. Here's what my code looks like:-
Code:
if(isset($_POST['golferentry#1']))
{
$golfers = array(); //create empty array of golfers - see pg 110 of sitepoint book
$golfers[0] = $_POST['golferentry#1']; //assign first golfer entered into first index of $golfer
$golfers[1] = $_POST['golferentry#2']; //assign first golfer entered into first index of $golfer
$result = array(); //set up array of results
$tour = $_POST['tour'];
$ctr = 0; //set this to 0 to check if first time through foreach loop
foreach($golfers as $golfer)
{
$result[$ctr] = @mysql_query("SELECT G.Golfer, T.T_Date, T.Tournament, F.Position FROM tbl_tournaments AS T,
tbl_golfers AS G LEFT OUTER JOIN tbl_finish_pos AS F ON T.ID = F.TournamentID AND F.GolferID = G.ID
WHERE T.Tour = '$tour' AND G.Golfer = ('$golfer') ORDER BY T.ID DESC, G.Golfer DESC LIMIT 10 ");
if (mysql_num_rows($result[$ctr]) == 0)
{
echo ("
The golfer name $golfer does not exist in the database. Please check your spelling or try with a different name</p>
");
}
if(!$result)
{
die('
Error performing query: ' . mysql_error() . '</p>');
}
$ctr++;
}
echo ("<table id=\"tour_results\" cellpadding=\"0\" cellspacing=\"1\">
<tbody><tr>
<th colspan=\"4\" id=\"golf_form_title\">Golfer Form Guide</th>
</tr>
<tr class=\"golf_form_hdr\">
<td rowspan=\"2\" class=\"width_15pc\">Date</td><td rowspan=\"2\" class=\"width_35pc\">Tournament</td><td colspan=\"2\" class=\"width_50pc tops\">Finish Positions for:</td>
</tr>
<tr><td class=\"tops\">$golfers[0]</td><td class=\"tops\">$golfers[1]</td></tr>
");
$ctr = 0;
while ($row = mysql_fetch_array($result[$ctr]) )
{
$Golfer = $row['Golfer'];
$fp = $row['Position'];
$Tournament = $row['Tournament'];
$TournamentDate = $row['T_Date'];
if(!isset($fp))
{
// $var is null (does not exist at this time) and the execution goes here
$fp = "-";
}
if($ctr == 0)
{
echo('<tr><td class="odds_even">' . date('d-m-y', strtotime($TournamentDate)) . '</td>');
echo("<td class=\"odds_even\">$Tournament</td><td class=\"odds_even\">$fp</td>");
}
if($ctr > 0)
{
if(isset($row))
{
echo("<td class=\"odds_even\">$fp</td></tr>");
$ctr = 0;
}
else
{
echo("<td class=\"odds_even\"></td></tr>");
$ctr = 0;
}
}
else if ($ctr == 0)
{
$ctr++;
}
}
echo '</table>';
}
Fyi, the 1st line:-
if(isset($_POST['golferentry#1']))
is in there because I wanted the first box to be mandatory but the second optional.
If anyone could help I'd appreciate it.
Also, as a php newbie I'm not sure if the way I've coded this is efficient or whether there are better ways so I'd appreciate any comments from the php gurus out there.
Many thanks for any help.[/code]