sql - Displaying multiple values from same name MySQL database field in Codeigniter & Dwoo -


I am creating a web application and in my application to use similar table and field names in Wordpress Option is selected. That means I mean how I have user table and how WordPress works like a user table.

Forgive me to make this question so big, I have chosen to be as descriptive as possible in this question.

The user table contains the following table prices;

umeta_id
user_id
meta_key
meta_val

As an example, I have the following data: ureata table;

user_id = 1
meta_key = first_name
meta_value = 'dwin'

user_id = 1
meta_key = last_name
meta_value = charrington

< P> I have the following example data in my user table;

ID = 1
USER_LOGIN = Administrator
user_pass = ui3h423h4o82374
user_email = test@test.com

Actually what do I do using joining It seems like it looks like the type of work:

  $ db = $ this- & gt; Db; $ Db- & gt; Select ('wolf_users.id, wolf_usermeta.user_id AS ID', FALSE); $ Db- & gt; Select ('wolf_users.user_login AS user_login', FALSE); $ Db- & gt; Select ('wolf_users.user_email AS user_email', FALSE); $ Db- & gt; Select ('wolf_users.user_status as status', FALSE); $ Db- & gt; Select ('wolf_usermeta.meta_key AS meta_key', FALSE); $ Db- & gt; Select ('wolf_usermeta.meta_value as meta_value', FALSE); $ Db- & gt; ('Wolf_users'); $ Db- & gt; Join ('wolf_usermeta', 'wolf_users.id = wolf_usermeta.user_id', 'left'); $ Db- & gt; Where ('wolf_usermeta.user_id = wolf_users.ID'); $ Q = $ db- & gt; get receive (); Return $ q- & gt; Result_are (); First of all: the result_array is returning duplicate data from my database (which is a little strange) whether I have formatted my wrong way or is there something I remember to stop it. Am doing Results return to results using only $ Q- (seems to stop duplicate data being returned).  

I am using Dwoo for my templating and when I echo out the variables that have kept the data using print_r, it shows a duplicate query while using the query query, but when using the result_ar Displays duplicate content (as it sometimes omits usb meritated).

I am using this database query, one page on one page lists all the customers in the database and then matches the data that matches the user table. So my question is how do I use the data from both tables and then in my visual template, can I display it in my application using a foreach?

Do you understand how works right?

By joining a user into meta data, the user will be repeated for each meta data entry that you extracted.

It. After dragging data by splitting your query out of the database or in two questions, a foreach can be avoided.

  User $ = $ this-> Db - & gt; Selection ('id, USER_LOGIN, User_email, user_status as status') - & gt; Where ('id', $ id) - & gt; Receive ('wolf_users') - & gt; Row_array (); If (! $ User) {return false; } $ User ['meta'] = $ this- & gt; Db - & gt; ('Meta_key, meta_value') - & gt; Select where ('user_id', $ id) - & gt; Receive ('wolf_usermeta') - & gt; Result_array (); $ User return;  

Some common MySQL points and suggestions:

  as wolf_users.id, wolf_usermeta.user_id id  

No need, you only have to select the user id once. . Selection of the second will come in the first place, the only one that is definitely

  $ db-> Selection ('wolf_usermeta.meta_value as meta_value', FALSE);  

You do not have to do this, the table name will be removed from the result, so it's useless to change their name.

Good luck!


Comments