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
https://forums.phpfreaks.com/topic/79741-solved-mysql-insert-into/
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

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());
  }
  }

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.