Jump to content

unexpected T_ENCAPSED_AND_WHITESPACE, expecting ']'


foxymoron

Recommended Posts

Hello,

 

I'm having trouble finding the error in the code below.  The error I get is "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting ']' in C:/ ... on line 45

 

while($row = mysql_fetch_array($result))

{

$display_string .= "<tr>";

$display_string .= "<td>$row[Est#]</td>";          //this is line 45

$display_string .= "<td>$row[Est_Desc]</td>";

$display_string .= "<td>$row[Price]</td>";

$display_string .= "<td>$row[Price_Unit]</td>";

$display_string .= "<td>$row[Quantity]</td>";

$display_string .= "<td>$row[Quantity_Unit]</td>";

$display_string .= "<td>$row[unit_Rate]</td>";

$display_string .= "<td>$row[Long_Desc]</td>";

$display_string .= "</tr>";

 

If I comment this line and its associated header in the table as well, the code runs as expected.  My only guess is that the # character may be messing this up however, in other queries this field name doesn't give me trouble.

 

Can anyone help?

 

Thanks in advance.

Hi,

 

Thanks for your response.  If I understand you correctly, I should change the code to:

 

while($row = mysql_fetch_array($result))

{

$display_string .= "<tr>";

$display_string .= "<td>$row['Est#']</td>";      //this is line 45

$display_string .= "<td>$row['Est_Desc']</td>";

$display_string .= "<td>$row['Price']</td>";

$display_string .= "<td>$row['Price_Unit']</td>";

$display_string .= "<td>$row['Quantity']</td>";

$display_string .= "<td>$row['Quantity_Unit']</td>";

$display_string .= "<td>$row['Unit_Rate']</td>";

$display_string .= "<td>$row['Long_Desc']</td>";

$display_string .= "</tr>";

 

But this change gives the error "Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\... on line 45"

 

Did I misunderstand?

 

Thanks

You need to either use concatenation or enclose the array reference in braces "{ }". Either

<?php
while($row = mysql_fetch_array($result))
{
   $display_string .= "<tr>";
   $display_string .= "<td>" . $row['Est#'] . "</td>";      //this is line 45
   $display_string .= "<td>" . $row['Est_Desc'] . "</td>";
   $display_string .= "<td>" . $row['Price'] . "</td>";
   $display_string .= "<td>" . $row['Price_Unit'] . "</td>";
   $display_string .= "<td>" . $row['Quantity'] . "</td>";
   $display_string .= "<td>" . $row['Quantity_Unit'] . "</td>";
   $display_string .= "<td>" . $row['Unit_Rate'] . "</td>";
   $display_string .= "<td>" . $row['Long_Desc'] . "</td>";
   $display_string .= "</tr>";
?>

or

<?php
while($row = mysql_fetch_array($result))
{
   $display_string .= "<tr>";
   $display_string .= "<td>{$row['Est#']}</td>";      //this is line 45
   $display_string .= "<td>{$row['Est_Desc']}</td>";
   $display_string .= "<td>{$row['Price']}</td>";
   $display_string .= "<td>{$row['Price_Unit']}</td>";
   $display_string .= "<td>{$row['Quantity']}</td>";
   $display_string .= "<td>{$row['Quantity_Unit']}</td>";
   $display_string .= "<td>{$row['Unit_Rate']}</td>";
   $display_string .= "<td>{$row['Long_Desc']}</td>";
   $display_string .= "</tr>";
?>

will work.

 

If I were doing this, I would use a temporary array:

<?php
while($row = mysql_fetch_array($result))
{
   $tmp = array();
   $tmp[] = $row['Est#'];      //this is line 45
   $tmp[] = $row['Est_Desc'];
   $tmp[] = $row['Price'];
   $tmp[] = $row['Price_Unit'];
   $tmp[] = $row['Quantity'];
   $tmp[] = $row['Quantity_Unit'];
   $tmp[] = $row['Unit_Rate'];
   $tmp[] = $row['Long_Desc'];
   $display_string = '<tr><td>' . implode('</td><td>',$tmp) . '</td></tr>";
?>

 

Ken

<?php
while($row = mysql_fetch_array($result))
{
   $tmp = array();
   $tmp[] = $row['Est#'];      //this is line 45
   $tmp[] = $row['Est_Desc'];
   $tmp[] = $row['Price'];
   $tmp[] = $row['Price_Unit'];
   $tmp[] = $row['Quantity'];
   $tmp[] = $row['Quantity_Unit'];
   $tmp[] = $row['Unit_Rate'];
   $tmp[] = $row['Long_Desc'];
   $display_string = '<tr><td>' . implode('</td><td>',$tmp) . '</td></tr>";
}
?>

I noticed the "}" missing.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.