html - Not displaying SQL data through PHP when using a template file -


i have used template.php file create layout of page , inserting content through $content variable stored in separate file. example of file:

<?php  $content = '     <table id="job_table">         <tr>           <th id="jobtitle">catering assistant</th>           <th id="r_code">ref code: 14407773</th>         </tr>          <tr>           <td id="location">northampton</td>           <td id="salery">£2,000 monthly</td>                </tr>          <tr>             <td id="description">description</td>             <td>             assist in catering workers in canteen area.             </td>         </tr>          <tr>             <td><a href="apply.php" class="applybutton">apply now!</a></td>             <td></td>         </tr>     </table> ';  include 'template.php';  ?> 

then inside of template using echo display content:

<div id="content_area">     <?php echo $content; ?> </div> 

when use following code inside of template.php file works intended:

<div id="content_area">                 <?php echo $content; ?>                  <?php                  $server = '192.168.56.2';                 $username = 'student';                 $password = 'student';                 $schema = 'travelcompanydatabase';                  $pdo = new pdo('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);                 $results = $pdo->query('select * user');                  foreach ($results $row)                 {                     echo '<p>' . $row['firstname'] . ' ' . $row['lastname'] . '</p>';                 }                  ?>             </div> 

working webpage

but when use same code within content php file error this:

<?php  $title = "jobs"; $content = '     <?php      $server = '192.168.56.2';     $username = 'student';     $password = 'student';     $schema = 'travelcompanydatabase';      $pdo = new pdo('mysql:dbname=' . $schema . ';host=' . $server, $username, $password);     $results = $pdo->query('select * user');      foreach ($results $row)     {         echo '<p>' . $row['firstname'] . ' ' . $row['lastname'] . '</p>';     }      ?> ';  include 'template.php';  ?> 

webpage displaying error

it's better if this:

<?php $title = "jobs"; $content = ''; // create empty string  $server = '192.168.56.2'; $username = 'student'; $password = 'student'; $schema = 'travelcompanydatabase';  $pdo = new pdo('mysql:dbname=' . $schema . ';host=' . $server, $username, $password); $results = $pdo->query('select * user');  foreach ($results $row) {    // add every result $content using .=     $content .= '<p>' . $row['firstname'] . ' ' . $row['lastname'] . '</p>'; }  echo $content; 

Comments

Popular posts from this blog

how to insert data php javascript mysql with multiple array session 2 -

multithreading - Exception in Application constructor -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -