嘿傢伙,看看這個,也許你可以幫助我。 這段代碼很自我解釋,它通過cron工作重複自己。Mysql,重置id的
<?php
$dbhost = 'blabla';
$dbuser = 'blabla';
$dbpass = 'blabla';
$dbname = 'blabla';
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
$table = 'cron';
$feed = 'a big xml feed';
$xml = simplexml_load_file($feed);
mysql_query("TRUNCATE TABLE ".$table.""); // empties cron
foreach($xml->performerinfo as $performerinfo)
{
bla bla inside foreach to get data from xml
mysql_query("INSERT INTO ".$table." (performerid, category, subcategory, build, hairlength, ethnicity, willingness, pic0, pic1, pic2, pic3, pic4, age) VALUES ('$performerid', '$category', '$subcategory', '$build', '$hairlength', '$ethnicity', '$willingness', '$pic0', '$pic1', '$pic2', '$pic3', '$pic4', '$age')");
} // inserts into cron
mysql_query("TRUNCATE TABLE newtable"); // empties newtable
mysql_query ("INSERT INTO newtable SELECT * FROM ".$table." WHERE ethnicity = 'White' AND age BETWEEN '30' AND '45' AND build <> 'above average' AND build <> 'large' AND build <> 'average' AND hairlength <> 'short'"); // inserts into newrtable
?>
的問題,希望你能理解我;)
表的Cron有編號的,從1到1000
id int(11) No auto_increment
時篩選cron和插入行到newtable中,我得到的ID喜歡:20,65,145,699等
如何重置新表的ID,使它們從1到35連續出現,可以說... 強文本
真的需要解決它,因爲我使用這個代碼與wordpress循環,並且我需要一種方法來處理循環內的這個問題 – webmasters 2010-08-02 16:33:54
@webmasters爲什麼?如果它是一個自動增量,這不應該是必要的。如果您需要爲其分配帖子ID,則它不應該是自動增量。 – 2010-08-02 17:01:59