Just looking for a bit of advice on how to handle this:
In the past (many moons ago) when I did the occasional php/mysql work, it was relatively easy to pull/display data from a table using the table header in the "WHERE" query. (i.e. SELECT * FROM 'table' WHERE 'column-name' = 'query'). The tables would have columns for each piece of information such as email, phone, address, etc.
I am currently working on a project using a table that was installed into the database by a plugin where I want to use some of that data in a different area of the site not related to the plugin.
Instead of a column for each type of information as above, this table has
- a user_id column which is linked to the users wordpress account
- user_id a meta_key column. This column has entries such as address, phone number, etc. (these would be the column names in my above example)
- a meta_value column. This column holds the data for each type of meta_key (the actual address, phone number, etc.)
What I am looking to do is get the value for each item for a particular user_id and pre-fill a form that is submitted.
So their User ID, Name and email are pulled from the users table of the WP database when they are logged in using the wp_get_current_user() function. Once I have the User ID, I then want to display that user's address, phone number etc from the other table in my form but I'm stuck on the sql query
global $wpdb; $current_user = wp_get_current_user(); $uid = $current_user->ID; $table = $wpdb_>prefix . 'plugin-table';
I then want to select the user's address and phone number etc and display them as individual pieces of info, so:
$mobile $address $studentnumber
so that I can use them where needed
What would be the correct way to query the database to get the info I'm looking for?
Hope that all made sense...