0

Having a few issues with changing my column width and changing it through

colspan='2'

works up till my while loop where it throws the error

Parse error: syntax error, unexpected T_LNUMBER, expecting ',' or ';'

Any help, heres my code:

echo "<table border='0', width='100%'><tr><th colspan='2'>ID</th>
                     <th colspan='2'>First Name</th>                             
                     <th colspan='2'>Last Name</th><th colspan='2'>Location</th>
                     <th colspan='2'>Last Updated</th></tr>";
    while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC))
    {

        echo "<tr><td colspan='2'>" .$row['userID'].' </td><td colspan='2'> '.$row['first_name'].' </td><td colspan='2'> '
        .$row['last_name'].' </td><td colspan='2'> '.$row['current_location'].' </td><td colspan='2'> '
        .$row['last_updated']->format('Y-m-d H:i:s'). "</td><tr>";
    }

    echo "</table>";
2
  • Not sure if that will solve anything, but you've got a comma where it's not needed on line 1 : border='0', width='100%' Commented May 8, 2017 at 21:44
  • 2
    You're using single quote as the delimiter around the strings and also the delimiter around the colspan='2' attribute. Commented May 8, 2017 at 21:44

3 Answers 3

1

Your are doing wrong concatenation

paste this inside while loop:

echo "<tr><td colspan='2'>" .$row['userID']." </td><td colspan='2'> ".$row['first_name']." </td><td colspan='2'> "
        .$row['last_name']." </td><td colspan='2'> ".$row['current_location']." </td><td colspan='2'> "
        .$row['last_updated']->format('Y-m-d H:i:s'). "</td><tr>";

or

Simply use

<tr>
<td colspan='2'><?php echo $row['userID'];?>
<td colspan='2'><?php echo $row['first_name'];?></td>
<td colspan='2'><?php echo $row['last_name'];?></td>
<td colspan='2'><?php echo $row['current_location'];?></td>
<td colspan='2'><?php echo $row['last_updated']->format('Y-m-d H:i:s'); ?></td>
<tr>
Sign up to request clarification or add additional context in comments.

Comments

0

The problem is that you're using the same quotes as the delimiters around the PHP strings and around the attribute values inside the string, e.g.:

' </td><td colspan='2'> '

Change one of them to double quotes:

' </td><td colspan="2"> '

or

" </td><td colspan='2'> "

Or escape the quotes inside:

' </td><td colspan=\'2\'> '

1 Comment

Thank you for your help!
0

Pay attention to your concatenation You are using single quotes for both string and colspan attribute inside your loop

 while($row = sqlsrv_fetch_array($results, SQLSRV_FETCH_ASSOC))
 {

    echo "<tr><td colspan='2'>" .$row['userID']." </td><td colspan='2'> 
   ".$row['first_name']." </td><td colspan='2'> "
   .$row['last_name']." </td><td colspan='2'> ".$row['current_location']." 
  </td><td colspan='2'> "
.$row['last_updated']->format('Y-m-d H:i:s'). "</td><tr>";

}

1 Comment

Appreciate you taking the time, thanks this was the problem!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.