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

  • SEARCH
  • Home
  • 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 9050113
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T12:34:26+00:00 2026-06-16T12:34:26+00:00

I am having some trouble with multidimensional array and its value. What i am

  • 0

I am having some trouble with multidimensional array and its value.

What i am looking for is , from my query I am searching teachers name in the array. And after that i want to create a pdf using dompdf. The problem is with looping. I am not able to create a proper loop which will work the way I want it to work. My sample query is

    $q11 = "select id from teachers order by teacher ";
    $r11 = mysql_query($q11) or die(mysql_error());
    while($rows11 = mysql_fetch_array($r11)){
        $teacher = $rows11['id'];
        $dompdf->"It will start working";
    }

Now i know , this code is confusing, but what i want is, it should create dompdf for every teacher in one single pdf file. Like from the query it should fetch teachers, and for each teacher it should create a dompdf page. Currently it is making just one page according to the last value that my query has search.

Please help. It is kinda urgent.

  • 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-06-16T12:34:29+00:00Added an answer on June 16, 2026 at 12:34 pm

    Your loop is working fine. The way you add pages to your PDF is probably wrong. Apparently you are overwriting one page again and again instead of attaching a new one.

    EDIT

    I’ve never used dompdf. A quick look into the docs let me think you create something like a HTML markup which then is converted into PDF, did I get this right?

    Example code

    $html = <<<HTML
      <html>
          <head>
                <style type="text/css">
                    /* Your document styling goes here */
                </style>
          </head>
          <body>
    HTML;
    
    while ( $row = $dbResult->fetch_assoc() ) {
        $html .= '<div class="teacherPage">'
                     . $row['name'] // your teacher document goes here
                 '</div>';
    }
    
    $html .= '</body></html>';
    
    $dompdf = new DOMPDF();
    $dompdf->load_html($html);
    $dompdf->render();
    $dompdf->stream("sample.pdf");
    

    If you wonder about the unusual syntax $var = <<<HTML \r\nHTML, that’s a heredoc. It’s just more comfortable to use heredocs when you have a lot of alien inline code, this can have variables {$varname} and you don’t need to worry about quotes. All you need to make sure, is that heredoc closer HTML is in a new line and not indented.

    EDIT2

    Still not too sure, which library you are using. I find this extension looking pretty good and it’s called dompdf, just like you said in your question.

    Your latest comment indicates you did not solve your problem so far, so I decided to add some more information to get you to the target.

    Disclaimer: I am not going to write functional code and I will not test this, but the following hints will push you into the right direction to get your stuff done.

    dompdf is able to read CSS2 and CSS3 properties of your input document.

    Each cycle in the while loop above represents one teacher whith each of them getting a own page in the output document.

    I put the page into a div container with the class teacherPage. You can fill this container with all the information you want to have displayed for a teacher.

    Now all we need to do, is to tell dompdf each teacherPage is a new page. This can be done using @page markup shipped with CSS3

    I added an empty css container <style type="text/css"></style> to the example document above, that’s where the page styling should go to.

    The example CSS

    @page teacher {
      size: A4 portrait;
      margin: 2cm;
    }
    
    .teacherPage {
       page: teacher;
       page-break-after: always;
    }
    

    With @page you can define a named page teacher, which can have properties valid for the whole page container.

    page-break-after: always will begin a new page after each container

    Hope this helps, have fun trying 🙂

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

Sidebar

Related Questions

I am dynamically trying to populate a multidimensional array and having some trouble. I
Having some trouble getting this query to work correctly. mysql_query(DELETE FROM `table` WHERE `id`
Having some trouble issuing a simple query from the PHP Mongo driver. This is
I´m having some trouble retrieving a collection of strings in a projection: say that
Having some trouble looping through these arrays , i have 4 properties that identical
Having some trouble sending properly formatted HTML e-mail from a PHP script. I am
Having some trouble figuring out why my ImageView buttons stop working after I change
Having some trouble passing values from one class to another. I basically have a
having some trouble with a Thread (CanvasThread) that is intermittently pausing at random points
After having some trouble with setting up a thread to start my MIDI sequencer

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.