Jump to content

Recommended Posts

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

Table.jpg

result.jpg

Edited by honkmaster
Link to comment
https://forums.phpfreaks.com/topic/318816-tcpdf-html-table-output/
Share on other sites

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.

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, '');

 

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.