manhattes Posted July 30, 2015 Share Posted July 30, 2015 I would like to save the results of this query to a table. What should I add under the WHILE statement? What would the format of the INSERT INTO statement? $query = "SELECT s.SName, s.Symbol, c.`Interventions`, c.`Study Results`, c.`Completion Date`, c.`First Received`, c.`Primary Completion Date` FROM Stocks s LEFT JOIN Calendar as c ON c.SName LIKE CONCAT('%', s.SName, '%' )LIMIT 20"; $sql51="INSERT INTO CombinedList $query)"; $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)){ $result51 = mysql_query($sql51); echo "Moved " . $row[SName] . " from searchable database into revised search table."; echo "<br>"; Link to comment https://forums.phpfreaks.com/topic/297559-saving-results-of-query-to-table/ Share on other sites More sharing options...
Barand Posted July 30, 2015 Share Posted July 30, 2015 Specify the columns to receive the data INSERT INTO combinedList (col, names, go, here,) SELECT ..... Link to comment https://forums.phpfreaks.com/topic/297559-saving-results-of-query-to-table/#findComment-1517771 Share on other sites More sharing options...
manhattes Posted July 30, 2015 Author Share Posted July 30, 2015 Specify the columns to receive the data INSERT INTO combinedList (col, names, go, here,) SELECT ..... Thank you Barand, I was going in that direction. Do you have to list all of the columns that are in the table? Or only the ones I want filled in? Thank you for your help! $query = "INSERT INTO CombinedList (SName2, Symbol, Interventions, Study Results, Completion Date, First Received, Primary Completion Date) SELECT s.SName, s.Symbol, c.`Interventions`, c.`Study Results`, c.`Completion Date`, c.`First Received`, c.`Primary Completion Date` FROM Stocks s LEFT JOIN Calendar as c ON c.SName LIKE CONCAT('%', s.SName, '%' )LIMIT 20"; Link to comment https://forums.phpfreaks.com/topic/297559-saving-results-of-query-to-table/#findComment-1517772 Share on other sites More sharing options...
Barand Posted July 30, 2015 Share Posted July 30, 2015 Just those that you want filled in Link to comment https://forums.phpfreaks.com/topic/297559-saving-results-of-query-to-table/#findComment-1517775 Share on other sites More sharing options...
manhattes Posted July 30, 2015 Author Share Posted July 30, 2015 Just those that you want filled in $query = "INSERT INTO CombinedList (Sname2, Symbol, First Received, Completion Date, Results First Received, Primary Completion Date) SELECT s.SName, s.Symbol, c.`Interventions`, c.`Study Results`, c.`Completion Date`, c.`Results First Received`, c.`Primary Completion Date` FROM Stocks s LEFT JOIN Calendar as c ON c.SName LIKE CONCAT('%', s.SName, '%' )LIMIT 20"; $result = mysql_query($query) or die(mysql_error()); I am getting the error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'Received, Completion Date, Results First Received, Primary Completion Date) SEL' at line 1 Link to comment https://forums.phpfreaks.com/topic/297559-saving-results-of-query-to-table/#findComment-1517777 Share on other sites More sharing options...
Barand Posted July 30, 2015 Share Posted July 30, 2015 Don't have column names containing spaces, use underscores. (If you really must, surround the name with backticks (note: not single quotes) eg `Completion Date`) Link to comment https://forums.phpfreaks.com/topic/297559-saving-results-of-query-to-table/#findComment-1517779 Share on other sites More sharing options...
manhattes Posted July 30, 2015 Author Share Posted July 30, 2015 Don't have column names containing spaces, use underscores. (If you really must, surround the name with backticks (note: not single quotes) eg `Completion Date`) Awesome that was it. Now it Says: Duplicate entry '' for key 'PRIMARY' When I look in the DB it seems to only do the first row of data and then stop Link to comment https://forums.phpfreaks.com/topic/297559-saving-results-of-query-to-table/#findComment-1517787 Share on other sites More sharing options...
manhattes Posted July 30, 2015 Author Share Posted July 30, 2015 Awesome that was it. Now it Says: Duplicate entry '' for key 'PRIMARY' When I look in the DB it seems to only do the first row of data and then stop I fixed it by REMOVING the Primary Index. I will use a different column to keep track.. Thank you again Barand. Link to comment https://forums.phpfreaks.com/topic/297559-saving-results-of-query-to-table/#findComment-1517788 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.