[wp-hackers] Creating / Inserting into Table named after WP Username

J.D. Grimes jdg at codesymphony.co
Mon Aug 26 19:42:43 UTC 2013


> Now that you bring it up however, I suppose I could have the profile page just check if the
> current user_id exists, and if yes then show the basic profile page with just their display_name etc.

Yes, I think that is what I would do.

You can get the ID of the current user in several different ways. You can use get_current_user_id() (http://codex.wordpress.org/Function_Reference/get_current_user_id) to get just the ID. If you want o get the WP_User object for the current user, then use wp_get_current_user() (http://codex.wordpress.org/Function_Reference/wp_get_current_user).

> I should add, that the on page form used to submit this information is used
> multiple times for dated information input.  So if I use one table rather
> than a table for each user_id then every row (and every button submit)
> needs to grab the user-ID and input that with the form information so it
> can be extracted.  Thats why I was opting for table names prefixed with the
> user-id rather than rows with a user ID column.

Yes, but one table with a user_id column just makes sense to me. You are going to need to grab the user ID on each submit either way. I definitely wouldn't want to clutter my database with hundreds of tables -- that's a bad idea, trust us on that one.

On Aug 26, 2013, at 3:28 PM, Gregory Lancaster <greglancaster71 at gmail.com> wrote:

> OH I understand what you're asking.
> 
> I want to pass the User_ID to the new table upon registering because I am
> coding this for a profile page of sorts.  So after registering, and
> confirming registration they will load up say site.com/profile which will
> dynamically pull their information from a separate table using their
> user_id.  From that page they can enter different information that would be
> saved in this separate database (for each user).
> 
> So the extra information they will be adding does not need to be added
> right away, however to load the profile page with their display_name and
> basic information I do need the information passed.  Now that you bring it
> up however, I suppose I could have the profile page just check if the
> current user_id exists, and if yes then show the basic profile page with
> just their display_name etc.  But either way, once they enter information
> into the on page form and submit it, the user-ID needs to be passed.
> 
> Which is where I came up with passing the current user ID, since they would
> already be logged in and registered. Really most of the questions I asked
> in this thread are variations of "how can I take the user_id and pass it to
> a separate database upon registration (or upon form submit) so the
> information in their specific table can be dumped back on their profile
> page for viewing.
> 
> The information will (ideally) be outputted into a format where I could
> format it with google charts or some type of visual display for them.
> 
> I hope that clarifies man, and again I am new to the loop so I apologize if
> I am driving anyone insane here.  Any advice welcome :)
> 


More information about the wp-hackers mailing list