开发者

How to select a product from SQL where code and id

开发者 https://www.devze.com 2023-04-11 14:55 出处:网络
I have an SQL table: CREATE TABLE IF NOT EXISTS `orders` ( `id` int(11) NOT NULL auto_increment, `order_name` text NOT NULL,

I have an SQL table:

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` 开发者_如何学Ctext NOT NULL,
  `stat` text NOT NULL,
  PRIMARY KEY  (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=cp1256 AUTO_INCREMENT=6 ;

I want to print out the rows one by one order by two rows:

1- order_id

2- code

This script looks like a shopping script, so when the clients are making the order, the script is automatically printing out the invoice.

What should I do?

My 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];
    }
?>


I am not really sure what you're trying to do, but does the following code do the trick? I haven't tested it, but it's pretty straightforward. See also SQL ORDER BY Keyword and 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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号