21,886
社区成员
发帖
与我相关
我的任务
分享
//link DB
$conn = mysql_connect(DB_HOST,DB_USER,DB_PASS);
$link = mysql_select_db(DB_NAME,$conn);
//查一条数据
$r = mysql_query('select * from `userreg` limit 1');
//获得表单名数量
$count = count(mysql_fetch_assoc($r));
for($i=0;$i<$count;$i++){
$tmp_name = mysql_field_name($r,$i);
//过滤掉c.shit
if($tmp_name != "c.shit"){
$filed_names[]= mysql_field_name($r,$i);
}
}
$f_names = implode(",",$filed_names);
$sql =<<<EOT
select distinct $f_names
from
`a` natural join `b` natural join `c`
where
`a`.`1` = `c`.`1` and `a`.`2` = xxx
EOT;
//n个字段的sql诞生了
print_r($sql);
<?php
$res = mysql_query('select * from `a` limit 1', $link);
$field_names = array();
for ($i=0; $i<50; $i++)
{
if ($i!=47)
$field_names[] = mysql_field_name($res, $i);
}
$f_names = implode(",",$filed_names);
$SQL =<<EOT
select distinct $f_names
from
`a` natural join `b` natural join `c`
where
`a`.`1` = `c`.`1` and `a`.`2` = xxx
EOT
?>
select distinct *
from
`a` natural join `b` natural join `c`
where
`a`.`1` = `c`.`1` and `a`.`2` = xxx
and
c.shit not in (select c.shit from c)
select distinct *
from
`a` natural join `b` natural join `c`
where
`a`.`1` = `c`.`1` and `a`.`2` = xxx