Error in displaying results in table using a drop down
I have got trouble with my functions.. It's more of capturing the data from the database using a drop down list and display it in a table..
I get a parse error instead..
Parse error: parse error, expecting `T_STRING' or `T_VARIABLE' or `T_NUM_STRING' in c:\inetpub\wwwroot\SIP\searchAircraftType.php on line 28
Line 28 - $sOptions .= "<option value=\"$row['AircraftType']\">$row['AircraftType']</option>";
Code:
<?php
include("data.inc");
//include("searchAircraftType.php");
$connection = mysql_connect($host, $user, $password)
or die ("couldn't connect to server.");
$db = mysql_select_db($database, $connection)
or die ("couldn't select database.");
function AircraftType()
{
$query = "SELECT distinct AircraftType FROM report";
$result = mysql_query($query) or die ("couldn't execute query.");
$sOptions = '';
while ($row = mysql_fetch_array($result))
{
extract($row);
$sOptions .= "<option value=\"$row['AircraftType']\">$row['AircraftType']</option>";
}
// set the number of results to display on each page... 4x2=8
if (!($limit)){
$limit = 10;
}
// check to see if we're on the first page of the results
if (!($page)){
$page = 0;
}
// in order to paginate the results we need to know in advance how many there are
$numrows = mysql_num_rows($query);
// if there are no results, print a friendly message
if ($numrows == 0){
print("<td>There are currently no results for this query</td>\n
</tr>\n</table>\n");
exit();
}
// divide the number of results by the number displayed on each page, to get number of pages
$pages = intval($numrows/$limit);
// if there are results left over, we need to add one more page
if ($numrows%$limit) {
$pages++;
}
$current = ($page/$limit) + 1; // calculate the current page number.
if (($pages < 1) || ($pages == 0)) {
$total = 1;
} else { // if $pages is less than one or equal to 0, total pages equals 1
$total = $pages;
} // if not, total pages is the value of $pages
$first = $page + 1;
//if this is not the last results page, last result = $page plus $limit
if (!((($page + $limit) / $limit) >= $pages) && $pages != 1) {
$last = $page + $limit;
} else { // if this is the last results page, last result equals total number of results
$last = $numrows;
}
return $sOptions;
?>
<tr>
<td colspan="4"></td>
</tr>
<tr>
<td colspan="4"> </td>
</tr>
</table>
<form action="searchAircraftType.php" method="get" name="search">
<table width="73%" height="459" border="1" bordercolor="#0099FF">
<tr>
<td><input name="Report" type="submit" id="Report2" value="Report"> <input name="Review" type="submit" id="Review" value="Review">
<input name="Logout" type="submit" id="Logout2" value="Logout">
</td>
</tr>
<tr>
<td>
<table width="100%" border="1">
<tr>
<td colspan="3"><strong><font color="#FF0000" size="4">Search Criteria</font></strong></td>
</tr>
<td width="44%">Aircraft Type</td>
<td width="56%"><select name="AircraftType" id="AircraftType">
<? AircraftType(); ?>
</select> <em><font color="#FF0000" size="2"></font></em></td>
</tr>
<tr>
<td colspan="3"> <div align="center"><strong>
<input type="submit" name="Submit" value="Search" />
</strong></div></td>
</tr>
</table>
<table width="100%" height="54" border="1" bordercolor="#FFFFFF" dwcopytype="CopyTableCell">
<tr>
<td height="23">
<?php
if ($result) {
echo "<table width=90% align=center border=1><tr>
<td align=center bgcolor=#00FFFF>AirCraft Tail No.</td>
<td align=center bgcolor=#00FFFF>Airframe Hours</td>
<td align=center bgcolor=#00FFFF>Type of Defect</td>
<td align=center bgcolor=#00FFFF>Location of Defect</td>
<td align=center bgcolor=#00FFFF>Rectifications</td>
<td align=center bgcolor=#00FFFF>Comments</td>
<td align=center bgcolor=#00FFFF>Related Documents</td>
</tr><tr>";
while ($r = mysql_fetch_array($result)) {
//if there are 7 cols, write the <tr> tag and reset the counter
if ($cntr == 2)
{
echo "</tr><tr>";
$cntr =1;
}
$aircraftTailNo = $r["aircraftTailNo"];
$aircraftType = $r["aircraftType"];
$airFrameHours = $r["airFrameHours"];
$defectInfo = $r["defectInfo"];
$rectifications = $r["rectifications"];
$comments = $r["comments"];
$relatedDoc = $r["relatedDoc"];
}
echo "
<td>$aircraftTailNo </td>
<td>$aircraftType </td>
<td>$airFrameHours </td>
<td>$defectInfo </td>
<td>$rectifications </td>
<td>$comments </td>
<td>$relatedDoc </td>
";
$cntr++; //increment the counter
}
echo "</tr></table>";
?>
<?php
if ($page != 0) { // don't show back link if this is the first page
$back_page = $page - $limit;
echo(" <a href=\"$PHP_SELF?query=".$query."&page=$back_page&limit=$limit\">previous</a> \n");
} else {
print (" ");
}
$ppage = $limit*($i - 1);
print ("page $current of $pages");
if (!((($page+$limit) / $limit) >= $pages) && $pages != 1) { // if this isn't the last page show 'next' link
$next_page = $page + $limit;
echo(" <a href=\"$PHP_SELF?query=".$query."&page=$next_page&limit=$limit\">next</a> \n");
} else {
print (" ");
}
?>
</td>
</tr>
<tr>
<td height="23"> </td>
</tr>
</table>
<table width="100%" height="32" border="0">
<tr>
<td> </td>
</tr>
</table></td>
</tr>
</table>
<br>
<table>
<tr>
<td> </td>
</tr>
</table>
</form>
<br>
<table width="75%" border="0">
<tr>
<td><div align="center"></div></td>
</tr>
</table>
<p> </p>
<p> </p>
I have never been a big fan of using variables inside the quotes. Also, if you are quoting HTML, I think it's much easier to use single quotes on PHP-side because that way you would not have to worry about adding slashes to all attributes' values. Try this: