inserts 'Array' into mysql table

Posted by Noah Smith on Stack Overflow See other posts from Stack Overflow or by Noah Smith
Published on 2012-09-13T21:16:23Z Indexed on 2012/09/13 21:38 UTC
Read the original article Hit count: 146

Filed under:

i want to insert an array into a mysql table. The array is produced by script scanning all the links, converting into absolute links and then displaying them in an array. i decided to mysql_query the array into the table but now i am stuck. it only posts 'Array', instead of every row from the array into a different row. Any ideas??!

   <?php
 require_once('simplehtmldom_1_5/simple_html_dom.php');
 require_once('url_to_absolute/url_to_absolute.php');
   $connect = mysql_connect("xxxx", "xxxx", "xxx") or die('Couldn\'t connect to MySQL Server: ' . mysql_error());
    mysql_select_db("xxxx", $connect ) or die('Couldn\'t Select the database: ' . mysql_error( $connect ));

  $links = Array();
  $URL = 'http://www.theqlick.com'; // change it for urls to grab  
  // grabs the urls from URL 
 $file  = file_get_html($URL);
 foreach ($file->find('a') as $theelement) {
  $links[] = url_to_absolute($URL, $theelement->href);
  } 
  print_r($links);
  mysql_query("INSERT INTO pages (url) VALUES ('$links[]')");
  mysql_close($connect);

© Stack Overflow or respective owner

Related posts about php