Php mysql从col1中选择不同的行,其中col2=x
我试图从“特定”中选择不同的名称,但仅限于col Type=特定值的情况 例如,我有Php mysql从col1中选择不同的行,其中col2=x,php,mysql,distinct,Php,Mysql,Distinct,我试图从“特定”中选择不同的名称,但仅限于col Type=特定值的情况 例如,我有 rowID Type Specifically 1 cat Ocicat 2 cat Bombay 3 cat Bombay 4 cat Bengal 5 cat Savannah 6 dog Collie 7 dog Keeshond 8 dog
rowID Type Specifically
1 cat Ocicat
2 cat Bombay
3 cat Bombay
4 cat Bengal
5 cat Savannah
6 dog Collie
7 dog Keeshond
8 dog Pug
9 dog Keeshond
10 dog Pug
11 dog Doberman
12 Horse n/a
我想读一些像
type=cat and specific=Bengal
type=cat and specific=Bombay
type=cat and specific=Ocicat
type=cat and specific=Savannah
我目前有这个,但它给了我“未定义的索引:类型”
$Result = mysql_query("select distinct Specifically from pet_table WHERE Type='cat' ORDER BY Specifically asc ");
while($row = mysql_fetch_array($Result))
{
PRINT("type=".$row['Type']." and specific=".$row['Specifically']."<BR>");
}
$Result=mysql\u query(“选择与pet\u表不同,其中Type='cat'按特定asc排序”);
while($row=mysql\u fetch\u数组($Result))
{
打印(“type=“.$row['type']”和specific=“.$row['specified']”和“
”;
}
我还想做一些事情,比如类型不是猫、狗或马。。。ect
谢谢您要分组吗
SELECT Type, Specifically FROM pet_table
WHERE Type='cat'
GROUP BY Specifically
ORDER BY Specifically asc
你要分组吗
SELECT Type, Specifically FROM pet_table
WHERE Type='cat'
GROUP BY Specifically
ORDER BY Specifically asc
索引不存在,因为您没有选择它。在
SELECT
语句中包含Type
以修复它。索引不存在,因为您没有选择它。在SELECT
语句中包含Type
以修复它。您会得到未定义的索引错误,因为您没有获取Type
列,而是试图使用它
将查询更改为
select type, distinct Specifically from pet_table
WHERE Type='cat' ORDER BY Specifically asc
其次,如果您不希望键入cat、dog或horse,可以使用notin
子句
最后,请不要使用MySQL,因为它没有维护,并且已被弃用。考虑使用,MyQuLi或PDO。< p>您得到未定义的索引错误,因为您没有获取
select type, distinct Specifically from pet_table
WHERE Type='cat' ORDER BY Specifically asc
其次,如果您不希望键入cat、dog或horse,可以使用notin
子句
最后,请不要使用MySQL,因为它没有维护,并且已被弃用。考虑使用,MyQuLi或PDO。< P>你得到这个错误的原因是因为你没有选择<代码>类型< /C> > < /P>
$res = mysql_query("SELECT DISTINCT `Specifically`,`Type` from `pet_table` WHERE `Type`='cat' ORDER BY `Specifically` ASC");
while($row = mysql_fetch_assoc($res))
{
echo "The type is {$row['Type']} and it is specifically a {$row['Specifically']}
}
出现此错误的原因是您没有选择
类型
$res = mysql_query("SELECT DISTINCT `Specifically`,`Type` from `pet_table` WHERE `Type`='cat' ORDER BY `Specifically` ASC");
while($row = mysql_fetch_assoc($res))
{
echo "The type is {$row['Type']} and it is specifically a {$row['Specifically']}
}
他还需要
类型
列他还需要类型
列