Jump to content

Insert image names into mysql - list pulled from remote server (cURL)


visda04

Recommended Posts

I have successfully pulled a list of image names from a remote web server:

See my list here:

http://www.katy2go.com/weather/loadoverlays.php

(if you view the source you can see where I think I am headed with this...)

 

I would like to insert the three bits of information, for each image, into my mysql database. With my limited knowledge mysql skills I am having great difficulties with the INSERT or UPDATE query to make this happen. Can some one offer assistance...

 

 

<?php
ini_set('display_errors', 1);

// Make a MySQL Connection
$link = mysql_connect('', '', '') ;
mysql_select_db("") or die(mysql_error());
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';


$html = file_get_contents('http://www.srh.noaa.gov/ridge/RadarImg/NCR/HGX/');

    /*** a new dom object ***/
    $dom = new domDocument;

    /*** load the html into the object ***/
    $dom->loadHTML($html);

    /*** discard white space ***/
    $dom->preserveWhiteSpace = false;

    /*** the table by its tag name ***/
    $tables = $dom->getElementsByTagName('table');

    /*** get all rows from the table ***/
    $rows = $tables->item(0)->getElementsByTagName('tr');

    /*** loop over the table rows ***/
    foreach ($rows as $row)
    {
        /*** get each column by tag name ***/
        $cols = $row->getElementsByTagName('td');

/*** echo the values ***/
$icon=$cols->item(0)->nodeValue;
     //   echo $cols->item(0)->nodeValue.'<br />';
  echo $icon.'<br />';
$image=$cols->item(1)->nodeValue;
    //    echo $cols->item(1)->nodeValue.'<br />';
  echo $image.'<br />';
$when=$cols->item(2)->nodeValue;
    //    echo $cols->item(2)->nodeValue.'<br />';
  echo $when.'<br />';
$howbig=$cols->item(3)->nodeValue;
    //    echo $cols->item(3)->nodeValue;
  echo $howbig.'<br />';
        echo '<hr />'; 


}
?> 

 

Thanks,

Robert

  • 2 weeks later...

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.