php商品数据库表,php商品展示
php如何查询数据库表中的数据并显示
这个简单啊!
网站建设哪家好,找成都创新互联!专注于网页设计、网站建设、微信开发、成都小程序开发、集团企业网站建设等服务项目。为回馈新老客户创新互联还提供了库尔勒免费建站欢迎大家使用!
首页做个前台输入姓名和会员卡信息的页面,我做个简单的页面给你看
!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "
html xmlns="
head
meta http-equiv="Content-Type" content="text/html; charset=utf-8" /
title会员查询系统/title
/head
body
form id="form1" name="form1" method="post" action="test.php"
p
label for="name"/label
input type="text" name="name" id="name" /
/p
p
label for="vipid"/label
input type="text" name="vipid" id="vipid" /
/p
p
input type="submit" name="button" id="button" value="查询" /
/p
/form
/body
/html
然后我给你一个test.php的文件代码:
?php
$name = trim($_POST['name']);
$vipid = trim($_POST['vipid']);
$con = mysql_connect("127.0.0.1","数据库用户名","数据库密码");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
$a = mysql_select_db("数据库名字", $con);
$sql = "select * from kh_customer where name = '$name' and vipid = '$vipid'";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
echo $row['name'] . " " . $row['data'];
echo "br /";
}
mysql_close($con);
?
页面美化自己去搞!只能帮你这么多了
PHP读取数据的问题,现在我的数据库有一个数据表是存放商品图片的 假如我将商品图片读出来
//以下是PHP上传图片的代码(我就不写了) . //假设上传后得到图片名称 $上传成功后,你会返回一个路径到这个页面.这个页面应该有一个隐藏的表单. ,RWEzaf
Php商品图片数量不固定,怎么设计表单跟数据库
1、商品表建立商品基本信息主表CREATETABLEproduc。
2、cidint10NOTNULLCOMMENT分类。
3、titlevarchar100NOTNULLCOMMENT商品名称。
4、ddtimeint10NOTNULLCOMMENT添加时间,PRIMARYKEY。
mysql数据库中有一张Product表,请编写php程序,把一条商品信息写入到数据库中。
又是你.....
这些都是最基础的,以后用框架或者自己封装类的话就简单多了
只需要熟练掌握原生态sql语句就行
?php
header('content-type:text/html;charset=utf8');
// 链接MySQL
mysql_connect('localhost','root','123');
//设置编码
mysql_query("set names utf8");
// 选择数据库
mysql_select_db('test');
// 先接值
$pname=$_POST['name'];
// sql语句
$sql="insert into products (pname) value('$pname')";
$result=mysql_query($sql);
// 判断是否添加成功
if($result){
echo "ok";
}else{
echo "error";
}
请教关于PHP购物车代码的数据库表和字段
PHP Code
div id="products-wrapper"
h1Products/h1
div class="products"
?php
//current URL of the Page. cart_update.php redirects back to this URL
$current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
$results = $mysqli-query("SELECT * FROM cart ORDER BY id ASC");
if ($results) {
//fetch results set as object and output HTML
while($obj = $results-fetch_object())
{
echo 'div class="product"';
echo 'form method="post" action="cart_update.php"';
echo 'div class="product-thumb"img src="images/'.$obj-product_img_name.'"/div';
echo 'div class="product-content"h3'.$obj-product_name.'/h3';
echo 'div class="product-desc"'.$obj-product_desc.'/div';
echo 'div class="product-info"';
echo 'Price '.$currency.$obj-price.' | ';
echo 'Qty input type="text" name="product_qty" value="1" size="3" /';
echo 'button class="add_to_cart"Add To Cart/button';
echo '/div/div';
echo 'input type="hidden" name="product_code" value="'.$obj-product_code.'" /';
echo 'input type="hidden" name="type" value="add" /';
echo 'input type="hidden" name="return_url" value="'.$current_url.'" /';
echo '/form';
echo '/div';
}
}
?
/div
div class="shopping-cart"
h2Your Shopping Cart/h2
?php
if(isset($_SESSION["products"]))
{
$total = 0;
echo 'ol';
foreach ($_SESSION["products"] as $cart_itm)
{
echo 'li class="cart-itm"';
echo 'span class="remove-itm"a href="cart_update.php?removep='.$cart_itm["code"].'return_url='.$current_url.'"×/a/span';
echo 'h3'.$cart_itm["name"].'/h3';
echo 'div class="p-code"P code : '.$cart_itm["code"].'/div';
echo 'div class="p-qty"Qty : '.$cart_itm["qty"].'/div';
echo 'div class="p-price"Price :'.$currency.$cart_itm["price"].'/div';
echo '/li';
$subtotal = ($cart_itm["price"]*$cart_itm["qty"]);
$total = ($total + $subtotal);
}
echo '/ol';
echo 'span class="check-out-txt"strongTotal : '.$currency.$total.'/strong a href="view_cart.php"Check-out!/a/span';
echo 'span class="empty-cart"a href="cart_update.php?emptycart=1return_url='.$current_url.'"Empty Cart/a/span';
}else{
echo 'Your Cart is empty';
}
?
/div
cart_update.php
PHP Code
?php
session_start();
include_once("config.php");
//empty cart by distroying current session
if(isset($_GET["emptycart"]) $_GET["emptycart"]==1)
{
$return_url = base64_decode($_GET["return_url"]); //return url
session_destroy();
header('Location:'.$return_url);
}
//add item in shopping cart
if(isset($_POST["type"]) $_POST["type"]=='add')
{
$product_code = filter_var($_POST["product_code"], FILTER_SANITIZE_STRING); //product code
$product_qty = filter_var($_POST["product_qty"], FILTER_SANITIZE_NUMBER_INT); //product code
$return_url = base64_decode($_POST["return_url"]); //return url
//limit quantity for single product
if($product_qty 10){
die('div align="center"This demo does not allowed more than 10 quantity!br /a href=""Back To Products/a./div');
}
//MySqli query - get details of item from db using product code
$results = $mysqli-query("SELECT product_name,price FROM cart WHERE product_code='$product_code' LIMIT 1");
$obj = $results-fetch_object();
if ($results) { //we have the product info
//prepare array for the session variable
$new_product = array(array('name'=$obj-product_name, 'code'=$product_code, 'qty'=$product_qty, 'price'=$obj-price));
if(isset($_SESSION["products"])) //if we have the session
{
$found = false; //set found item to false
foreach ($_SESSION["products"] as $cart_itm) //loop through session array
{
if($cart_itm["code"] == $product_code){ //the item exist in array
$product[] = array('name'=$cart_itm["name"], 'code'=$cart_itm["code"], 'qty'=$product_qty, 'price'=$cart_itm["price"]);
$found = true;
}else{
//item doesn't exist in the list, just retrive old info and prepare array for session var
$product[] = array('name'=$cart_itm["name"], 'code'=$cart_itm["code"], 'qty'=$cart_itm["qty"], 'price'=$cart_itm["price"]);
}
}
if($found == false) //we didn't find item in array
{
//add new user item in array
$_SESSION["products"] = array_merge($product, $new_product);
}else{
//found user item in array list, and increased the quantity
$_SESSION["products"] = $product;
}
}else{
//create a new session var if does not exist
$_SESSION["products"] = $new_product;
}
}
//redirect back to original page
header('Location:'.$return_url);
}
//remove item from shopping cart
if(isset($_GET["removep"]) isset($_GET["return_url"]) isset($_SESSION["products"]))
{
$product_code = $_GET["removep"]; //get the product code to remove
$return_url = base64_decode($_GET["return_url"]); //get return url
foreach ($_SESSION["products"] as $cart_itm) //loop through session array var
{
if($cart_itm["code"]!=$product_code){ //item does,t exist in the list
$product[] = array('name'=$cart_itm["name"], 'code'=$cart_itm["code"], 'qty'=$cart_itm["qty"], 'price'=$cart_itm["price"]);
}
//create a new product list for cart
$_SESSION["products"] = $product;
}
//redirect back to original page
header('Location:'.$return_url);
}
?
view_cart.php
PHP Code
div class="view-cart"
?php
$current_url = base64_encode($url="http://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI']);
if(isset($_SESSION["products"]))
{
$total = 0;
echo 'form method="post" action="paypal-express-checkout/process.php"';
echo 'ul';
$cart_items = 0;
foreach ($_SESSION["products"] as $cart_itm)
{
$product_code = $cart_itm["code"];
$results = $mysqli-query("SELECT product_name,product_desc, price FROM cart WHERE product_code='$product_code' LIMIT 1");
$obj = $results-fetch_object();
echo 'li class="cart-itm"';
echo 'span class="remove-itm"a href="cart_update.php?removep='.$cart_itm["code"].'return_url='.$current_url.'"×/a/span';
echo 'div class="p-price"'.$currency.$obj-price.'/div';
echo 'div class="product-info"';
echo 'h3'.$obj-product_name.' (Code :'.$product_code.')/h3 ';
echo 'div class="p-qty"Qty : '.$cart_itm["qty"].'/div';
echo 'div'.$obj-product_desc.'/div';
echo '/div';
echo '/li';
$subtotal = ($cart_itm["price"]*$cart_itm["qty"]);
$total = ($total + $subtotal);
echo 'input type="hidden" name="item_name['.$cart_items.']" value="'.$obj-product_name.'" /';
echo 'input type="hidden" name="item_code['.$cart_items.']" value="'.$product_code.'" /';
echo 'input type="hidden" name="item_desc['.$cart_items.']" value="'.$obj-product_desc.'" /';
echo 'input type="hidden" name="item_qty['.$cart_items.']" value="'.$cart_itm["qty"].'" /';
$cart_items ++;
}
echo '/ul';
echo 'span class="check-out-txt"';
echo 'strongTotal : '.$currency.$total.'/strong ';
echo '/span';
echo '/form';
}else{
echo 'Your Cart is empty';
}
?
/div
/div
求php的sql语句,查询数据库中的热销商品
语句还是把数量也查询出来,PHP显示的时候不显示数量即可:
$sql="select name,jqian from ppten";
if ($res=mysql_query($sql)){
$i=1;
while (list($p)=mysql_fetch_row($res)){echo "第 $i 名: $pbr";$i++;}
mysql_free_result($res);
} else echo "执行 $sql 错误:".mysql_error();
网站名称:php商品数据库表,php商品展示
链接URL:http://pwwzsj.com/article/dsisdho.html