Current location: Hot Scripts Forums » Programming Languages » PHP » Error in displaying results in table using a drop down


Error in displaying results in table using a drop down

Reply
  #1 (permalink)  
Old 07-04-05, 03:47 AM
SummerL SummerL is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
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">&nbsp; </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("&nbsp;&nbsp;<a href=\"$PHP_SELF?query=".$query."&page=$back_page&limit=$limit\">previous</a>&nbsp;&nbsp;\n");
} else {
	print ("&nbsp;&nbsp;&nbsp;&nbsp;");
}		
		
$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("&nbsp;&nbsp;<a href=\"$PHP_SELF?query=".$query."&page=$next_page&limit=$limit\">next</a>&nbsp;&nbsp;\n");
} else {
print ("&nbsp;&nbsp;&nbsp;&nbsp;");
}		
?>
            </td>
          </tr>
          <tr> 
            <td height="23">&nbsp;</td>
          </tr>
        </table>
        <table width="100%" height="32" border="0">
          <tr>
            <td>&nbsp; </td>
          </tr>
        </table></td>
    </tr>
  </table>
  <br>
  <table>
    <tr>
      <td>&nbsp;</td>
    </tr>
  </table>
</form>
<br>
<table width="75%" border="0">
  <tr>
    <td><div align="center"></div></td>
  </tr>
</table>
<p>&nbsp;</p>
<p>&nbsp;</p>
Reply With Quote
  #2 (permalink)  
Old 07-05-05, 10:28 AM
SummerL SummerL is offline
Newbie Coder
 
Join Date: Jul 2005
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
can someone please help me.. i really can't get it to work..
Reply With Quote
  #3 (permalink)  
Old 07-05-05, 12:44 PM
blaw's Avatar
blaw blaw is offline
Junior Code Guru
 
Join Date: Dec 2003
Location: Vancouver, BC, Canada
Posts: 550
Thanks: 0
Thanked 0 Times in 0 Posts
Hello,

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:

PHP Code:

$sOptions .= '<option value="'.$row['AircraftType'].'">'.$row['AircraftType'].'</option>'
Hope this helps.
__________________
Blavv =|
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Using the checkbox for displaying all results mcrob PHP 2 05-12-05 04:56 PM
Help with a "form" and displaying results. (Newbie here!) Rusty Ranchero ASP 11 04-26-05 04:45 PM
Output Array results into table dodotopia PHP 6 04-06-05 05:14 PM
Difficulty in displaying results of query altlprsn PHP 14 04-28-04 12:20 PM
[newbie] Displaying Database results in tables omgwtf PHP 4 03-21-04 07:15 PM


All times are GMT -5. The time now is 06:54 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.