请教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)<5)
{
if($this->guolv($tpl2result['title']))
array_push($array1,$tpl2result);
}
if(sizeof($array2)<5)
{
if(!$this->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>
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号