how to get value from database

https://stackoverflow.com/questions/8541291/codeigniter-this-db-get-how-do-i-return-values-for-a-specific-row




50down voteaccepted

SOLUTION ONE

$this->db->where('id','3');// here we select every column of the table
$q = $this->db->get('my_users_table');
$data = $q->result_array();

echo($data[0]['age']);

SOLUTION TWO

// here we select just the age column
$this->db->select('age');
$this->db->where('id','3');
$q = $this->db->get('my_users_table');
$data = $q->result_array();

echo($data[0]['age']);

SOLUTION THREE

$this->db->select('age');
$this->db->where('id','3');
$q = $this->db->get('my_users_table');// if id is unique, we want to return just one row
$data = array_shift($q->result_array());

echo($data['age']);

SOLUTION FOUR (NO ACTIVE RECORD)

$q = $this->db->query('SELECT age FROM my_users_table WHERE id = ?',array(3));
$data = array_shift($q->result_array());
echo($data['age']);
shareedit
  • 0 utilizatori au considerat informația utilă
Răspunsul a fost util?

Articole similare

database commands

from https://codeigniter.com/userguide2/database/active_record.html...

php excel, how to set clickable url

$this->phpExcelObj->getActiveSheet()->setCellValueExplicit('‌​A1', $id,...

For online form capture multimedia on mobile devices

<p>Capture Image: <input type="file" accept="image/*" id="capture" capture="camera">...

add button to perform function

https://www.w3schools.com/jsref/tryit.asp?filename=tryjsref_onclick <!DOCTYPE...