Exoon Posted December 1, 2007 Share Posted December 1, 2007 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 More sharing options...
wsantos Posted December 1, 2007 Share Posted December 1, 2007 did you get the right value? print_r($gnames); Link to comment https://forums.phpfreaks.com/topic/79741-solved-mysql-insert-into/#findComment-403823 Share on other sites More sharing options...
Exoon Posted December 1, 2007 Author Share Posted December 1, 2007 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 https://forums.phpfreaks.com/topic/79741-solved-mysql-insert-into/#findComment-403826 Share on other sites More sharing options...
mlin Posted December 1, 2007 Share Posted December 1, 2007 $insert = "INSERT INTO release(name) VALUES('{$gnames[1][$i]}')"; Link to comment https://forums.phpfreaks.com/topic/79741-solved-mysql-insert-into/#findComment-403856 Share on other sites More sharing options...
wsantos Posted December 1, 2007 Share Posted December 1, 2007 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 https://forums.phpfreaks.com/topic/79741-solved-mysql-insert-into/#findComment-403858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.