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

Posted on 2009-04-16
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?
Question by:fastfind1
    1 Comment
    LVL 39

    Accepted Solution

    You can use this syntax to create a table based on the result of a query, i.e. save the result to a table:


    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:


    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.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    Join & Write a Comment

    Suggested Solutions

    Both Easy and Powerful How easy is PHP? (  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
    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…
    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 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 …

    746 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

    16 Experts available now in Live!

    Get 1:1 Help Now