for loop using the variable count
im using PHP & MYSQL
MOD still dont get it
i searched on the net and found a sql function SELECT COUNT,
how can i use it and used its variable in a FOR LOOP
again this is my code
PHP Code:
<?php
$invoice_no=$_GET['invoice_no'];
include("conn_db.php");
require('fpdf.php');
$result = mysql_query ("SELECT date, invoice_no, customer, address, business_style, tin, total_sales, tax, total_amount, prepared_by, approved_by, released_by
FROM cash_invoice AS ci
WHERE ci.invoice_no = '$invoice_no'");
while($row = mysql_fetch_array($result))
{
$date = $row["date"];
$invoice_no = $row["invoice_no"];
$customer = $row["customer"];
$address = $row["address"];
$business_style = $row["business_style"];
$tin = $row["tin"];
$total_sales = $row["total_sales"];
$tax = $row["tax"];
$total_amount = $row["total_amount"];
$prepared_by = $row["prepared_by"];
$released_by = $row["released_by"];
$approved_by = $row["approved_by"];
}
$pdf=new FPDF();
$pdf->Open();
$pdf->AddPage();
//Arial bold 15
$pdf->SetFont('Times','B',15);
//Document Number
$pdf->Cell(200,25,$invoice_no,0,0,'R');
$pdf->ln(30);
$pdf->Cell(10);
$pdf->Cell(30,20,$customer,0,0,'L');
$pdf->Cell(160,20,$tin,0,0,'R');
$pdf->ln(10);
$pdf->Cell(10);
$pdf->Cell(30,25,$address,0,0,'L');
$pdf->Cell(80,25,$business_style,0,0,'R');
$pdf->Cell(80,25,$date,0,0,'R');
$pdf->ln(5);
$pdf->SetFont('Arial','B',11);
$prod ="SELECT p.description, ip.qty, ip.unit_price, ip.total, ip.invoice_no
FROM invoice_products as ip
LEFT JOIN product as p on p.prod_id = ip.prod_id
LEFT JOIN cash_invoice as ci ON ci.invoice_no = ip.invoice_no
WHERE ip.invoice_no='$invoice_no'";
$result=mysql_query($prod);
while($row=mysql_fetch_array($result))
{
$description=$row["description"];
$qty=$row["qty"];
$unit_price=$row["unit_price"];
$total=$row["total"];
$pdf->ln(4);
$pdf->Cell(20,50,$qty,0,0,'L');
$pdf->Cell(120,50,$description,0,0,'L');
$pdf->Cell(40,50,$unit_price,0,0,'L');
$pdf->Cell(30,50,$total,0,0,'L');
}
$pdf->ln(5);
$pdf->Cell(5,80,$prepared_by,0,0,'L');
$pdf->Cell(80,80,$approved_by,0,0,'R');
$pdf->Cell(35,80,$released_by,0,0,'R');
//New Line
$pdf->ln(5);
//Arial bold 15
$pdf->SetFont('Arial','B',12);
$pdf->Cell(10);
$pdf->ln(5);
$pdf->Cell(200,50,$total_sales,0,0,'R');
$pdf->ln(5);
$pdf->Cell(200,50,$tax,0,0,'R');
$pdf->ln(5);
$pdf->Cell(200,50,$total_amount,0,0,'R');
$pdf->Output();
?>
Re: for loop using the variable count
Rather than using SELECT COUNT which is having a MySQL return the number of rows, why don't you just use mysql_num_rows(). This will use PHP to count the returned rows right into a PHP variable.
Re: for loop using the variable count