没有使显示/回声过快

时间:2019-07-13 08:37:41

标签: php mysql

我正在MYSQL表上运行SELECT代码

我有一个MYSQL表:

CREATE TABLE mytable (
wf_id int(11) UNSIGNED NOT NULL,
session varchar(255) NOT NULL,
s varchar(60) DEFAULT NULL,
time timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
menudate varchar(80) DEFAULT NULL,
mainitemname1 varchar(160) DEFAULT NULL,
mainitemdescription1 varchar(350) DEFAULT NULL,
mainitemtype1 varchar(80) DEFAULT NULL,
mainitemname2 varchar(160) DEFAULT NULL,
mainitemdescription2 varchar(350) DEFAULT NULL,
mainitemtype2 varchar(80) DEFAULT NULL,
dessert varchar(320) DEFAULT NULL,
dessertnsa varchar(320) DEFAULT NULL,
mainitemcomment varchar(500) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

我正在其上运行以下SELECT代码:

$sql=" SELECT * FROM mytable WHERE mainitemtype1 like ``'%".o."%'   
OR mainitemtype2 like '%".o."%'      
AND mainitemtype1 NOT like '%".m."%'   
OR mainitemtype1 NOT   like '%".p."%'   
OR mainitemtype1 NOT like '%".c."%'    
OR   mainitemtype1 NOT like '%".s."%'    
AND mainitemtype2 NOT like '%".m."%'   
OR mainitemtype2 NOT   like '%".p."%'   
OR mainitemtype2 NOT like '%".c."%'    
OR mainitemtype2 NOT like '%".s."%' ";  

我只想在网页上显示/回显o型的mainitemtype1和mainitemtype2(有5种不同类型的mainitemtype分类[o,s,m,c,p],下面是代码I正在使用,但没有显示我想要的东西。我想要的东西可能吗?

<?php
$no     = 1;
$total  = 0;
while ($row = mysqli_fetch_array($query))
{
$amount  = $row['amount'] == 0 ? '' : number_format($row['amount']) 
if ($row['mainitemtype1'] == o OR $row['mainitemtype2'] == o)
{
echo '<tr>
<td><strong><font color=red> (start new record)</strong> </font> '.$row['menudate'].'</td>
<td><strong>'.$row['mainitemname1'].'  ('.$row['mainitemtype1'].') AND &nbsp; &nbsp; '.$row['mainitemname2'].'   ('.$row['mainitemtype2'].')</strong></td>                  
</tr>';
}
# $total += $row['amount'];
# $no++;
}?>

您可以转到http://www.marscafe.com/php/wfdinner_ALL_DINNER_results25-9.12(IF).php

查看结果

1 个答案:

答案 0 :(得分:1)

如果仅需要类型为o的行 您可以尝试

SELECT * 
FROM mytable 
WHERE  mainitemtype1 like concat('%', 'o', '%') 
OR mainitemtype2 like concat('%', 'o', '%') 
AND  NOT  (
    mainitemtype1  like concat('%', 'm', '%') 
    OR mainitemtype2 like concat('%', 'm', '%') 
    OR mainitemtype1  like concat('%', 'p', '%') 
    OR mainitemtype2 like concat('%', 'p', '%') 
    OR mainitemtype1  like concat('%', 'c', '%') 
    OR mainitemtype2 like concat('%', 'c', '%') 
    OR mainitemtype1  like concat('%', 's', '%') 
    OR mainitemtype2 like concat('%', 's', '%') 
)