honkmaster Posted March 6 Share Posted March 6 (edited) Hi have a simple query which should retrieve 4 lines from database and display in HTML table but only 3 lines displaying??? This is the query which when I test works SELECT * FROM stock_material WHERE stock_material.material_catagory = 'B2 Indigo' AND stock_material.material_status = 'Active' See Screen shot from mySQL Database When the pdf is output it returns 3 results not 4 missing the first 1 This is the part generating the table $pdf->SetFont('Helvetica', 'B', 32); $pdf->SetTextColor(0, 0, 0); $pdf->Text(10,10, "Stock Check"); $pdf->SetXY(10, 30); $pdf->SetFont('helvetica', '', 9); $totalRows_rsB2Indigo > mysql_num_rows($rsB2Indigo); { $tbl = '<table style="width: 650px;" cellpadding="3" cellspacing="0">'; $tbl = $tbl . '<tr bgcolor="#CCCCCC"> <td style="border: 1px solid #000000; width: 60px; text-align:center"><strong>Id</strong></td> <td style="border: 1px solid #000000; width: 120px; text-align:center"><strong>Name</strong></td> <td style="border: 1px solid #000000; width: 60px;"><strong>Stock</strong></td> <td style="border: 1px solid #000000; width: 60px;"><strong>Allocated</strong></td> </tr>'; while($row_rsB2Indigo = mysql_fetch_assoc($rsB2Indigo,MYSQL_ASSOC)){ $id = $row_rsB2Indigo['material_id']; $name = $row_rsB2Indigo['material_name']; $Stock = $row_rsB2Indigo['material_stock']; $allocation = $row_rsB2Indigo['materia_allocated']; $tbl = $tbl . '<tr> <td style="border: 1px solid #000000; width: 60px; text-align:center"><strong>'.$id.'</strong></td> <td style="border: 1px solid #000000; width: 120px; text-align:center"><strong>'.$name.'</strong></td> <td style="border: 1px solid #000000; width: 60px;">'.$Stock.'</td> <td style="border: 1px solid #000000; width: 60px;">'.$allocation.'</td> </tr>'; } $tbl = $tbl . '</table>'; } // Print text using writeHTMLCell() $pdf->writeHTML($tbl, true, true, true, false, ''); I'm not sure where i'm going wrong, any help would be great Edited March 6 by honkmaster Quote Link to comment https://forums.phpfreaks.com/topic/318816-tcpdf-html-table-output/ Share on other sites More sharing options...
mac_gyver Posted March 6 Share Posted March 6 you likely have a single ...fetch() statement somewhere between where you have executed the sql query and the code you did post. btw - the mysql_ extension has been removed from php for a very long time. you should both update your php version to 8+ and switch to the PDO extension. Quote Link to comment https://forums.phpfreaks.com/topic/318816-tcpdf-html-table-output/#findComment-1617311 Share on other sites More sharing options...
honkmaster Posted March 6 Author Share Posted March 6 Thanks, yes we are going update soon Below is the code but no fetch() mysql_select_db($database_workflow, $workflow); $query_rsB2Indigo = "SELECT * FROM stock_material WHERE stock_material.material_catagory = 'B2 Indigo' AND stock_material.material_status = 'Active'"; $rsB2Indigo = mysql_query($query_rsB2Indigo, $workflow) or die(mysql_error()); $row_rsB2Indigo = mysql_fetch_assoc($rsB2Indigo); $totalRows_rsB2Indigo = mysql_num_rows($rsB2Indigo); ob_end_clean(); $pdf = new TCPDF(); // add a page $resolution= array(210, 297); // set margins $pdf->SetAutoPageBreak(true, 20); $pdf->setCellMargins(0, 0, 0, 0); $pdf->setCellPaddings(0, 0, 0, 0); // Set default header/footer $pdf->setPrintHeader(false); $pdf->setPrintFooter(false); // set default font subsetting mode $pdf->setFontSubsetting(true); $pdf->AddPage(); // Set some content to print $pdf->SetFont('Helvetica', 'B', 32); $pdf->SetTextColor(0, 0, 0); $pdf->Text(10,10, "Stock Check"); $pdf->SetXY(10, 30); $pdf->SetFont('helvetica', '', 9); $totalRows_rsB2Indigo > mysql_num_rows($rsB2Indigo); { $tbl = '<table style="width: 650px;" cellpadding="3" cellspacing="0">'; $tbl = $tbl . '<tr bgcolor="#CCCCCC"> <td style="border: 1px solid #000000; width: 60px; text-align:center"><strong>Id</strong></td> <td style="border: 1px solid #000000; width: 120px; text-align:center"><strong>Name</strong></td> <td style="border: 1px solid #000000; width: 60px;"><strong>Stock</strong></td> <td style="border: 1px solid #000000; width: 60px;"><strong>Allocated</strong></td> </tr>'; while($row_rsB2Indigo = mysql_fetch_assoc($rsB2Indigo,MYSQL_ASSOC)){ $id = $row_rsB2Indigo['material_id']; $name = $row_rsB2Indigo['material_name']; $Stock = $row_rsB2Indigo['material_stock']; $allocation = $row_rsB2Indigo['materia_allocated']; $tbl = $tbl . '<tr> <td style="border: 1px solid #000000; width: 60px; text-align:center"><strong>'.$id.'</strong></td> <td style="border: 1px solid #000000; width: 120px; text-align:center"><strong>'.$name.'</strong></td> <td style="border: 1px solid #000000; width: 60px;">'.$Stock.'</td> <td style="border: 1px solid #000000; width: 60px;">'.$allocation.'</td> </tr>'; } $tbl = $tbl . '</table>'; } // Print text using writeHTMLCell() $pdf->writeHTML($tbl, true, true, true, false, ''); Quote Link to comment https://forums.phpfreaks.com/topic/318816-tcpdf-html-table-output/#findComment-1617312 Share on other sites More sharing options...
Barand Posted March 6 Share Posted March 6 4 minutes ago, honkmaster said: Below is the code but no fetch() ... then what do think that is on line 4? Quote Link to comment https://forums.phpfreaks.com/topic/318816-tcpdf-html-table-output/#findComment-1617313 Share on other sites More sharing options...
honkmaster Posted March 6 Author Share Posted March 6 Thank you so much, removed and it worked perfect. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/318816-tcpdf-html-table-output/#findComment-1617315 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.