2019年10月28日 星期一

MySQL語法紀錄

  • select

$sql="select * from team where id='$id'";
$result=mysql_query($sql) or die("query error");
$n = mysql_num_rows($result);
$rs=mysql_fetch_array($result); //只列出一項

$sql="select * from team";
$result=mysql_query($sql) or die("query error");
while($rs=mysql_fetch_array($result)){
//列出全部
}

  • update


$sql = "update team set keep=0 where id='$id'";
$result = mysql_query($sql) or die($sql);


  • INSERT


$sql = "INSERT INTO team (team,IP) VALUES ('$team','$IP')";
$result = mysql_query($sql) or die($sql);


  • DELETE


 $sql = "DELETE FROM team where id='$id'";
$result = mysql_query($sql) or die($sql);


  • limit搭配offset


$sql ="select * from team where keep=0 order by IP limit 1000 offset ".$page*1000;
$result=mysql_query($kick) or die($sql );
//做分頁用,範例是以1000筆為一頁


  • order 


$sql ="select * from team where keep=0 order by keep DESC,IP";
$result=mysql_query($sql ) or die($sql);
//範例是用兩個欄位做排序


  • in 


$team="'".$team;
$team=str_replace(",","','",$team);
$team=substr($team,0,-2);

$sql ="select * from team where name in ($team) and keep>0 order by IP";
$result=mysql_query($sql ) or die($sql );
//將team資料夾中的name拿進去$team陣列查找
//$team=" 'abc','def,''hij' ";

沒有留言:

張貼留言