mysql_fetch_array(),在我的程序中不起作用

时间:2015-01-22 11:28:24

标签: php html mysql

我需要从mysql表中获取多行或单行,但我的代码只从表中检索数据,如我的where子句条件为true,即使我的条件为真,也不会获取单行。 PLZ建议我任何人。 (我只知道一点点英语)

<?php 
include 'connection/db_connection.php';

 $sqlquery=mysql_query("select * from sadmin_invoiceno order by sno desc");
 $row1=mysql_fetch_assoc($sqlquery);
    $invoice=$row1['invoice_no'];
    /* if($row1['invoice_no']<=9)
    {
    $myvalue=$row1['invoice_no'];
    $idvalue="".$myvalue;   
    }
    if($row1['invoice_no']>9 && $row1['sno']<100)
    {
    $myvalue=$row1['invoice_no'];
    $idvalue="".$myvalue;   
    } */
        $sql="SELECT * FROM sadmin_sales where invoice_no='".$invoice."'";
        $result = mysql_query($sql);
        $count=mysql_num_rows($result);



?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <title>IT Flower invoice</title>
    <link rel="stylesheet" href="assets/css/style_popup.css" media="all" />
 <link href="assets/css/utopia-white.css" rel="stylesheet">
  </head>
  <body>

  <div class="invoice">
    <header class="clearfix">
      <div id="logo">
        <img src="assets/img/utopia-logo1.png">
      </div>
      <div id="company">
        <h2 class="name">Indian Traditional Flowers</h2>
        <div>10 - 3500 McNicoll Ave., <br>Toronto, Ontario ON M1V 4c7</div>
        <div>+1.647.836.9999</div>
        <div><a href="mailto:info@itflowers.com">info@itflowers.com</a></div>
      </div>

    </header>
    <main>
      <div id="details" class="clearfix">
        <div id="client">
          <div class="to">INVOICE TO:</div>
          <h2 class="name"><?php 
          $sql2=mysql_query("SELECT franchies, customer FROM sadmin_sales where invoice_no='".$invoice."'");
          $res1=mysql_fetch_array($sql2);echo $res1['customer']; 
          $franchies= $res1['franchies'];

          $sql3=mysql_query("SELECT * FROM sadmin_customer where email='".$franchies."'");
           $res2=mysql_fetch_array($sql3);
          echo $res2['shop_name'];
          ?></h2>

         <div class="address"> <?php echo $res2['owner_name']; ?> </div>
          <div class="address"><?php echo $res2['address']; ?></div>
          <div class="email"><?php echo $res2['email']; ?></div>
             <div class="email"><?php echo $res2['phone']; ?></div>
        </div>
        <div id="invoice">
          <h1>INVOICE NO: <?php echo $invoice; ?></h1>
          <div class="date">Date of Invoice: <?php echo $date = date('d/m/Y h:i:s a'); ; ?></div>

        </div>
      </div>
      <table class="inventory" border="0" cellspacing="0" cellpadding="0">
        <thead>
          <tr style="text-align: center;">
            <th class="no">#</th>
            <th class="desc">DESCRIPTION</th>
            <th class="unit">UNIT PRICE</th>
            <th class="qty">QUANTITY</th>
            <th class="total">TOTAL</th>
          </tr>
        </thead>
        <tbody>
        <tr>

        <?php
        $tax=0;
        $ship=0;
        $paid=0;
        $bal=0;
        $grand=0;

        $sum=0;
        for($i=1; $i<$count;)
        {
        while($row = mysql_fetch_array($result))
        {

        $franchies = $row['franchies'];

        echo "<td class='no'>".$i."</td> ";
        echo "<td class='desc'>" . $row['product_name'] . "</td>";
        echo "<td class='unit'>" . $row['unit_price'] . "</td>";
        echo "<td class='qty'>" . $row['quantity'] . "</td>";
        echo "<td  class='total' >".$row['total']."</td>";
        echo "</tr>"; 
        $sum=$sum + $row['total'];
        $i++;
        //$tax=$sum *.13;
        $include=$row['tax_type'];

        if ($include =='includetax')
        { 
            $tax1=mysql_query("select * from sadmin_tax  where tax_type like 'include%'");
            $res1=mysql_fetch_array($tax1);
            $tax2=$res1['percentage'];
            $tax=$sum * $tax2/100;
            $sum1=$sum - $tax;

        } 
        else
        { 
            $tax3=mysql_query("select * from sadmin_tax  where tax_type like 'exclude%'");
            $res3=mysql_fetch_array($tax3);
            $tax4=$res3['percentage'];
            $tax=$sum * $tax4/100;
            $sum1=$sum + $tax;

        }

        $ship=$row['shipping_amt'];
        $paid=$row['paid_amt'];

        $grand=$sum1 + $ship;
        $bal=$grand - $paid;

        }
        }
        ?>



        </tbody>
        <tfoot>
          <tr>
            <td colspan="2"></td>
            <td colspan="2">SUBTOTAL</td>
            <td>$ <?php echo $sum; ?></td>
          </tr>
          <tr>
            <td colspan="2"></td>
            <td colspan="2">TAX 13%</td>
            <td>$ <?php echo $tax; ?></td>
          </tr>
            <tr>
            <td colspan="2"></td>
            <td colspan="2">SHIP</td>
            <td>$<?php echo $ship; ?></td>
          </tr>
          <tr>
            <td colspan="2"></td>
            <td colspan="2">PAID</td>
            <td>$<?php echo $paid; ?></td>
          </tr>
           <tr>
            <td colspan="2"></td>
            <td colspan="2">BALANCE</td>
            <td>$<?php echo $bal; ?></td>
          </tr>
          <tr>
            <td colspan="2"></td>
            <td colspan="2">GRAND TOTAL</td>
            <td>$<?php echo $grand; ?></td>

          </tr>

        </tfoot>
      </table>
<button onclick="myFunction()" class="btn btn-primary" style="width: 106px;float: right;">Print this page</button>

     <!--  <div id="thanks">Thank you!</div>
      <div id="notices">
        <div>NOTICE:</div>
        <div class="notice">A finance charge of 1.5% will be made on unpaid balances after 30 days.</div>
      </div>
    </main>
    <footer>
      Invoice was created on a computer and is valid without the signature and seal.
    </footer> -->
</div>

<script>
function myFunction() {
    window.print();
}
</script>
  </body>
</html>

1 个答案:

答案 0 :(得分:0)

我不确定我完全理解你的问题,你是说你有多行而只想要一个?

如果是这样,请查看MySQL&#34; LIMIT&#34;这会将您的SQL查询限制为X行数,例如SELECT * FROM sadmin_customer where email='".$franchies." LIMIT 1

这将只返回1行,条件为真的第一行。