时间:2021-07-01 10:21:17 帮助过:5人阅读
$bliang='这是个变量'$sql=SELECT * FROM A表 WHERE cart LIKE '%.$bliang.%'$query=mysql_query($sql);while($row=mysql_fetch_array($query)){ …………}
function foo($x){global $con;$sql=SELECT * FROM A表 WHERE cart LIKE '%.$x.%'mysql_query($sql,$con);// some codereturn $query;}
function foo($x){global $con;$sql=SELECT * FROM A表 WHERE cart LIKE '%.$x.%'mysql_query($sql,$con);// some codereturn $query;}
function foo($x){global $con;$sql=SELECT * FROM A表 WHERE cart LIKE '%.$x.%'mysql_query($sql,$con);// some codereturn $query;}
写成函数啊,我也是刚学php,我给你一个我自己做的类参考下吧,所有数据库操作都在这里了
dsn, $this->user, $this->pass); $dbh->query($this->names); return $dbh->query($sql); $dbh = null; } catch(Exception $e) { echo 'error: ' . $e->getMessage(); } } //操作单条数据(更新/删除/插入),无返回结果 public function sql_one($sql) { try { $dbh = new PDO($this->dsn, $this->user, $this->pass); $dbh->exec($this->names); $dbh->exec($sql); $dbh = null; } catch(Exception $e) { echo 'error: ' . $e->getMessage(); } } //操作多条数据(更新/删除),无返回结果 public function sql_more($sql, $str) { try { $dbh = new PDO($this->dsn, $this->user, $this->pass); $dbh->exec($this->names); foreach ($str as $arrs) { $dbh->exec($sql . $arrs); } $dbh = null; } catch(Exception $e) { echo 'error: ' . $e->getMessage(); } } //参数化查询数据库返回结果(单条) public function cs_sql_select($sql,$str) { try { $dbh = new PDO($this->dsn, $this->user, $this->pass); $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $dbh->query($this->names); $stmt = $dbh->prepare($sql); $stmt->bindValue(":key", $str ,PDO::PARAM_INT); $stmt->execute(); return $stmt; $dbh = null; } catch(Exception $e) { echo 'error: ' . $e->getMessage(); } } //参数化查询操作多条数据(删除/更新),无返回结果 public function cs_sql_more($sql, $str) { try { $dbh = new PDO($this->dsn, $this->user, $this->pass); $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $dbh->exec($this->names); foreach ($str as $arrs) { $stmt = $dbh->prepare($sql); $stmt->bindValue(":key", $arrs,PDO::PARAM_INT); $stmt->execute(); } $dbh = null; } catch(Exception $e) { echo 'error: ' . $e->getMessage(); } } //参数化查询操作单条数据(删除/更新),无返回结果 public function cs_sql_one($sql, $str) { try { $dbh = new PDO($this->dsn, $this->user, $this->pass); $dbh->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); $dbh->exec($this->names); $stmt = $dbh->prepare($sql); $stmt->bindValue(":key", $str,PDO::PARAM_INT); $stmt->execute(); $dbh = null; } catch(Exception $e) { echo 'error: ' . $e->getMessage(); } } ////////}?>
sql_one("DELETE FROM `user_type` WHERE `user_id` = ".$_REQUEST['id']."");//无参数化查询操作$mysql->cs_sql_one("DELETE FROM `user_type` WHERE `user_id` = :key",$_REQUEST['id']);//参数化查询操作}else{echo '非法操作';}} //多选删除else if($_REQUEST["action"] == 'delCheck'){$id=$_POST['delAll'];if(isset($id)){//$mysql->sql_more("DELETE FROM `user_type` WHERE `user_id` = ",$id);//无参数化查询操作$mysql->cs_sql_more("DELETE FROM `user_type` WHERE `user_id` = :key",$id);//参数化查询操作}}//读取数据库?>
function foo($x){global $con;$sql=SELECT * FROM A表 WHERE cart LIKE '%.$x.%'mysql_query($sql,$con);// some codereturn $query;}
写成函数啊,我也是刚学php,我给你一个我自己做的类参考下吧,所有数据库操作都在这里了
我是这样的意思
$b='这是个变量'$sql=SELECT * FROM A表 WHERE cart LIKE '%.$b.%'$query=mysql_query($sql);while($row=mysql_fetch_array($query)){ $new="$row['title']." - ".$row['con']." - ".$row['num'].";}
写成函数啊,我也是刚学php,我给你一个我自己做的类参考下吧,所有数据库操作都在这里了
我是这样的意思
$b='这是个变量'$sql=SELECT * FROM A表 WHERE cart LIKE '%.$b.%'$query=mysql_query($sql);while($row=mysql_fetch_array($query)){ $new="$row['title']." - ".$row['con']." - ".$row['num'].";}
$new="$row['title']." - ".$row['con']." - ".$row['num'].";
改写为
$new[$row['title']] = $row['title']." - ".$row['con']." - ".$row['num'];
function foo($x){global $con;$sql=SELECT * FROM A表 WHERE cart LIKE '%.$x.%'mysql_query($sql,$con);// some codereturn $query;}
function foo($x){global $con;$sql=SELECT * FROM A表 WHERE cart LIKE '%.$x.%'mysql_query($sql,$con);// some codereturn $query;}
$tagxs_lx="select * from ".DB_MUSICDATA." left join ".DB_SINGER." on ".DB_MUSICDATA.".singer_id=".DB_SINGER.".singer_id left join ".DB_TAG." on ".DB_MUSICDATA.".tag_id=".DB_TAG.".tag_id and ".DB_TAG.".tag like '%标签1%' order by ".DB_MUSICDATA.".music_id desc limit 10";$query_lx=mysql_query($tagxs_lx);$num=0;$tag1="";while($row=mysql_fetch_array($query_lx)){$num++;if($row['singer_id']==""){$singer="";}else{$singer=''.$row['singer_name'].'';} $tag1 .='
然后我页面调用的时候 直接 就可以了
然后我页面调用的时候 直接 就可以了
取回的是数组 你这种需求反人类...难道你要在function里把格式都写好,那也是反人类设计.
所以 我觉得你还是按照你原来的额写法写算了,别搞function了....
function你能看懂 剩下的不就是循环出数据 拼接成你要的样子吗?这个地方也不熟悉的话 我建议你先弄清楚返回的数据结构...
不知道怎么说了
查找别的问题 偶然解决了这个, 回来做个标记 顺便吧解决方法贴上来留着
function index($title,$limit){$text="select * from test wheretag like '%$title%' order by test.id desc limit $limit"; return $text;}echo index('条件','可以多个');