PLEASE HELP ..how to write html and php code into a php variable?

I have a problem with writing php code into html. Here is a sample code.

<?php
include_once 'phpFiles/session.php';
include_once 'class_db_connect.php';
$sql="select * from officeinfo where empid=$empid";
                $result=mysql_query($sql);

                $nrow=mysql_numrows($result);

while($row=mysql_fetch_array($result)) {




 $tableoutput=<<<_
        <table>
                <tr >
                     <th align="left">Employee ID</th><td>$row[empid]</td>
                </tr>
                <tr>
                     <th align="left">Department</th><td>$row[deptname]</td>
                </tr>
                <tr>
                     <th align="left">Position Name&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp </th><td>$row[positionname]</td>
                </tr>
                <tr>
                     <th align="left">Salary Grade</th><td>$row[salarygradeid]</td>
                </tr>
                <tr>
                     <th align="left">Joining Date</th><td>$row[joiningdate]</td>
                </tr>
                $stuid=$row_record_student[id];
                  $query_record_student_info = sprintf("SELECT * FROM previous_qualification where student_id=$stuid");
            $record_student_info = mysql_query($query_record_student_info, $M) or die(mysql_error());
                $numrows=mysql_num_rows($record_student_info);
                    $i=1;
    while($student_info=mysql_fetch_assoc($record_student_info))
    {
    $awardingbody_previous=stripslashes($student_info[Awarding_Body]);
    $qualification=stripslashes($student_info[previous_qualification]);
    $year=stripslashes($student_info[year]);
    $result=stripslashes($student_info[result]);
         <tr>
                            
                            <td><table>
                <tr>
                    <td valign="top">$i</td>
                    <td valign="top">$qualification&nbsp;,&nbsp;$awardingbody_previous,&nbsp;Year&nbsp;-&nbsp;$year&nbsp;,&nbsp;Result&nbsp;-&nbsp;$result</td>
                </tr>
            
            </table></td>
                      </tr>
     $i++ }
                

            </table>
_;
    

echo $tableoutput;
                }

?>

in php i write html and i want to execute while loop in the html code but thats a problem , i can’t get the whole output that i want. how can i do this ?

You have to close your heredoc string before the PHP commands, i.e, put the “_;” before the “$stuid=$row_record_student[id];”.

Hello
Example…

$bb=“Sitepoint”;
$a=“<a href=‘http://www.sitepoint.com’>$bb</a>”;
echo $a;

Thanks

If i put heredoc string before the PHP commands then it only execute upto the code before the heredoc commands “_;”. But i need to show whole table output.

If it is to display a single employee table information then why do you need to loop? I would do something like this if i am not getting you wrong.


<?php
include_once 'phpFiles/session.php';
include_once 'class_db_connect.php';
$sql = "SELECT * FROM officeinfo WHERE empid=$empid";
$result = mysql_query($sql) or die(mysql_error());

if(mysql_num_rows($result) > 1):
    $row = mysql_fetch_array($result); ?>
    <table>
        <tr >
             <th align="left">Employee ID</th><td><?php echo $row['empid'] ?></td>
        </tr>
        <tr>
             <th align="left">Department</th><td><?php echo $row['deptname'] ?></td>
        </tr>
        <tr>
             <th align="left">Position Name&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp </th><td><?php echo $row['positionname'] ?></td>
        </tr>
        <tr>
             <th align="left">Salary Grade</th><td><?php echo $row['salarygradeid'] ?></td>
        </tr>
        <tr>
             <th align="left">Joining Date</th><td><?php echo $row['joiningdate'] ?></td>
        </tr>
        <?php
        $stuid = $row_record_student['id'];
        $query_record_student_info = sprintf("SELECT * FROM previous_qualification where student_id=$stuid");
        $record_student_info = mysql_query($query_record_student_info, $M) or die(mysql_error());
        $numrows = mysql_num_rows($record_student_info);
        $i = 1;
        while($student_info = mysql_fetch_assoc($record_student_info)):
        $awardingbody_previous = stripslashes($student_info['Awarding_Body']);
        $qualification = stripslashes($student_info['previous_qualification']);
        $year = stripslashes($student_info['year']);
        $result = stripslashes($student_info['result']); ?>
        <tr>
            <td>
                <table>
                    <tr>
                        <td valign="top">$i</td>
                        <td valign="top"><?php echo $qualification; ?>&nbsp;,&nbsp;<?php echo $awardingbody_previous; ?>,&nbsp;Year&nbsp;-&nbsp;<?php echo $year; ?>&nbsp;,&nbsp;Result&nbsp;-&nbsp;<?php echo $result; ?></td>
                    </tr>
                </table>
            </td>
        </tr>
         <?php $i++;
         endwhile; ?>
    </table>
<?php
else:
    echo "No record found";
endif;  
?>