0

モデルでグローバル変数を作成して mysql テーブルの id フィールドをインクリメントしようとしていますが、CI ではグローバル変数を作成できません。

私は周りを検索しましたが、人々はライブラリを作成し、そこでグローバル変数を宣言し、モデルにライブラリをロードして変数を使用する必要があると述べています。

私はそのアプローチを理解していますが、どのように/どこで変数の値をインクリメントして、次に関数で呼び出されたときに +1 になるようにできますか?

事前に助けてくれてありがとう

編集: 私がやろうとしているのは、テーブルに新しい行を挿入するたびに、最後のエントリ ID 番号から続行したい、つまり、テーブルの最後の ID 番号が 9 である、その番号からインクリメントしたいということです新しい行のID番号を10にします

4

1 に答える 1

0

If you're able to access the database through CI you can use the Active Record count_all() function.

From CI docs http://ellislab.com/codeigniter/user-guide/database/active_record.html

Permits you to determine the number of rows in a particular table. Submit the table name in the first parameter. Example:

echo $this->db->count_all('my_table');

// Produces an integer, like 25

You would just get the number of rows in the table returned and add 1 for the row in your new entry.

于 2012-12-27T21:33:30.857 に答える