分表联合查询,请大侠修改,提供源码,谢谢!!
表qiu_job中的ID太多,我想分到表qiu_job2的ID中,如果新增的ID值存在qiu_job或qiu_job2的ID中,就拒绝添加;如果新增的ID值不存在上述2表中,就将之添加到qiu_job2的ID中,请问要如何写呢?谢谢!谢谢!
未分表的源代码在:http://sbbt.gou-w.cn/1.txt中。
以下为未分表之前的源码:
<?php
require 'common.php';
$url=daddslashes($_GET['url']);
$key=daddslashes($_GET['key']);
if(!empty($url) && !empty($key)){
$kmrow=$DB->get_row("SELECT * FROM qiu_kms WHERE km='$key' and kind=1 limit 1");
if(!$kmrow['id'])
exit('{"code":-9}');
if($kmrow['isuse']==1)
exit('{"code":-4}');
$data = get_curl($url,0,0,0,1);
preg_match("/Location: (.*?)\r\n/iU", $data, $urls);
if(!$urls[1]) $long_url=$url;else $long_url=$urls[1];
if(strpos($long_url,'www.battleofballs.com')===false){
exit('{"code":-3}');
}
$refer = str_replace("?","/index_mobile_share.html?",$long_url);
$account = explode('Account=',$refer);
$account = urldecode($account[1]);
$id = intval(trim(getSubstr($refer,"id=","&A")));
$row=$DB->get_row("SELECT * FROM qiu_job WHERE id='$id' limit 1");
if($row){
if($row['endtime']>$date)
exit('{"code":-11}'); //我自己瞎改的,我的要求是只要ID值存在数据库中,就拒绝添加并提示错误。
else
if($row['id']>'1') //我自己瞎改的,我的要求是只要ID值存在数据库中,就拒绝添加并提示错误。
exit('{"code":-3}');
}else{
$endtime=date("Y-m-d H:i:s", strtotime("+ {$kmrow['value']} days"));
if(!$DB->query("update qiu_kms set isuse='1',user='$id',usetime='$date' where id='{$kmrow['id']}'"))exit('{"code":-5}');
if(!$DB->query("insert into `qiu_job2` (`id`,`addtime`,`endtime`) values ('".$id."','".$date."','".$endtime."')"))exit('{"code":-8}');
exit('{"id":"'.$id.'","account":"'.$account.'","keyday":"'.$kmrow['value'].'","endtime":"'.$endtime.'","code":0}');
}
}else{
exit('{"code":-2}');
}