Jump to content

twittoris

Members
  • Posts

    87
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

twittoris's Achievements

Member

Member (2/5)

0

Reputation

  1. I have a table I am trying to import to mySQL I am having trouble assigning the right variable which represents a column header to the correct column header in the mySQL table. <?php /********************************/ /* Code at http://legend.ws/blog/tips-tricks/csv-php-mysql-import/ /* Edit the entries below to reflect the appropriate values /********************************/ $databasehost = "xxx"; $databasename = "xxx"; $databasetable = "names"; $databaseusername ="xxx"; $databasepassword = "xxx"; $fieldseparator = "\t"; $lineseparator = "\n"; $csvfile = "AddEnt2.txt"; $con = @mysql_connect($databasehost,$databaseusername,$databasepassword) or die(mysql_error()); @mysql_select_db($databasename) or die(mysql_error()); $fcontents = file ('AddEnt2.txt'); # expects the csv file to be in the same dir as this script for($i=0; $i<sizeof($fcontents); $i++) { $line = trim($fcontents[$i],'\t'); // '\t' for tab delimeted $arr = explode('\t', $line); // '\t' for tab delimeted $name=implode("','",$arr); $PA=implode("','",$line); # if your data is comma separated # instead of tab separated # change the '\t' above to ',' $sql = "insert into $databasetable values ('$PA','$name')"; $sql = str_replace("''", mysql_escape_string("NULL"), $sql); $sql = str_replace("' '", mysql_escape_string("NULL"), $sql); mysql_query($sql); echo $sql ."<br>\n"; if(mysql_error()) { echo mysql_error() ."<br><b><font color=red>\n</b>"; } } ?>
  2. Also, Is it possible to store each table row in an array?
  3. i found some code that is helping me extract a table. Currently it works and extracts every single table row however it duplicates some of the rows. I am new to XPATH and would appreciate if someone could comment the following code so that I can alter it to meet my needs. Thanks. $newDom->appendChild($newDom->importNode($item,true)); $xpath = new DOMXPath( $newDom ); foreach ($item->attributes as $attribute) { for ($node = $item->firstChild; $node !== NULL; $node = $node->nextSibling) { if (($attribute->nodeName =='valign') && ($attribute->nodeValue=='top')) { print($node->nodeValue); } else { print("<br>".$node->nodeValue); } } print("<br>");
  4. yeah I have worked through all the other issues. This is my last one. I dont even know if its possible to put the output of a dom xpath into an array. I was hoping a veteran php-er would see what im trying to do and explain how to fix it if at all possible.
  5. The output is a table with 6 rows. I am trying to assign each row to a variable.
  6. I am trying to assign the output getElementsBtTagName to an array. I am new to arrays and so far i have this: foreach ($rows as $row) { /*** get each column by tag name ***/ $cols = $row->getElementsByTagName('td'); //Declare array $address = array(); if($row->childNodes->length) { foreach($row->childNodes as $ii) { $address[$ii->nodeName] = $ii ->nodeValue; } } $adresses[] = $address; /*** echo the values ***/ echo $cols->item(0)->nodeValue.'<br />'; echo '<hr />'; echo $address; ;
  7. I would like to place the output of these node values into an array: foreach ($rows as $row) { /*** get each column by tag name ***/ $cols = $row->getElementsByTagName('td'); /*** echo the values ***/ echo $cols->item(0)->nodeValue.'<br />'; echo $cols->item(1)->nodeValue.'<br />'; echo '<hr />'; } If the echo $cols->item(0)->nodeValue.'<br />'; always returns 6 values how can I call the values of each node later?
  8. I want it do escape the loop if it is not found like below: However this is not working. If ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i); $url = $href->getAttribute('href'); $purl = substr($url, 30,300); echo '<p>Found:<br />' . $purl. '<br />Retrieving Additional Information... '; } else { echo '<p>No Match Found For:<br />'.$row['name'].'<br />'; } It never gets to the else statement even if no link is found.
  9. I am running a search for a specific link on my site in order to make a big change but some of my entries are a little malformed. How do I make this script go to the next record if no match is found. Here are the two pieces of code: $result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_assoc($result)){ echo $row['name']; echo "<br />"; //After the page is loaded search for specified links for ($i = 0; $i < $hrefs->length; $i++) { $href = $hrefs->item($i); $url = $href->getAttribute('href'); $purl = substr($url, 30,300); //Here I would like to continue the while loop //Maybe if i could find the value "No entities were found" it would escape it just as well? At the end of the code I would like to continue the while loop if i could find the value "No entities were found" on the page that is missing the link I need. Thanks for the help.
  10. I am having trouble obtaining the second table in this HTML code: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head><html> <head> <meta http-equiv="Pragma" content="no-cache"> <title>Entity Information</title> <link rel="stylesheet" href="documents/CORP/default.css" media="screen" type="text/css"> <link rel="stylesheet" href="documents/CORP/infotable.css" media="screen" type="text/css"> </head> <body> <div class="headings"> <h1 class="dos_heading1">Company Information </h1> <BR> <h2 class="dos_heading2"> </h2> <h3 class="page_heading">Company Information</h3> <p class="DtMsg">The information contained in this database is current through September 10, 2010.</p> </div> <hr noshade width="100%"> <center> <div class="highlight">Selected Company Name: 1 PARK ROW, LLC</div> <table summary="This table contains status information for the selected entity."> <caption> Selected Company Status Information </caption> <tr> <th>Current Company Name:</th> <td>1 PARK ROW, LLC</td> </tr> <tr> <th>Initial Filing Date:</th> <td>JANUARY 22, 1997</td> </tr> <tr> <th>County:</th> <td>NASSAU</td> </tr> <tr> <th>Jurisdiction:</th> <td>NEW JERSEY </td> </tr> <tr> <th>Entity Type:</th> <td>DOMESTIC LIMITED LIABILITY COMPANY</td> </tr> <tr> <th>Current Company Status:</th> <td>ACTIVE </td> </tr> </table> <BR> <table id="tblAddr" summary="This table contains address information for the selected entity."> <caption>Selected Entity Address Information</caption> <tr> <th scope="col" id="c1" class="leftalign"><span class="rmvbold">Address</span></th> </tr> <tr> <td headers="c1"> C/O ELECTRONICS INC.<br> 2355 PARK ROW<br> NEW BRUNSWICK, NEW YORK, 15538 </td> </tr> <tr> <th scope="col" id="c4" class="leftalign">Registered Agent</th> </tr> <tr> <td headers="c1"> NONE </td> </tr> </table> <br> <p style="width:50%"> </p> <div id="divStockContainer"> <h4 id="capStock">*Stock Information</h4> <div id="divStock"> <table id="tblStock" cellpadding="0" cellspacing="6"> <tr> <th># of Shares</th> <th>Type of Stock</th> <th>$ Value per Share</th> </tr> <tr> <td> </td> <td>No Information Available</td> <td> </td> </tr> </table> </div> <p id="pStockBlurb">*Stock information is applicable to domestic business corporations.</p> </div> <div id="divHistNmContainer"> <h4 id="capNmHist">Name History</h4> <div id="divNmHist"> <table id="tblNameHist" cellpadding="0" cellspacing="6"> <tr> <th class="FileDt">Filing Date</th> <th class="NameType">Name Type</th> <th class="CorpName">Company Name</th> </tr> <tr> <td class="FileDt">JAN 22, 1997</td> <td class="NameType">Actual</td> <td class="CorpName">1 PARK ROW, LLC</td> </tr> </table> </div> <p id="pFictName"> </p> </div> </center> </body> </html> <script language='javascript' src='https://a12.alphagodaddy.com/hosting_ads/gd01.js'></script></script> I can get the top part with this: /*** a new dom object ***/ $dom = new domDocument; /*** load the html into the object ***/ $dom->loadHTML($html2); /*** 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 ***/ echo $cols->item(0)->nodeValue.'<br />'; echo $cols->item(1)->nodeValue.'<br />'; echo $cols->item(2)->nodeValue; echo '<hr />'; } } Any help would be appreciated I dont even know where to start to echo the 2nd table in the html. Thanks.
  11. I think you can use xpath with domdocument or get_file_contents
  12. That would be awesome. I just want to set the table values into variables (maybe an array?) so that as i go through the company pages I can enter these values into my mySQL table. Current Company Name: $CCN Initial Filing Date: $Date County: $County Jurisdiction: $JUR Entity Type: $ET Current Company Status: $CCS Address: $addr
  13. Ill Pay $20 via paypal if someone can break those tables down into variables ready to be placed in a mysql database.
  14. Can I use Preg-Match in a DOMDocument?
×
×
  • 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.