Solved

Insert multiple rows based on number of clients from another table

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

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to create a scatter graph with straight lines 6 26
Form Processing in PHP 11 31
mysqli 3 21
Bootstrap collapse causes odd behavior with php loop 7 22
Creating and Managing Databases with phpMyAdmin in cPanel.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

910 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

23 Experts available now in Live!

Get 1:1 Help Now