当前位置: 代码迷 >> PHP >> 小弟我的表P_id没设置为自动增长,插入数据时小弟我要通过程序控制p_id自动增长,该如何做。求教
  详细解决方案

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

热度:100   发布时间:2016-04-28 17:20:43.0
我的表P_id没设置为自动增长,插入数据时我要通过程序控制p_id自动增长,该怎么做。求教
//添加商品SQL
mysql_query("insert into t_product
(
p_id
categorycode,
subcategorycode,
price,
shopid
)
values
(

'$categorycode',
'$subcategorycode',
'$price',
$s_id
)");


------解决思路----------------------
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
    )");
  相关解决方案