时间:2021-07-01 10:21:17 帮助过:4人阅读
$SQ="SELECT infotags,id FROM hd_ecms_shop_data_1 WHERE hd_ecms_shop_data_1.infotags LIKE '%我爱你%'";$result=mysqli_query($link,$SQ);$idStr='';if(mysqli_num_rows($result)){ $data=mysqli_fetch_all($result,MYSQL_ASSOC); foreach($data as $value){ if(isset($value['id'])) $idStr.=$value['id']; } $idStr=rtrim($idStr,','); echo $idStr;}
$SQ="SELECT infotags,id FROM hd_ecms_shop_data_1 WHERE hd_ecms_shop_data_1.infotags LIKE '%我爱你%'";$result=mysqli_query($link,$SQ);$idStr='';if(mysqli_num_rows($result)){ $data=mysqli_fetch_all($result,MYSQL_ASSOC); foreach($data as $value){ if(isset($value['id'])) $idStr.=$value['id']; } $idStr=rtrim($idStr,','); echo $idStr;}
sql=mysql_query($query,return_dblink($query)) or die($ecms_config['db']['showerror']==1?mysql_error().'
'.str_replace($GLOBALS['dbtbpre'],'***_',$query):'DbError'); return $this->sql; } //执行mysql_query()语句2 function query1($query){ $this->sql=mysql_query($query,return_dblink($query)); return $this->sql; } //执行mysql_query()语句(选择数据库USE) function usequery($query){ global $ecms_config; $this->sql=mysql_query($query,$GLOBALS['link']) or die($ecms_config['db']['showerror']==1?mysql_error().'
'.str_replace($GLOBALS['dbtbpre'],'***_',$query):'DbError'); if($GLOBALS['linkrd']) { mysql_query($query,$GLOBALS['linkrd']); } return $this->sql; } //执行mysql_query()语句(操作数据库) function updatesql($query){ global $ecms_config; $this->sql=mysql_query($query,return_dblink($query)) or die($ecms_config['db']['showerror']==1?mysql_error().'
'.str_replace($GLOBALS['dbtbpre'],'***_',$query):'DbError'); return $this->sql; } //执行mysql_fetch_array() function fetch($sql)//此方法的参数是$sql就是sql语句执行结果 { $this->r=mysql_fetch_array($sql); return $this->r; } //执行fetchone(mysql_fetch_array()) //此方法与fetch()的区别是:1、此方法的参数是$query就是sql语句 //2、此方法用于while(),for()数据库指针不会自动下移,而fetch()可以自动下移。 function fetch1($query) { $this->sql=$this->query($query); $this->r=mysql_fetch_array($this->sql); return $this->r; } //执行mysql_num_rows() function num($query)//此类的参数是$query就是sql语句 { $this->sql=$this->query($query); $this->num=mysql_num_rows($this->sql); return $this->num; } //执行numone(mysql_num_rows()) //此方法与num()的区别是:1、此方法的参数是$sql就是sql语句的执行结果。 function num1($sql) { $this->num=mysql_num_rows($sql); return $this->num; } //执行numone(mysql_num_rows()) //统计记录数 function gettotal($query) { $this->r=$this->fetch1($query); return $this->r['total']; } //执行free(mysql_result_free()) //此方法的参数是$sql就是sql语句的执行结果。只有在用到mysql_fetch_array的情况下用 function free($sql) { mysql_free_result($sql); } //执行seek(mysql_data_seek()) //此方法的参数是$sql就是sql语句的执行结果,$pit为执行指针的偏移数 function seek($sql,$pit) { mysql_data_seek($sql,$pit); } //执行id(mysql_insert_id()) function lastid()//取得最后一次执行mysql数据库id号 { $this->id=mysql_insert_id($GLOBALS['link']); if($this->id<0) { $this->id=$this->gettotal('SELECT last_insert_id() as total'); } return $this->id; } //返回影响数量(mysql_affected_rows()) function affectnum()//取得操作数据表后受影响的记录数 { return mysql_affected_rows($GLOBALS['link']); }}?>
$SQ="SELECT infotags,id FROM hd_ecms_shop_data_1 WHERE hd_ecms_shop_data_1.infotags LIKE '%我爱你%'";$result=mysqli_query($link,$SQ);$idStr='';if(mysqli_num_rows($result)){ $data=mysqli_fetch_all($result,MYSQL_ASSOC); foreach($data as $value){ if(isset($value['id'])) $idStr.=$value['id']; } $idStr=rtrim($idStr,','); echo $idStr;}
query('SELECT infotags,id FROM hd_ecms_shop_data_1 WHERE hd_ecms_shop_data_1.infotags LIKE "%现货促销产品%"');//查询副表下的infotags字段$idStr='';if($empire->num($sqld)){ $data=$empire->fetch($sqld); foreach($data as $key=>$value){ if(isset($value['id'])) $idStr.=$value['id']; } $idStr=rtrim($idStr,','); echo $idStr;}?>
$SQ="SELECT infotags,id FROM hd_ecms_shop_data_1 WHERE hd_ecms_shop_data_1.infotags LIKE '%我爱你%'";$result=mysqli_query($link,$SQ);$idStr='';if(mysqli_num_rows($result)){ $data=mysqli_fetch_all($result,MYSQL_ASSOC); foreach($data as $value){ if(isset($value['id'])) $idStr.=$value['id']; } $idStr=rtrim($idStr,','); echo $idStr;}
//代码误导你了 修改一下 $idStr.=$bqrd[id].',';}$idStr=rtrim($idStr,',')
另外 mysqli_fetch_all 是 PHP 的mysql数据库驱动 并没有给淘汰,只是服务器需要打开这个支持而已.有的服务器环境可能没有支持比如 sea...一般自己编译的服务器都可以轻松得到这个支持
另外 mysqli_fetch_all 是 PHP 的mysql数据库驱动 并没有给淘汰,只是服务器需要打开这个支持而已.有的服务器环境可能没有支持比如 sea...一般自己编译的服务器都可以轻松得到这个支持
$SQ="SELECT infotags,id FROM hd_ecms_shop_data_1 WHERE hd_ecms_shop_data_1.infotags LIKE '%我爱你%'";$result=mysqli_query($link,$SQ);$idStr='';if(mysqli_num_rows($result)){ $data=mysqli_fetch_all($result,MYSQL_ASSOC); foreach($data as $value){ if(isset($value['id'])) $idStr.=$value['id']; } $idStr=rtrim($idStr,','); echo $idStr;}
//hava a try SELECT GROUP_CONCAT(infotags SEPARATOR ",") as infotags,id FROM hd_ecms_shop_data_1 WHERE hd_ecms_shop_data_1.infotags LIKE '%我爱你%' GROUP BY infotags
可以查询出来id的数组再用implode来处理啊,为啥非要用sql查询来处理?
可以查询出来id的数组再用implode来处理啊,为啥非要用sql查询来处理?
//骚年,这是基本功的问题啊while($row=mysql_fetch_array($result)){ $id[]=$row['id'];}echo join(",",$id);
//骚年,这是基本功的问题啊while($row=mysql_fetch_array($result)){ $id[]=$row['id'];}echo join(",",$id);
//骚年,这是基本功的问题啊while($row=mysql_fetch_array($result)){ $id[]=$row['id'];}echo join(",",$id);
//骚年,这是基本功的问题啊while($row=mysql_fetch_array($result)){ $id[]=$row['id'];}echo join(",",$id);
//骚年,这是基本功的问题啊while($row=mysql_fetch_array($result)){ $id[]=$row['id'];}echo join(",",$id);