?
Solved

PHP MySQL - Save query results to table when don't know exact number of records

Posted on 2009-04-16
1
Medium Priority
?
1,015 Views
Last Modified: 2013-12-12
How can I write a MySQL query (using PHP), that automatically saves the results to a different table?  I am a beginner at this, and although it seems like I should know how, I can't figure it out.  What confuses me is that each time you run the query, you will get a different number of records.  So you may get 1 record and then the next time the query is run you may get 1000 records.  

Can anyone point me in the right direction here?
0
Comment
Question by:fastfind1
1 Comment
 
LVL 39

Accepted Solution

by:
Roger Baklund earned 2000 total points
ID: 24164272
You can use this syntax to create a table based on the result of a query, i.e. save the result to a table:

CREATE TABLE NewTable SELECT ...

This will make a copy of the result. You talk about a query that returns different results each time you run it. The "NewTable" will not change, it will contain a copy of the result you got at that single run. If you need the table to change when the query changes, you can use a view:

CREATE VIEW ViewName AS SELECT ...

Now "ViewName" will change whenever the SELECT result changes, you can do

SELECT * FROM ViewName

...and it will be equivalent to running the original SELECT query.
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
It’s a season to be thankful, and we’re thankful for users like you who engage on site, solve technology problems, and network with others in the industry. What tech are we most thankful for? Keep reading.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
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…
Suggested Courses
Course of the Month16 days, 11 hours left to enroll

862 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