View Full Version : Import Data into mySQL
nikomou
12-19-2005, 07:17 PM
Hey,
I want to automatically update (using a php script) a mySQL database using pipeline ( | ) seperated data from a webpage provided by an affiliate.
Here's some example data from the webpage (feed.asp):
Handset | Make | ID | date | features | description |
Nokia N92 | Nokia | n92 | 999 | f,c,v,m,b,,g | The Nokia...... |
Does anyone know how this can be done?
ob_start();
include("http://www.affiliate.com/feed.asp");
$feed = ob_get_contents();
ob_end_clean();
$heads = explode("\n", $feed);
$data = explode("|", $feed[1]);
$heads = explode("|", $feed[0]);
for($i=0;$i<count($heads);$i++) {
// Insert data into table - $heads[$i] and $data[$i]
}
nikomou
12-22-2005, 05:33 PM
Thanks Twey,
how would i insert that into a table?!
See the MySQL INSERT (http://dev.mysql.com/doc/refman/5.1/en/loading-tables.html) statement.
nikomou
12-23-2005, 04:45 PM
Something like this?!?!?!
mysql_query(INSERT INTO $table VALUES ($heads[$i],$data[$i]));
No, you'd need to use the for loop to construct the query then execute it outside.
$query = "INSERT INTO $table VALUES (";
for($i=0;$i<count($heads);$i++)
$query .= $data[$i] . ( $i + 1 < count($heads) ? "," : "" );
$query .= ");";
mysql_query($query);
nikomou
12-27-2005, 01:29 PM
Twey, this is what i have so far..
<?
ob_start();
include("http://www.mysite.com/feed.html");
$feed = ob_get_contents();
ob_end_clean();
$heads = explode("\n", $feed);
$data = explode("|", $feed[1]);
$heads = explode("|", $feed[0]);
for($i=0;$i<count($heads);$i++) {
$username="user";
$password="pass";
$database="database";
$table="table";
mysql_connect(localhost,$username,$password);
@mysql_select_db($database) or die( "Unable to select database");
$query = "INSERT INTO $table VALUES (";
for($i=0;$i<count($heads);$i++)
$query .= $data[$i] . ( $i + 1 < count($heads) ? "," : "" );
$query .= ");";
mysql_query($query);
}
?>
It just doesnt seem to add anything onto the database
Powered by vBulletin® Version 4.2.2 Copyright © 2021 vBulletin Solutions, Inc. All rights reserved.