Rumah >pembangunan bahagian belakang >tutorial php >请问php大师-phpnewnew
请教php大师---phpnewnew
我有2张数据表
a表
有 字段title
b表
也有字段title
a表中有1000条数据,b表中有10条数据
要求:
查询a表的title,若a.title 在 b.title中,则a.title存入 $array1中,如果sizeof($array1)>5 ,则不存。
若 若a.title 不在 b.title中,则 则a.title存入 $array2中,如果sizeof($array2)>5 ,则不存。
我的做法
<!--Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->$sql="select title from a"........while($tpl2result=mysql_fetch_array($result_sql)) { if(sizeof($array1)guolv($tpl2result['title'])) array_push($array1,$tpl2result); } if(sizeof($array2)guolv($tpl2result['title'])) array_push($array2,$tpl2result); } if(sizeof($newtalk)==5&&sizeof($newvote)==5) { break; exit; } }
$array1 = array();$SQL = "SELECT a.title As atitle FROM a WHERE a.title in(SELECT b.title FROM b)";$mysql->query($SQL);$total = 0;while ($result = $mysql->fetch_assoc()) { $array[] = $result['atitle']; if ($total > 5) { break; } $total++;}$array2 = array();$SQL = "SELECT a.title As atitle FROM a WHERE a.title not in(SELECT b.title FROM b)";$total = 0;while ($result = $mysql->fetch_assoc()) { $array2[] = $result['atitle']; if ($total > 5) { break; } $total++;}<br><font color="#e78608">------解决方案--------------------</font><br><br>