Michan Posted October 9, 2007 Share Posted October 9, 2007 Hi all, I'm trying to create a piece of code that gets rows from a database, formats them as "|1|2|3|4|..", and then inserts them into the database. Here's my code: function games() { echo('|'); $get = mysql_query('SELECT id FROM vg_games ORDER BY popular_week DESC LIMIT 0,100'); while($show = mysql_fetch_array($get)) { echo($show['id'].'|'); } } function scores() { echo('|'); $get = mysql_query('SELECT popular_week FROM vg_games ORDER BY popular_week DESC LIMIT 0,100'); while($show = mysql_fetch_array($get)) { echo($show['popular_week'].'|'); } } $games = games(); $scores = scores(); mysql_query('INSERT INTO vg_popular (games, scores) VALUES ("'.$games.'", "'.$scores.'")'); But all it does is display what I want to go into the database on that very page: |2086|132|864|1632|407|466|900|1654|1655|1656|1657|1658|1659|1660|1661|1662|1699|2013|2014|2015|2016|2017|1|2|3|4|2114|6|8|9|617|10|23|22|20|21|19|24|2113|25|26|27|28|29|30|31|32|33|34|35|36|37|38|2112|40|41|42|71|44|45|46|47|48|49|50|51|52|53|54|55|56|57|58|59|60|61|62|63|64|65|66|67|68|69|70|72|73|74|75|449|77|78|79|80|81|82|2120|2119|86|87||10|3|2|2|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|1|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0|0| A new row in the database is created with the id and timestamp, but with the "games" and "scores" columns blank. How do I get about putting this data into the database, rather than outputting it on the page? Thanks in advance. - Mi Quote Link to comment https://forums.phpfreaks.com/topic/72430-solved-trying-to-perform-query-with-function/ Share on other sites More sharing options...
btherl Posted October 9, 2007 Share Posted October 9, 2007 Try this .. you'll need to make a similar change for games() function scores() { $get = mysql_query('SELECT popular_week FROM vg_games ORDER BY popular_week DESC LIMIT 0,100'); $all_values = '|'; while($show = mysql_fetch_array($get)) { $all_values .= $show['popular_week'].'|'; } return $all_values; } $games = games(); $scores = scores(); mysql_query('INSERT INTO vg_popular (games, scores) VALUES ("'.$games.'", "'.$scores.'")'); Quote Link to comment https://forums.phpfreaks.com/topic/72430-solved-trying-to-perform-query-with-function/#findComment-365257 Share on other sites More sharing options...
Michan Posted October 9, 2007 Author Share Posted October 9, 2007 Thank you very much, that worked flawlessly. Quote Link to comment https://forums.phpfreaks.com/topic/72430-solved-trying-to-perform-query-with-function/#findComment-365258 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.