我想在表中搜索另一列的每個成員的列並打印結果。我在PHP中編寫了一個for循環,但它太密集,因爲它涉及太多的查詢。我願意使用任何支持Web的語言。對另一列的每個成員搜索一列
$search1=mysql_query(SELECT COLUMN2 FROM TABLE WHERE COLUMN1 LIKE %Search_term%);
for($i=0; i < $search1->num_rows; $i++){
$search2=mysql_query(SELECT COLUMN1 FROM TABLE WHERE COLUMN1 LIKE %Seach_term% AND COLUMN1 LIKE 「%$search1[$i]%」 LIMIT 3);
echo 「$search2[0]」;
echo 「$search2[1]」;
echo 「$search2[2]」;
echo 「<P>」;
$i++;
}
有沒有辦法做到這一點,沒有做一個選擇語句for循環的每個實例?如果我可以選擇一次,然後在SQL中循環並對它進行排序或分組,我會非常高興。我查看了GROUPBY或SORTBY,但是我無法找到一個與此相關的示例來將其應用於此。
謝謝。
edit: example table
id column1 column2
1 walk park dog win for good walk
2 walk go forward do win dog go
3 park job forward daycare a park
4 go with me certified job I with
5 dolphin job park walk care dolphin
6 pack for good park go job for
7 leader forward win dog for leader
8 leader go forward win walk forward
9 tablet forward go walk for tablet
10 Jones job me certfied do go job
results of searching by column2 into column1:
walk go forward do win dog
dolphin job park walk care
leader go forward win walk
walk go forward do win dog
go with me certified job I
pack for good park go job
walk park dog win for good
park job forward daycare a
dolphin job park walk care
go with me certified job I
dolphin job park walk care
walk park dog win for good
leader forward win dog for
tablet forward go walk for
leader forward win dog for
leader go forward win walk
walk go forward do win dog
park job forward daycare a
leader forward win dog for
tablet forward go walk for
park job forward daycare a
go with me certified job I
dolphin job park walk care
-
實際表是25000000個文獻引用,第二列與取出共同停止字相同的引文。夢想是將共同的引用組合在一起。
再次感謝您。
您能否介紹一下所涉及表格的詳細信息以及它們之間的數據鏈接? –
我剛剛提供了一個樣本表和鏈接的解釋。 – user3643012