php - Loop through database and display them in new file -


i have script loops through database , displays of it's contents.

$select_report = $conn->prepare("select test_db report"); $select_report->execute(); while ($result_report = $select_report->fetch(pdo::fetch_assoc)){    echo $result_report["test_db"]; } 

my question is, can create html file has looped content? tried using script displays last row in generated html file.

$select_report = $conn->prepare("select test_db report"); $select_report->execute(); while ($result_report = $select_report->fetch(pdo::fetch_assoc)){    $html_report = "                 <!doctype html>                 <html>                 <head>                 <title>sales report</head>                 </head>                 <body>                   <div class='container'>                     <table>                         <thead>                            <tr>                              <th>test</th>                            </tr>                         </thead>                         <tbody>                            <tr>                              <th>". $result_report["test_db"] ."</th>                            </tr>                         </tbody>                     </table>                   </div>                </body>                </html>                   "; $myfile = fopen("report - ".date("m, d, s").".html", "w") or die("unable open file!"); fwrite($myfile, $html_report); fclose($myfile); } 

image:

generated html table

it matter of looping items (in case table rows) need looped:

$select_report = $conn->prepare("select test_db report"); $select_report->execute(); $html_report = "                 <!doctype html>                 <html>                 <head>                 <title>sales report</head>                 </head>                 <body>                   <div class='container'>                     <table>                         <thead>";  while ($result_report = $select_report->fetch(pdo::fetch_assoc)){    // concatenate rows    $html_report .= "<tr>                              <th>test</th>                            </tr>                         </thead>                         <tbody>                            <tr>                              <th>". $result_report["test_db"] ."</th>                            </tr>                         </tbody>"; } // outside of loop     $html_report .= "</table>                   </div>                </body>                </html>                   ";  $myfile = fopen("report - ".date("m, d, s").".html", "w") or die("unable open file!");  fwrite($myfile, $html_report); fclose($myfile); 

Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -