我试图从“Specifically”中选择不同的名称,但仅限于 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
我目前有这个,但它给了我“ undefined index :类型”
$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>");
}
我还想做一些类似类型不是猫或狗或马的事情......等等
谢谢
最佳答案
索引不存在,因为您没有选择它。在您的 SELECT
语句中包含 Type
以修复它。
关于php - mysql SELECT distinct row from col1 WHERE col2=x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15368483/