下面的代码可以查询单个数据库的所有表的指定的字段内容,如何才能实现多个数据库一起查询相同字段的内容,每个数据库字段都一样,表都是100+个.并且下面的代码虽然能查询单个数据库所有表的内容,但是查询一次耗费时间很长,该怎么样优化才能加快速度,不然假设多个数据库一起查询实现了,该会变得多卡.
这个简单啊!
首页做个前台输入姓名和会员卡信息的页面,我做个简单的页面给你看
html?xmlns="
head
title会员查询系统/title
/head
body
form?id="form1"?name="form1"?method="post"?action="test.php"
p
label?for="name"/label
input?type="text"?name="name"?id="name"?/
/p
label?for="vipid"/label
input?type="text"?name="vipid"?id="vipid"?/
input?type="submit"?name="button"?id="button"?value="查询"?/
/form
/body
/html
然后我给你一个test.php的文件代码:
php
$name?=?trim($_POST['name']);
$vipid?=?trim($_POST['vipid']);
if?(!$con)
{
die('Could?not?connect:?'?.?mysql_error());
}
$a?=?mysql_select_db("数据库名字",?$con);
$sql?=?"select?*?from?kh_customer?where?name?=?'$name'?and?vipid?=?'$vipid'";
$result?=?mysql_query($sql);
while($row?=?mysql_fetch_array($result))
echo?$row['name']?.?"?"?.?$row['data'];
echo?"br?/";
mysql_close($con);
页面美化自己去搞!只能帮你这么多了
select 列名,cont(*)班级人数
from 表名
group by 列名
order by 班组人数 desc
我直接在这给你修改答案算了
使用的时候删除行号
修改数据库配置
如果想使用
页面不刷新查询数据库
需要使用JQUERY
如果有需要给我留言
if(isset($_POST['submit'])$_POST['submit']=='提交'){
//判断是否是提交过来的
$intext
=
$_POST['intext'];
if($intext!=null||$intext!=''){
$link
mysql_connect("localhost",
"root",
//数据库配置信息
第一个参数数据库位置第二个是用户名第三个是密码
mysql_select_db("szn_test");
//设置要使用的数据库
$sql
"select
*
from
demo
where
res
'".$intext."'";
//SQL语句
var_dump($sql);
$res
mysql_query($sql);
$arr
array();
//吧结果存入数组
并记录数组长度
$count
0;
while($data
mysql_fetch_array($res)){
$arr[$count]
$data;
$count++;
//关闭数据库
mysql_close($link);
html
title/title
form
id="form1"
method="post"
action="demo.php"
input
type="text"
name="intext"
type="submit"
name="submit"
value="提交"
if(isset($arr)$arr
!=
null){
for($i
$i
$count;
$i++){
foreach($arr[$i]
as
$key
$value){
echo
"key:".$key."
value:".$value;
"
";
"br";
这个是数据库查询代码
你可以看以下对照着修改修改
$dbname = 'mysql_dbname';
if (!mysql_connect('mysql_host', 'mysql_user', 'mysql_password')) {
print 'Could not connect to mysql';
exit;
$result = mysql_list_tables($dbname);
if (!$result) {
print "DB Error, could not list tables\n";
print 'MySQL Error: ' . mysql_error();
while ($row = mysql_fetch_row($result)) {
print "Table: $row[0]\n";
mysql_free_result($result);
查看一下代码:
//?获取表单提交值
$student_id?=?intval(trim($_POST['student_id']));
//?页面表单?可以放单独的html文件中,如果放单独的html页面中?form?的action的地址要改成下面的PHP文件名
echo?'form?action=""?method="post"
input?type="text"?name="student_id"?value="{$student_id}"/
input?type="submit"?name="submit"?value="查询"/
/form';
//?当有数据提交时
if?($student_id)
$con=?mysql_connect("localhost","root","111")?or?die("连接错误");
mysql_select_db("examination",$con);
//?查询
$sql?=?"SELECT?*?FROM?tablename?WHERE?student_id?=?$student_id?";
$res=mysql_query($sql);
$row=mysql_fetch_array($res);
//?输出
echo?'学号:'.$row['student_id'].'br姓名:'.$row['name'].'br性别:'.$row['gender'].'br分数:'.$row['score'];