Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7017549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:55:43+00:00 2026-05-27T22:55:43+00:00

I am putting a whole HTML content inside a PHP variable and inside that

  • 0

I am putting a whole HTML content inside a PHP variable and inside that content I am trying to echo some data fetching from database. But the problem is I cannot make the database query and echo the reuslt as the whole thing is wrapped with PHP and then HTML.(if it sounds confusing please check the code below.)

Is there any way to make the database query outside the PHP variable and echo it. Although I have already tried querying the database outside the variable but as it turned out this time >> $row['examdate'] is creating the problem. It shows an syntax error.

I am doing all these to generate PDF using DOMPDF. After getting the variable I will pass it to my controller to generate the pdf.

 <?php $variable= " I need your help, I want to echo this <br>

<table id=\"table-6\" width=\"100%\">
<tr>
    <th>Exam Date</th>
    <th>Exam Type</th>
    <th>Subject</th>

</tr>

$this->db->select('*');
$this->db->from('marks');
$this->db->where('studentid', $studentid);
$this->db->where('examdate >=', $daterange1);
$this->db->where('examdate <=', $daterange2);
$this->db->order_by('examdate','DESC'); 
$query = $this->db->get(''); 


            if ($query->num_rows() > 0)
            {
               $row = $query->row_array();

    <tr>
        <td> echo $row['examdate']</td> ///****this line***** 

        <td>12</td>
        <td>12</td>
        <td>100</td>
    </tr>
    </table>
   "; ?>-<< variable ends here
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:55:44+00:00Added an answer on May 27, 2026 at 10:55 pm

    You need to separate the filling of your variable from the execution of your PHP logic.

    Append the data at a later stage instead of trying assign everything in one single step.

    Here is a modified code:

    <?php
    $variable = " I need your help, I want to echo this <br>
    
    <table id=\"table-6\" width=\"100%\">
        <tr>
            <th>Exam Date</th>
            <th>Exam Type</th>
            <th>Subject</th>
    
        </tr>
    ";
    
    // now execute the database logic
    $this->db->select('*');
    $this->db->from('marks');
    $this->db->where('studentid', $studentid);
    $this->db->where('examdate >=', $daterange1);
    $this->db->where('examdate <=', $daterange2);
    $this->db->order_by('examdate','DESC'); 
    $query = $this->db->get(''); 
    
    if ($query->num_rows() > 0)
    {
        $row = $query->row_array();
    
        // append the data to the existing variable using ".="
        // and include the examdate
        $variable .= "
            <tr>
                <td>{$row['examdate']}</td> ///****this line***** 
    
                <td>12</td>
                <td>12</td>
                <td>100</td>
            </tr>
        ";
    }
    
    // append the closing table tag to the variable using ".=" again
    $variable .= "</table>";
    
    // output $variable
    echo $variable;
    

    ?>

     

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have one table which display data as from Dynamic Content in 1 column.
Revised: I have a list items on the page that I'm creating from database
I'm trying to execute some inline javascript within an HTML page as early in
I want my android app to get data from an online database. Here are
Update Putting this at the top because it is crazy :) So some users
I putting together a page that will display a set of stored values. I
I've been putting a lot of thought into procedural generation of content for a
I'm putting together some demo pages, and one of the things I want to
I'm loading image tags via AJAX and inserting them with the conventional .html(content) function
I'm writing some html to be shown in the screen and sent by e-mail

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.