php与mysql数据库增删改查的一些操作!

php与mysql通过修改完善一个php商城程序而记录的一些常用的php-mysql的基本应用!
1:数据库连接:

session_start();
$conn = mysql_connect('127.0.0.1','root','') or die(mysql_error);
mysql_select_db('shoping',$conn);
mysql_query(“SET character_set_results = gb2312”) ;
mysql_query(“SET character_set_client = gb2312”);
mysql_query(“SET character_set_connection = gb2312”);

2:嵌入其他:

include(“conn.php”);
?>

3:简单的数据库调用输出

$sql_news=”select id,title from news order by id desc”;
$rs_news=mysql_query($sql_news);
while(list($news_id,$title)=mysql_fetch_row($rs_news))
{
?>


4:按一行12个循环排列

$sql=”select id,name from shoping_type”;
$rs=mysql_query($sql);
$i=1;
$j=mysql_num_rows($rs);
while(list($id,$name)=mysql_fetch_row($rs))
{
?>

if($i%12==0)
{
echo “

“;
}
$i++;
}
?>
|


另一种循环

$sql_shoping_type=”select id,name,img from shoping_type order by id”;
$rs_shoping_type=mysql_query($sql_shoping_type);
$j=1;
while(list($id,$name,$img)=mysql_fetch_row($rs_shoping_type))
{
?>

………………………………………………………………………
if($j%3==0)
{
?>

}
$j++;
}
?>


5:根据一个字段进行数据库读取
 
$sql1=”select img,url from img_news where id=1″;
$rs_news=mysql_query($sql1);
while(list($img,$url)=mysql_fetch_row($rs_news))
{
?>

按商品名称查询:
“>

按品牌查询:

下部是分页与显示文章部分

$sql=”select id,product_name from product where 1=1″;
if(trim($_POST[”productname”])!=””)
{
$sql.=” and product_name like '%”.trim($_POST[”productname”]).”%' order by id desc”;
}
elseif(trim($brand_name)!=””)
{
$sql.=” and product_brand like '%”.trim($brand_name).”%' order by id desc”;
}
else
{
$sql.=” order by id desc”;
}
//echo $sql;
$rs = mysql_query($sql);
$pagesize = 15;
$cnt = mysql_num_rows($rs);
if($cnt==0)
{
echo “暂无数据”;
exit;
}
$pagecount = ceil($cnt/$pagesize);
if(!isset($pageno)) $pageno=1;
if($pageno<1) $pageno = 1;
if($pageno>$pagecount) $pageno = $pagecount;
mysql_data_seek($rs,($pageno-1)*$pagesize) or die(“无法定位数据!”);
$j=0;
?>

…………………………………内容循环部分
while(list($id,$product_name)=mysql_fetch_row($rs) and $j < $pagesize)
{
?>

$j++;
}
?>

…………………………………内容循环部分


function ClickType(typeclass) {
frmUpdate.tType.value=selecttype(frmUpdate);
}
function inittype(myfrm)
{
var type1box;
type1box = myfrm.selJWHName;
for(i = 1; i <= tIndexes.length-1; i++)
{
oOption=document.createElement("OPTION");
oOption.text=tName[i];
oOption.value=tIndexes[i];
type1box.add(oOption);
}

for(i = 1; i <= tIndexes.length-1; i++)
{
if(tIndexes[i]==""){

type1box.options[i-1].selected = true;
}
}
type1box.length = i-1;
}

function selecttype(myfrm)
{
var type1box;
type1box = myfrm.selJWHName;
seltype = parseInt(type1box.selectedIndex);
seltype++;
tIdx = tIdxs[seltype];
tContent = tContents[seltype];
if(tIdx != null && tContent != null)
{
type2box = myfrm.selStreetName;
type2box.length = 0;
for(i = 0; i < tIdx.length; i++)
{
oOption = document.createElement("OPTION");
oOption.text = tContent[i];
oOption.value = tIdx[i];

//str = /*i + "." + */tContent[i];
//type2box.options[i] = new Option(str, tIdx[i]);
type2box.add(oOption);
}
for(i = 0; i < tIdx.length; i++)
{
if(tIdx[i] == ""){
type2box.options[i].selected = true;
}
}
type2box.length = i;
}
}



">


You May Also Like

About the Author: admin

发表评论

您的电子邮箱地址不会被公开。

&brand_name=“>首页 &brand_name=“>上一页 &brand_name=“>下一页 &brand_name=“>尾页 页次:/篇/页 转到:

其中的js

13:一个onmouseover 属性

大类:

小类: