I wanted to learn something new over the weekend and decided to teach myself PHP
, DOM
, and MySQL
. As a starting project, I wanted to try adding the following table that I've extracted from another website into my own database.
http://i67.tinypic.com/fuot5g.jpg
However, I ran into a wall when I was trying to add the data (not including the header line like 'No.'
, 'Ticker'
, etc..) into my own database.
Here is an extract of my code:
<?php
$dom = new DOMDocument;
$dom->loadHTML($document);
$tbl = $dom->getElementByID('forex_performance');
$trneeded = $tbl->getElementsByTagName('tr');
foreach ($trneeded as $row) {
foreach ($row->getElementsByTagName('td') as $cell) {
$cellarray[] = $cell->nodeValue;
$query = "INSERT INTO sampletable (no, ticker, price, perf5, perfhour, perfday, perfweek, perfmonth,perfquart, perfhalf, perfyear, perfytd, date, time) VALUES ('')
mysql_query($query);
}
}
?>
I am able to get specific data from the cell array, but I can't for the life of me figure out how to insert them into my db.
I'm still really new to this and hope my question made sense! I would really appreciate it if someone could help me by pointing me in the right direction!