1
SET @rownum:=0;
SELECT @rownum:=@rownum+1 as count, student_name,student_info FROM studnet;

このクエリをコード点火モデルにマージしたい...

カウントが動的である場合、つまりレコードが増加するにつれて増加する次のような出力が必要です:::

count  student_name  student_info
1        Ram          Palpa
2        Shyam        Butwal
4

1 に答える 1

0

CodeIgniter のデータベース カスタム関数呼び出しの使用:

application/config/database.phpにmysqliが設定されていると仮定します。

$db['default']['dbdriver'] = 'mysqli';

次に、モデルで:

$this->load->database();

// Perform a mysqli_multi_query
$db_id = $this->db->conn_id;
$this->db->call_function("multi_query", $db_id, "SET @rownum:=0; SELECT @rownum:=@rownum+1 as count, student_name,student_info FROM student;"
$this->db->call_function('next_result', $db_id);  // Skip the first query in this multi_query since you want the result from the second query
$result = $this->db->call_function("store_result", $db_id);

// Output each row
while($row = $result->fetch_assoc()){
    $row['count'] . " ". $row['student_name'] . " " . $row['student_info'] . "\n";
}
于 2013-06-05T02:47:44.790 に答える