0

我正在使用以下代码:

for(i=1; i<16; i++) {
visible =1;
if(i > 5) {visible = 0 ;}
cObj.insert('siteCategoriesVideos',{
clientID:p.clientID,
position:i,
visible:visible,
title:'Video Album'+i

});
videoCatID = cObj.lastInsertId();
                    }

console.log('inserted video cats '+videoCatID );

for(i=1; i<101; i++) {
visible =1;
categoriesArray ='';
if(i > 10) {visible = 0 ;}
if(i === 1 || i ===2) {newVideoCatID = videoCatID-14;categoriesArray =     '[{"index":"0","value":'+newVideoCatID+'}]';}
if(i === 3 || i ===4) {newVideoCatID = videoCatID-13;categoriesArray = '[{"index":"1","value":'+newVideoCatID+'}]';}
if(i === 5 || i ===6) {newVideoCatID = videoCatID-12;categoriesArray = '[{"index":"2","value":'+newVideoCatID+'}]';}
if(i === 7 || i ===8) {newVideoCatID = videoCatID-11;categoriesArray = '[{"index":"3","value":'+newVideoCatID+'}]';}
if(i === 9 || i ===10) {newVideoCatID = videoCatID-10;categoriesArray = '[{"index":"4","value":'+newVideoCatID+'}]';}


// musicCatId is the last id in the 15 rows
cObj.insert('siteVideos',{
clientID:p.clientID,
position:i,
visible:visible,
categoriesArray:categoriesArray,
title:'Video'+i

});

我有 2 个问题。1. 有没有更有效的方法来产生记录。2. 我需要确保每次插入都会产生连续的记录行。

即,表 siteCategoriesVideos 将创建一个 catID 运行(autoInc 列)将产生 3-4-5-6-7-8-9 等,并且与 siteVideo 表相同。

我假设如果该命令由不同的用户同时运行,则将随机创建行。

干杯

史蒂夫

4

0 回答 0