Home > Backend Development > PHP Tutorial > 我的表P_id没设置为自动增长,插入数据时我要通过程序控制p_id自动增长,该怎么做。求教

我的表P_id没设置为自动增长,插入数据时我要通过程序控制p_id自动增长,该怎么做。求教

WBOY
Release: 2016-06-23 13:33:37
Original
982 people have browsed it

//添加商品SQL	mysql_query("insert into t_product	(	p_id	categorycode,	subcategorycode,	price,	shopid	)	values	(		'$categorycode',	'$subcategorycode',	'$price',	$s_id	)");	
Copy after login


回复讨论(解决方案)

list($pid) = mysql_fetch_row(mysql_query("select max(p_id)+1 from t_product"));//添加商品SQL    mysql_query("insert into t_product    (    p_id    categorycode,    subcategorycode,    price,    shopid    )    values    (     '$p_id',    '$categorycode',    '$subcategorycode',    '$price',    $s_id    )");
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template