怎么做,才能搜索出两个MYSQL数据库的内容 做个搜索数据库名 test1 test2要怎么做,才能搜索出这两个数据库,相同表相同字段里的内容,一起显示 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 [code=PH]<?php$conna = mysql_connect('localhost','root','root');$connb = mysql_connect('localhost','root','root');mysql_select_db('mytest',$conna); //mytestmysql_select_db('mmtest',$connb); //mmtestmysql_set_charset('gbk',$conna); //设置字符集mysql_set_charset('gbk',$connb); //设置字符集$sql = "select * from mmtest.info union all (select * from mmtest.info)"; //union all 是把两个表的数据都显示出来;union 把两个表的数据显示出来,并去掉重复的。$query = mysql_query($sql);while($re = mysql_fetch_array($query)){ echo $re['id']."--".$re['url']."<br />\n";}?>[/code]输出:2--http://bbs.wanku.com/660--http://bbs.uc.cn/1267--http://bbs.yys5.com/index.php1379--http://67.220.92.027/forum/index.php2041--http://www.eaf1.cn/bbs/index.php2842--http://www.tsmm.com/bbs/2852--http://my.chinacars.com/bbs/2915--http://bbs.changjiang.cc/2954--http://www.panamachinese.com/bbs/3544--http://www.gochina.cn/bbs/3902--http://bbs2.ispeak.cn/4093--http://67.220.92.017/forum/4303--http://www.kokwind.com/bbs/4374--http://www.netyourlife.net/forum/4495--http://www.379.cc/4677--http://zenmela-net.osteching.com/bbs/5404--http://bbs.hcbbs.com/viewthread.php?tid=414086164--http://www.bbsda.info/viewthread.php?tid=551848995--http://bbs.ipark.cn/archiver/tid-16059.html9626--xxx2--http://bbs.wanku.com/660--http://bbs.uc.cn/1267--http://bbs.yys5.com/index.php1379--http://67.220.92.027/forum/index.php2041--http://www.eaf1.cn/bbs/index.php2842--http://www.tsmm.com/bbs/2852--http://my.chinacars.com/bbs/2915--http://bbs.changjiang.cc/2954--http://www.panamachinese.com/bbs/3544--http://www.gochina.cn/bbs/3902--http://bbs2.ispeak.cn/4093--http://67.220.92.017/forum/4303--http://www.kokwind.com/bbs/4374--http://www.netyourlife.net/forum/4495--http://www.379.cc/4677--http://zenmela-net.osteching.com/bbs/5404--http://bbs.hcbbs.com/viewthread.php?tid=414086164--http://www.bbsda.info/viewthread.php?tid=551848995--http://bbs.ipark.cn/archiver/tid-16059.html9626--xxx两个数据库:mytest和mmtest 他们都有一个info表, mytest的info表和mmtest的info的表结构是一样的,这两个表的数据也是一样的,所以看上去象是重复显示了一次。mysql_set_charset是设置编码 要和你的网页编码一致! 否则中文乱码 如果两个数据库的编码也是一样的那么就可以简略成这样:$conn = mysql_connect('localhost','root','root');$sql = "select * from mmtest.info union all (select * from mmtest.info)"; $query = mysql_query($sql);while($re = mysql_fetch_assoc($query)){ echo $re['id']."--".$re['url']."<br />\n";}mysql_close($conn); 如果两个数据库的编码也是一样的那么就可以简略成这样:$conn = mysql_connect('localhost','root','root');mysql_query("SET NAMES `GBK`");//设置编码$sql = "select * from mmtest.info union all (select * from mmtest.info)"; $query = mysql_query($sql);while($re = mysql_fetch_assoc($query)){ echo $re['id']."--".$re['url']."<br />\n";}mysql_close($conn); $conn = mysql_connect('localhost','root','root');mysql_query("SET NAMES `GBK`");//设置编码$sql = "select * from mmtest.info union all (select * from mmtest.info)"; $query = mysql_query($sql);while($re = mysql_fetch_assoc($query)){ echo $re['id']."--".$re['url']."<br />\n";}mysql_close($conn);有点看不明白,这连接了两个数据库吗?调用了两个表的吗mmtest, mytest不用吗 数据库1 mytest 数据库2 mmtest他们都有一个名为info的表,且表结构相同。在连接数据库服务器后,不需要mysql_select_db,只要把查询语句中的表名用“库名.表名”来表示就可以了。mysql可以根据查询语句来识别是哪个库的哪个表 mysql分组新问题 php如何获取flash中的Url(在线等待。。。。) 文件夹 显示图片 php能不能alert(ab||ba);这样?! 我觉得我糊涂了,要转义三次? 用thinkphp写的用户登录界面,但是每次都说用户名或者密码不正确,求解? 寻找成都本地的php开发熟手,有项目外包 我要建一个个人主页,提下建议! ---一个有关include得问题,谢谢--- 求中文俩字符串匹配包含的函数。 正则如何得到域名中间字符串? 请教如何过滤xss代码,谢谢
<?php
$conna = mysql_connect('localhost','root','root');
$connb = mysql_connect('localhost','root','root');
mysql_select_db('mytest',$conna); //mytest
mysql_select_db('mmtest',$connb); //mmtest
mysql_set_charset('gbk',$conna); //设置字符集
mysql_set_charset('gbk',$connb); //设置字符集
$sql = "select * from mmtest.info union all (select * from mmtest.info)";
//union all 是把两个表的数据都显示出来;union 把两个表的数据显示出来,并去掉重复的。
$query = mysql_query($sql);
while($re = mysql_fetch_array($query)){
echo $re['id']."--".$re['url']."<br />\n";
}
?>
[/code]输出:
2--http://bbs.wanku.com/
660--http://bbs.uc.cn/
1267--http://bbs.yys5.com/index.php
1379--http://67.220.92.027/forum/index.php
2041--http://www.eaf1.cn/bbs/index.php
2842--http://www.tsmm.com/bbs/
2852--http://my.chinacars.com/bbs/
2915--http://bbs.changjiang.cc/
2954--http://www.panamachinese.com/bbs/
3544--http://www.gochina.cn/bbs/
3902--http://bbs2.ispeak.cn/
4093--http://67.220.92.017/forum/
4303--http://www.kokwind.com/bbs/
4374--http://www.netyourlife.net/forum/
4495--http://www.379.cc/
4677--http://zenmela-net.osteching.com/bbs/
5404--http://bbs.hcbbs.com/viewthread.php?tid=41408
6164--http://www.bbsda.info/viewthread.php?tid=55184
8995--http://bbs.ipark.cn/archiver/tid-16059.html
9626--xxx
2--http://bbs.wanku.com/
660--http://bbs.uc.cn/
1267--http://bbs.yys5.com/index.php
1379--http://67.220.92.027/forum/index.php
2041--http://www.eaf1.cn/bbs/index.php
2842--http://www.tsmm.com/bbs/
2852--http://my.chinacars.com/bbs/
2915--http://bbs.changjiang.cc/
2954--http://www.panamachinese.com/bbs/
3544--http://www.gochina.cn/bbs/
3902--http://bbs2.ispeak.cn/
4093--http://67.220.92.017/forum/
4303--http://www.kokwind.com/bbs/
4374--http://www.netyourlife.net/forum/
4495--http://www.379.cc/
4677--http://zenmela-net.osteching.com/bbs/
5404--http://bbs.hcbbs.com/viewthread.php?tid=41408
6164--http://www.bbsda.info/viewthread.php?tid=55184
8995--http://bbs.ipark.cn/archiver/tid-16059.html
9626--xxx两个数据库:mytest和mmtest 他们都有一个info表, mytest的info表和mmtest的info的表结构是一样的,
这两个表的数据也是一样的,所以看上去象是重复显示了一次。mysql_set_charset是设置编码 要和你的网页编码一致! 否则中文乱码
那么就可以简略成这样:
$conn = mysql_connect('localhost','root','root');
$sql = "select * from mmtest.info union all (select * from mmtest.info)";
$query = mysql_query($sql);
while($re = mysql_fetch_assoc($query)){
echo $re['id']."--".$re['url']."<br />\n";
}
mysql_close($conn);
那么就可以简略成这样:
$conn = mysql_connect('localhost','root','root');
mysql_query("SET NAMES `GBK`");//设置编码
$sql = "select * from mmtest.info union all (select * from mmtest.info)";
$query = mysql_query($sql);
while($re = mysql_fetch_assoc($query)){
echo $re['id']."--".$re['url']."<br />\n";
}
mysql_close($conn);
mysql_query("SET NAMES `GBK`");//设置编码
$sql = "select * from mmtest.info union all (select * from mmtest.info)";
$query = mysql_query($sql);
while($re = mysql_fetch_assoc($query)){
echo $re['id']."--".$re['url']."<br />\n";
}
mysql_close($conn);有点看不明白,这连接了两个数据库吗?调用了两个表的吗mmtest, mytest不用吗
数据库2 mmtest
他们都有一个名为info的表,且表结构相同。在连接数据库服务器后,不需要mysql_select_db,只要把查询语句中的表名用“库名.表名”来表示就可以了。mysql可以根据查询语句来识别是哪个库的哪个表