我正在MYSQL表上运行SELECT代码
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."%' ";
<?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 '.$row['mainitemname2'].' ('.$row['mainitemtype2'].')</strong></td>
</tr>';
}
# $total += $row['amount'];
# $no++;
}?>
您可以转到http://www.marscafe.com/php/wfdinner_ALL_DINNER_results25-9.12(IF).php
查看结果答案 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', '%')
)