如何从SQL中选择代码和id的产品

时间:2011-10-09 15:57:44

标签: mysql select printing

我有一个SQL表:

CREATE TABLE IF NOT EXISTS `orders` (
  `id` int(11) NOT NULL auto_increment,
  `order_name` text NOT NULL,
  `order_q` text NOT NULL,
  `order_price` text NOT NULL,
  `order_id` text NOT NULL,
  `code` text NOT NULL,
  `order_date` text NOT NULL,
  `stat` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=cp1256 AUTO_INCREMENT=6 ;

我想逐行打印两行:

1- order_id

2- code

此脚本看起来像购物脚本,因此当客户端下订单时,脚本会自动打印出发票。

我该怎么办?

我的代码:

<?
    include("config.php");
    $print = 'onload="window.print();
    "'; $code_num="123456";
    $result = mysql_query("SELECT * FROM orders WHERE stat='0' && code='$code_num' order by id ASC limit 1");
    while($row = mysql_fetch_array($result))
    {
        echo $row[order_name];
    }
?>

1 个答案:

答案 0 :(得分:0)

我不确定你要做什么,但是下面的代码是否可以解决这个问题?我没有测试它,但它非常简单。另请参阅 SQL ORDER BY Keyword PHP MySQL Order By Keyword

$query = "SELECT * FROM orders ORDER BY order_id, code";
$result = mysql_query($query)or die(mysql_error());

while($row = mysql_fetch_array($result)){
    echo $row['order_name'];//echo the parts you need
}