Jump to content

Recommended Posts

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

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.'")');

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.