我使用以下代码:
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表相同。
我假设命令是由不同的用户同时运行的,同时会随机创建行。
干杯
SteveW