Jump to content

[SOLVED] mysql insert into


Exoon

Recommended Posts

Hello, im trying to grab data from another website and insert it into a database.

 

For some reason it wont pick up the [1] and it just keeps ignoring it. Is there any way i can write it so it will pick it up.

 

  $connect = mysql_connect(localhost, root, '');
  $db = mysql_select_db(games, $connect) or die(mysql_error());
  
  $page_contents = file_get_contents("http://shop.gameplay.co.uk/webstore/release_calendar.asp?platform=ALL&themonth=1&theyear=2008&radar_show=1");

  preg_match_all('#<b>(.*)</a></b>#', $page_contents, $gnames); // Gets the name of the games

  for($i=0; $i<73; $i++){
  
  $insert = "INSERT INTO release(name) VALUES($gnames[1][$i])";
  
  if (mysql_query($insert)){
    echo "Game Added Added<br>";
    echo $gnames[1][$num];
  }else {
    die(mysql_error());
  }
  }

Link to comment
Share on other sites

When i type

 

print_r($gnames);

 

I get a list of all the game names in the array including the

<b>

tag

 

if i type

 

print_r($gnames[1][15])

 

I get entry 15 in that array. So i want to put all 72 entries into my dB but it is just ignoring the number 1 so it wont actually list anything

Link to comment
Share on other sites

Try this...where did $num come from?

 

  $connect = mysql_connect(localhost, root, '');
  $db = mysql_select_db(games, $connect) or die(mysql_error());
  
  $page_contents = file_get_contents("http://shop.gameplay.co.uk/webstore/release_calendar.asp?platform=ALL&themonth=1&theyear=2008&radar_show=1");

  preg_match_all('#<b>(.*)</a></b>#', $page_contents, $gnames); // Gets the name of the games

  for($i=0; $i<73; $i++){
  
  $insert = "INSERT INTO release(name) VALUES('$gnames[1][$i]')";
  
  if (mysql_query($insert)){
    echo "Game Added Added<br>";
    echo $gnames[1][$i];
  }else {
    die(mysql_error());
  }
  }

Link to comment
Share on other sites

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.