Problems with MySQL

Associate
Joined
21 Mar 2007
Posts
41
Hi,

Can anyone tell me why I keep alternating between an "unexpected T_ENCAPSED_AND_WHITESPACE" error and an "unexpected T_LNUMBER" error with the following code:

$query = "SELECT * FROM boardchanges_checkuser";
$get_comments = mysql_query($query);
while($data = mysql_fetch_array($get_comments))
{
echo("
<table width=\'100%\'>
<tr><td class=\"poll\" align=\"center\"><strong>Comments</strong></td></tr>
<tr><td class=\"poll\" width='25%'>$data['user']</td>
<td class=\"poll\" width='75%>$data['comments']</td><tr>
</table>");
}

I'm trying to insert a table that gives the user number and comments posted by that user.
 
replace:
Code:
width='75%
with:
Code:
width=\"75%\"

unless you're doing something weird, you shouldn't need to escape single quotes in there
 
Nope, still getting:

Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING

I can post the whole page's code if it'd help.
 
I think so,

Entire page code:

Code:
<?
include "../bin/global.php";

#check we are logged in...
validateuser(true);

if($isadmin!=true && $isinter!=true){
Header("Location: /index.php");
}

include "../bin/header.php";
?>
<script language="javascript" type="text/javascript">
<!--
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="random"){LeftPosition=(screen.width)?Math.floor(Math.random()*(screen.width-w)):100;TopPosition=(screen.height)?Math.floor(Math.random()*((screen.height-h)-75)):100;}
if(pos=="center"){LeftPosition=(screen.width)?(screen.width-w)/2:100;TopPosition=(screen.height)?(screen.height-h)/2:100;}
else if((pos!="center" && pos!="random") || pos==null){LeftPosition=0;TopPosition=20}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);}
// -->
</script>
<table width="500" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td>


<?


	$poll = mysql_fetch_array(mysql_query("select * from boardchanges_poll"));
	$totalvotes = $poll['totalvotes'];
	$question = $poll['question'];
			
	echo("
<table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">
<tr><td class=\"poll\" align=\"center\">
<strong>Current Standings</strong><br /><br />
</td></tr>
<tr><td class=\"poll\">
");
	
	$get_questions = mysql_query("select * from boardchanges_options");
	while($r=mysql_fetch_array($get_questions)){
	
	
		extract($r);
		$per = $votes * 100 / $totalvotes;
		$per = floor($per);
		
		echo htmlspecialchars($field); 
		?>: <strong><? echo("$votes"); ?></strong><br />
		<div style="background-color: #EEEEEE;"><div style="color: #000000; font-size: 10px; text-align: right;background-color: #CCCCCC; width: <? echo($per); ?>%;"><? echo("$per%"); ?></div></div><br />
		<?
			
	}
	
	echo("
</td></tr>
<tr><td class=\"poll\">
<br /><center>Total votes: <strong>$totalvotes</strong></center>
</td></tr>
</table>");

	$query = "SELECT * FROM boardchanges_checkuser";
	$get_comments = mysql_query($query);
	while($data = mysql_fetch_array($get_comments))
	{
	echo("
<table width=\'100%\'>
<tr><td class=\"poll\" align=\"center\"><strong>Comments</strong></td></tr>
<tr><td class=\"poll\" width=\'25%\'>$data['user']</td>
<td class=\"poll\" width=\'75%\'>$data['comments']</td><tr>
</table>");
}
?>


<?
include "../bin/footer.php";
?>
 
You probably have an unterminated string. I suggest you context switch between html and php using %>. Then using an IDE you will be able to see is you do have an unterminated string.
 
I have been through your code again and I just can't see anything wrong. Probably because there is no code highlighting! And the formatting sucks too :p
 
$query = "SELECT * FROM boardchanges_checkuser";
$get_comments = mysql_query($query);
while($data = mysql_fetch_array($get_comments))
{
echo("
<table width=\'100%\'>
<tr><td class=\"poll\" align=\"center\"><strong>Comments</strong></td></tr>
<tr><td class=\"poll\" width='25%'>$data['user']</td>
<td class=\"poll\" width='75%>$data['comments']</td><tr>
</table>");
}

One thing which immediately jumps out at me is the two items in bold. When indexing associative arrays inside a string, you can't put single quotes around the element name. Try changing them so that they read $data[user] and $data[comments] respectively.
 
Right, guy above is correct. I removed the single quotes and Eclipse stopped highlighting the line as an error.

I thought you had missed a closing tag, but I had accidently deleted it when messing - only realised it wasn't missing in your post until after I posted :p
 
Last edited:
Thanks guys, that's got it to display, even if it does look a bit strange. I've probably got a few missing tags somewhere that the other person I'm working with can find (as they're very good at doing that!)
 
I know you have resolved this, but really you should be separating out your code. Makes it so much easier to manage. This like so...

Code:
{
%>
    <table width='100%'>
        <tr>
            <td colspan="2" class="poll" align="center">
                <strong>Comments</strong>
            </td>
         </tr>
         <tr>
             <td class="poll" width='25%'>
                 <%php echo $data['user'] %>
             </td>
             <td class="poll" width='75%>
                 <%php echo $data['comments'] %>
             </td>
         <tr>
     </table>
<%php
}
 
Back
Top Bottom