Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/290.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php mysql从col1中选择不同的行,其中col2=x_Php_Mysql_Distinct - Fatal编程技术网

Php mysql从col1中选择不同的行,其中col2=x

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

我试图从“特定”中选择不同的名称,但仅限于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    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>您得到未定义的索引错误,因为您没有获取Type 列,但正在尝试使用。 将查询更改为

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']}
}

他还需要
类型
列他还需要
类型