SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Michigan
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Grouping MySQL Records with 1 ID - Need an Approach

    I have a database with about 35,000 records of cheat codes. Each record is a cheat code and has numerous fields, one being the title of the game. I need to take my database and group everything by game_name and apply a new field "game_id".

    What I need to do is: Take my existing database and update it with the game_id, then insert into a new table I created called games with the same game_id and the game_name.

    I have some code I made. I won't post the forms and everything, just the loop code that updates it. When I use it works for awhile and it goes haywire.

    PHP Code:
    foreach($game_id as $games) {


        
    $execQuery mysql_query("INSERT INTO games (`game_id`, `game_name`, `console_id`)
            VALUES ('', '
    $games', '$conid')");


        
    $newID mysql_insert_id();

        
    //echo $newID . "<BR>\n";

        
    $updateQuery mysql_query("UPDATE cheats SET game_id='$newID
            WHERE console_id='
    $conid' AND origional_game_name='$games'");

    Not sure what to do at this point. Perhaps someone has an overall better solution?

  2. #2
    Who turned the lights out !! Mandes's Avatar
    Join Date
    May 2005
    Location
    S.W. France
    Posts
    2,496
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    You should delete the games name field from your old table once youve created the games table.

    If you need to know the game name you can get it through referencing the games table.
    A Little Knowledge Is A Very Dangerous Thing.......
    That Makes Me A Lethal Weapon !!!!!!!!

    Contract PHP Programming

  3. #3
    SitePoint Addict
    Join Date
    Mar 2002
    Location
    Michigan
    Posts
    260
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I figured out my problem... had some bad data in a few fields. I'm running my script right now and it seems to be importing the data into the new field just fine.

    There won't be a use for having two fields with the same name so I might as well take it out after I'm done running the script. Thanks for the suggestion.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •