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

标签 php html mysql

我需要从 mysql 表中获取多行或单行,但我的代码仅从表中检索数据,如我的 where 子句条件为 true 中给出的多行,即使我的条件为 true,也不会获取单行。请向我推荐任何人。 (我只懂一点英语)

<?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>

最佳答案

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

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

这将仅返回 1 行,即条件为 true 的第一行。

关于php - mysql_fetch_array(),在我的程序中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28087643/

相关文章:

javascript - 从多个表单中选择特定元素

javascript - Dojo:过滤选择模板

mysql - MariaDB 备份工具 Mariabackup 失败并出现错误

mysql - 您如何监控复制和客户端证书的 MariaDB SSL 到期?

php - 每月最后一天自动添加到数据库

php - Controller 命名空间必须以您的应用程序命名空间 : App</error > 开头

html - 如何创建像这个网站一样的 pin unpin 效果?

mysql - 从 MySQL 中的两个不同表中进行 SELECT 和 COUNT

php - 如何连接到另一台服务器上的数据库?

php - Laravel 测试时创建数据库