Solved

Insert multiple rows based on number of clients from another table

Posted on 2010-09-06
2
468 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 500 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

813 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now