for loop using the variable count
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3

Thread: for loop using the variable count

  1. #1
    Join Date
    Dec 2008
    Posts
    27

    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();
        
    ?>
    Last edited by PeejAvery; January 6th, 2009 at 08:09 AM. Reason: Added PHP tags.

  2. #2
    PeejAvery's Avatar
    PeejAvery is offline Super Moderator Power Poster
    Join Date
    May 2002
    Posts
    10,886

    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.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Dec 2008
    Posts
    27

    Re: for loop using the variable count

    got it MOD! tnx!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center