I am editing somebody else’s code and I am a PHP beginner.
I want to access the contents of a column called “email” in the database “tga_purchase_items” where the “id” of the row is “14”. I want to save the output to a variable “$sp_email”.
The code I have is thus:
$sp_email = $this->db->select("email")->from("tga_purchase_items")->where("id", 14)->get();
The variable is coming out empty although the database field is definitely populated.
What am I doing wrong? I am not used to this “->” syntax at all.
The syntax used in your database leans towards Codeigniter and active record.
If this is the case, the following code will retrieve the email column.
What you’re missing is retrieving the data from the result set which you get. The
get()functions return a result set which is similar to the native MySQLi Result class. This means that you need to retrieve the data you want from this set. There are various functions available in CodeIgniter to do this, namelyrow(),row_array(),result()andresult_array()which you can read about on their manual page.