Best pratice for double queries at a time? (PHP)
Hi.
So, I have to get 2 sets of data (from two different table competition and user) to determine which competition the user has already registered or not by checking the participation table (many-to-many relationship since, multiple users can join multiple competitions). I thought of doing;
2 Queries (using PHP's mysqli::multi_query)
Query all from competition to set the values of option tag in the select tag and query from participant to compare the values of which competition the users have registered. If it is the same value then add disabled attribute into the option tag. So, users can only pick the option that they have not registered yet.
1 Query
Query all from competition and let users pick the option tag including the one they have already registered. However, during inserting the data query, include a check for duplicate of the same data (fk_user_id and fk_competition_id) using the ON CONFLICT (PgSQL) or ON DUPLICATE (MySQL). Then, handle the error accordingly to the user.
PS: I cannot use UNIQUE for both column since the same user can register for another competition and a competition can be participated by another user.
What do you think?
Thank you for you time.
Please or to participate in this conversation.