foxymoron Posted March 13, 2008 Share Posted March 13, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/96054-unexpected-t_encapsed_and_whitespace-expecting/ Share on other sites More sharing options...
AdRock Posted March 13, 2008 Share Posted March 13, 2008 It's with every one of these $row[Est#] and the rest they need to be like this $row['Est#'] Quote Link to comment https://forums.phpfreaks.com/topic/96054-unexpected-t_encapsed_and_whitespace-expecting/#findComment-491752 Share on other sites More sharing options...
foxymoron Posted March 13, 2008 Author Share Posted March 13, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/96054-unexpected-t_encapsed_and_whitespace-expecting/#findComment-491759 Share on other sites More sharing options...
derrick1123 Posted March 13, 2008 Share Posted March 13, 2008 $display_string = "<tr>"; Try removing the "."... Quote Link to comment https://forums.phpfreaks.com/topic/96054-unexpected-t_encapsed_and_whitespace-expecting/#findComment-491761 Share on other sites More sharing options...
kenrbnsn Posted March 13, 2008 Share Posted March 13, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/96054-unexpected-t_encapsed_and_whitespace-expecting/#findComment-491768 Share on other sites More sharing options...
derrick1123 Posted March 13, 2008 Share Posted March 13, 2008 <?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. Quote Link to comment https://forums.phpfreaks.com/topic/96054-unexpected-t_encapsed_and_whitespace-expecting/#findComment-491770 Share on other sites More sharing options...
AdRock Posted March 13, 2008 Share Posted March 13, 2008 or just change this $display_string .= "<tr>"; to $display_string = "<tr>"; Quote Link to comment https://forums.phpfreaks.com/topic/96054-unexpected-t_encapsed_and_whitespace-expecting/#findComment-491772 Share on other sites More sharing options...
kenrbnsn Posted March 13, 2008 Share Posted March 13, 2008 Changing the ".=" to "=" will not fix the error. As for the missing closing "}", the OP didn't have one in the original post, so I didn't put it in. Ken Quote Link to comment https://forums.phpfreaks.com/topic/96054-unexpected-t_encapsed_and_whitespace-expecting/#findComment-491774 Share on other sites More sharing options...
foxymoron Posted March 13, 2008 Author Share Posted March 13, 2008 I used the method of enclosing the array reference in braces and it worked. Thank you very much! Thanks to everyone that offered assistance, as well. Quote Link to comment https://forums.phpfreaks.com/topic/96054-unexpected-t_encapsed_and_whitespace-expecting/#findComment-491776 Share on other sites More sharing options...
derrick1123 Posted March 13, 2008 Share Posted March 13, 2008 As for the missing closing "}", the OP didn't have one in the original post, so I didn't put it in. Ken I know that thats why I thought he might be missing it, but it looks like it works now. ^.^ Quote Link to comment https://forums.phpfreaks.com/topic/96054-unexpected-t_encapsed_and_whitespace-expecting/#findComment-491779 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.