通常、あなたは、一意の識別子を渡すgetCompanyDetailsByID()
のようなもの、あなたのモデル関数を呼び出しますし、それに応じて、単一の結果オブジェクトを返します。
<?php
function getCompanyDetailsByID($id)
{
$this->db->select('coreCompanyName, coreContactName, coreContactEmail');
$this->db->where('coreCompanyID', $id);
return $this->db->get('core')->first_row();
}
"coreCompanyID"をプライマリカラム名に置き換えてください。
ADDITION:
<?php
function getCompanyDetails()
{
$this->db->select('coreCompanyName, coreContactName, coreContactEmail');
return $this->db->get('core')->result();
}
// And then in your controller:
function display()
{
$this->load->model('core');
$companies = $this->core->getCompanyDetails();
// Here's where you would probably load the data into a view
foreach ($companies as $company)
{
echo $company->coreCompanyName.'<br />';
}
}
FINAL ANSWER:
は、ここでは、すべての企業の情報を取得する方法をです! :P
<?php
function companyDetails()
{
static $details;
if (!$details)
{
$this->db->select('coreCompanyName, coreContactName, coreContactEmail');
$this->db->where('coreCompanyID', $id);
$details = $this->db->get('core')->first_row();
}
return $details;
}
今、あなたは、その関数への複数の呼び出しを行うことができ、それが唯一例えば、一度データベースをヒットする:一度だけ使用しているデータベースを打つこと
<?php
echo $this->core_model->companyDetails()->coreCompanyName;
// do stuff
echo $this->core_model->companyDetails()->coreContactName;
// more stuff
echo $this->core_model->companyDetails()->coreContactEmail;
すべて。
しかし、モデルにIDを渡す必要があることはわかりますか? –
どのような結果が必要なのでしょうか?すべての企業を取得したい場合、それは別の話ですが、私はその答えを変更する必要があります。 – landons
しかし、このデータベースには1社しかいないので、データを抽出したかっただけです –