Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.