[Last Call] Learn about multicloud storage options and how to improve your company's cloud strategy. Register Now

x
?
Solved

Insert multiple rows based on number of clients from another table

Posted on 2010-09-06
2
Medium Priority
?
520 Views
Last Modified: 2013-12-13
Using php and mysql,

I have a table called "certificates" and another table called "clients". I'd like to issue a certificate to every client in the database based on the existance of their user_id within the client table.

Basic logic being

Grab all unique user_ids from table clients

Insert into certificates the certificate value (from POST data) and a new row for every unique user_id

So the end result is if there are 10 user_ids in clients, 10 certificates will be issued... 1 for each client. I do store the user_id in the certificate table for obvious reasons.
0
Comment
Question by:Russelauto
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 6

Accepted Solution

by:
nasirbest earned 2000 total points
ID: 33611852
Your question is not clear. what happen if you POST certificate value twice
To keep things simple, I assume you will not do that, or on another post 10 more certificates entries will be created for clients.

here is code
$cert   = $_POST['certificate'];

// assume certificate table has two columns user_id and cert_value
$result = mysql_query("INSERT INTO certificate (user_id, cert_value) SELECT DISTINCT user_id, '$cert' FROM clients");

Open in new window

0
 

Author Closing Comment

by:Russelauto
ID: 33612667
Thank you for your quick response.
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows the steps required to install WordPress on Azure. Web Apps, Mobile Apps, API Apps, or Functions, in Azure all these run in an App Service plan. WordPress is no exception and requires an App Service Plan and Database to install
In this blog, we’ll look at how improvements to Percona XtraDB Cluster improved IST performance.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question