php+mysql基础
2016-12-11 09:54
274 查看
1、 统计总数:
2、取整数:
3、API:
4、 复制:
5、替换特殊字符:
6、有条件显示背景色
7、合计
8、显示重复
9、时间格式
10、mysql将一个字段的值赋给另一个字段
11、按时间段搜索
提交页
处理页
$result = mysql_query("SELECT * FROM goods"); $num_rows = mysql_num_rows($result); 总数<?=$num_rows;?>
2、取整数:
<?=ceil($total/200)+1?>
3、API:
$quanzhanye = $_POST['s'][0]; $url='http://api.***'.$quanzhanye.'';/**API接口**/ $data=file_get_contents($url); $data=json_decode($data,true); $data = $data['result']; $table_name='plugin_jinzhe'; $num=0; foreach($data as $val){ $plugin_data=array(); $val['num_iid']=trim($val['GoodsID']); $plugin_data['cid']=$val['Cid']; $plugin_data['iid']=$val['GoodsID']; $plugin_data['pic_url']=$val['Pic']; $plugin_data['price']=$val['Price']; $plugin_data['price_jian']=$val['Quan_price']; $plugin_data['youhuiquan_ur']=$val['Quan_link']; $plugin_data['zhushi']=$val['Introduce']; $plugin_data['price_original']=$val['Org_Price']; $plugin_data['title']=$val['D_title']; $plugin_data['commission_rate']=$val['Commission_jihua']; $plugin_data['volume']=$val['Sales_num']; $plugin_data['baoyou']=1; $plugin_data['shop_type']=($val['IsTmall']=='1')?1:0; $plugin_data['sort']=$val['ordid']; $plugin_data['starttime']=time();//原来的$val['coupon_start_time']; $plugin_data['endtime']=strtotime('+1 day',strtotime($val['Quan_time'])); $plugin_data['addtime']=time(); $plugin_data['status']=1; $res=''; $res=$duoduo->insert($table_name,$plugin_data); if($res && is_int($res)){ echo 'num_iid:'.$val['GoodsID'].' 添加成功<br />'; $num++; }else{ echo 'num_iid:'.$val['GoodsID'].' <span style="color:red">添加失败,商品可能已经存在</span><br />'; } } exit('一键获取结束,总共成功获取了 '.$num.' 款商品'.print_r($data));//echo '<pre>';print_r($array);
4、 复制:
<script type="text/javascript"> function copyUrl2(obj) { var Url2=obj;//复制对象 Url2.select(); //选择对象 document.execCommand("Copy"); //执行浏览器复制命令 window.status="复制成功,可直接粘贴" setTimeout("window.status=''",1000) alert("复制成功,直接粘贴即可"); } </script> <input type="text" class="d_out" onMouseOver="this.className='d_over'" onMouseOut="this.className='d_out'" value="<?php echo $row_wtcl_nrly['wtcl_a']; ?>,ID:<?php echo $row_wtcl_nrly['wtcl_b']; ?>,<?php echo $row_wtcl_nrly['wtcl_k']; ?>,(<?php echo $row_wtcl_nrly['wtcl_c']; ?>,订单号:<?php echo $row_wtcl_nrly['wtcl_d']; ?>)。" onClick="copyUrl2(document.getElementById('<?=$row_wtcl_nrly['wtcl_id']; ?>'))" size="1" maxlength="10" id="<?=$row_wtcl_nrly['wtcl_id']; ?>">
5、替换特殊字符:
function replace_specialChar($strParam){ $regex = "/\/|\~|\!|\@|\#|\\$|\¥|\%|\^|\&|\*|\(|\)|\_|\+|\{|\}|\:|\:|\<|\>|\?|\[|\]|\,|\.|\/|\;|\'|\`|\-|\=|\\\|\快递|\单号|\|/"; return preg_replace($regex,"",$strParam); } $str_wtcl_g = $_POST['wtcl_g']; $str_wtcl_g = replace_specialChar($str_wtcl_g); echo $str_wtcl_g;
6、有条件显示背景色
<?php if($row_wtcl_nrly['wtcl_i'] == '待处理'){ $wtcl_i_bg="#FFCCCC";} elseif($row_wtcl_nrly['wtcl_i'] == '处理中'){ $wtcl_i_bg="#C7EDCC";} else{$wtcl_i_bg="#66CCFF";}?> <tr bgcolor="<?php echo $wtcl_i_bg;?>">
7、合计
$sql="select sum(xinka_kyed) from xinka"; $kyed = mysql_query($sql); $sum_kyed=mysql_fetch_assoc($kyed); //echo array_sum($sum_kyed).'<hr>'; //print_r($sum_kyed);
8、显示重复
$sql = "Select wtcl_b, Count(*) As wtcl_b From wtcl_nr Group By wtcl_b order by wtcl_b desc"; $rs = mysql_query($sql); while (list($wtcl_b, $count) = mysql_fetch_row($rs)){ if($count>=2 & $wtcl_b<>'.'){ echo '<span style="color: #333; font-size: 12px;">['.$wtcl_b.']'.$count.',</span>'; }}
9、时间格式
<?=date('n-j H:i:s', strtotime($row_jsbb_show['jsbb_time']))?> // m-d
10、mysql将一个字段的值赋给另一个字段
UPDATE `shuju`.`nr` SET `riqi` = `time`
11、按时间段搜索
提交页
<form action="chaxun.php" method="post" name="form2" target="_blank" id="form2">开始:<input name="kaishi" type="text" id="kaishi" onClick="return Calendar('kaishi');" value="<?=date('Y-m-01')?>" size="7">,截止:<input name="jiezhi" type="text" id="jiezhi" onClick="return Calendar('jiezhi');" value="<?=date('Y-m-d')?>" size="7"><input type="submit" class="btn" value="搜索" ></form>
处理页
$kaishi = $_POST['kaishi']; $jiezhi = $_POST['jiezhi']; $sql = "select * from jsbb_nr where jsbb_riqi between '$kaishi' and '$jiezhi' order by jsbb_time desc;";
相关文章推荐
- PHP 和 MySQL 基础教程(三)
- PHP 和 MySQL 基础教程(一)
- PHP 和 MySQL 基础教程(一)
- iis下php+mysqli基础配置记录
- PHP/MySQL 基础知识集锦一
- PHP 和 MySQL 基础教程(一)
- [PHP+MySQL开发基础分享]在本地配置PHP开发环境
- PHP 和 MySQL 基础教程(三)
- win2000/2003 Php+ZendOptimizer+Mysql+eaccelerator配置及基础优化全攻略
- PHP、MySQL最基础的教程
- PHP 和 MySQL 基础教程(二)
- PHP 和 MySQL 基础教程(二)
- PHP 和 MySQL 基础教程(三)
- PHP 和 MySQL 基础教程(四)
- PHP 和 MySQL 基础教程(一)
- PHP 和 MySQL 基础教程(四)
- PHP 和 MySQL 基础教程(四)
- PHP 和 MySQL 基础教程(二)
- 用新PHP插件实现MySQL为基础的事务
- [PHP+MySQL开发基础分享]好书推荐