Home  >  Article  >  Backend Development  >  小弟我的表P_id没设置为自动增长,插入数据时小弟我要通过程序控制p_id自动增长,该如何做。求教

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

WBOY
WBOYOriginal
2016-06-13 12:21:04937browse

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

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

------解决思路----------------------
list($pid) = mysql_fetch_row(mysql_query("select max(p_id)+1 from t_product"));<br />//添加商品SQL<br />    mysql_query("insert into t_product<br />    (<br />    p_id<br />    categorycode,<br />    subcategorycode,<br />    price,<br />    shopid<br />    )<br />    values<br />    (<br />     '$p_id',<br />    '$categorycode',<br />    '$subcategorycode',<br />    '$price',<br />    $s_id<br />    )");

Statement:
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