简体   繁体   English

PHP,MYSQL 仅获取结果数组的第一行和第二行

[英]PHP, MYSQL get 1st and second row only of result array

I have a query that result like this.我有一个查询结果是这样的。

SELECT check.c_id, check.voucher, check.payee, check.c_date, transact.atc_code, transact.value
    FROM `check`
    LEFT JOIN `transact`
    ON check.c_id = transact.t_id
    WHERE t_id='1' AND (atc_code LIKE '%72%' OR atc_code LIKE '%35%')
    ORDER BY check.c_id
"c_id"   "voucher"      "payee"                     "c_date"        "atc_code"      "value"
"1"      "PDMK162953"   "TOYOTA GLOBAL CITY, INC."  "04/11/2016"    "MK-GF-7202"    "10338.44"
"1"      "PDMK162953"   "TOYOTA GLOBAL CITY, INC."  "04/11/2016"    "MK-GF-3505"    "206.77"
while($row = $result->fetch_assoc()) {
    $c_id = $row['c_id'];
    $voucher = $row['voucher'];
    $payee = $row['payee'];
    $c_date = strtotime($row['c_date']);
    $atc_code = $row['atc_code'];
    $income = $row['value'];
    $tax = $row['value'];
}

How will i able to echo out the column 'value' to table first cell 10338.44 and 206.77 in the other cell of the table in html我将如何将列“值”回显到 html 表格的另一个单元格中的第一个单元格 10338.44 和 206.77

Just mention limit in your query.只需在您的查询中提及限制。

SELECT check.c_id, check.voucher, check.payee, check.c_date, transact.atc_code, transact.value
FROM `check`
LEFT JOIN `transact`
ON check.c_id = transact.t_id
WHERE t_id='1' AND (atc_code LIKE '%72%' OR atc_code LIKE '%35%')
ORDER BY check.c_id
LIMIT 2    // Add this

Showing records in one row and two columns:在一行和两列中显示记录:

 <table border="1">
   <tr>
     <th>Tax 1</th>
     <th>Tax 2</th>
     <?php  while($row = $result->fetch_assoc()) { ?>
     <td>
       <?php  echo $row['value']; ?>
     </td>
     <?php } ?>
   </tr>
 </table>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM