[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Insert multiple rows based on number of clients from another table

Posted on 2010-09-06
2
Medium Priority
?
525 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
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

Get quick recovery of individual SharePoint items

Free tool – Veeam Explorer for Microsoft SharePoint, enables fast, easy restores of SharePoint sites, documents, libraries and lists — all with no agents to manage and no additional licenses to buy.

Question has a verified solution.

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

In this article, we’ll look at how to deploy ProxySQL.
In this article, I’ll talk about multi-threaded slave statistics printed in MySQL error log file.
The viewer will learn how to dynamically set the form action using jQuery.
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month20 days, 6 hours left to enroll

872 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