how to strore the php result in mysql database

Discussion in 'Google' started by Nagadurga, Jul 29, 2010.

  1. #1
    please anyone suggest

    i have use the following code to extract the data from the webpage. how to store it in database..? I tried to use mysql connectivity and insert query but it didn't work .
    please give a suggestion to me.

    
    <html>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <table>
    <tr>
    <td>
    <center><h3> Bar Name </h3></center>
    <?php
    $html = file_get_contents ('http://tel.local.ch/en/q/bar.html?typeref=res');
    $dom = new DomDocument();
    @$dom->loadHTML ($html);
    $xpath = new DOMXPath ($dom);
    $key1 = $xpath->query ('//*[@class="fn"]');
    
    foreach($key1 as $keys){
    echo $keys->nodeValue ,"<br/> \n";
    }
    
    ?>
    </td>
    <td>
    <center><h3> Address </h3></center>
    <?php
    $html = file_get_contents ('http://tel.local.ch/en/q/bar.html?typeref=res');
    $dom = new DomDocument();
    @$dom->loadHTML ($html);
    $xpath = new DOMXPath ($dom);
    $key2 = $xpath->query ('//*[@class="adr"]');
    foreach($key2 as $keys){
    echo $keys->nodeValue ,"<br/> \n";
    }
    
    ?>
    </td>
    <td>
    <center><h3> Conduct </h3></center>
    <?php
    $html = file_get_contents ('http://tel.local.ch/en/q/bar.html?typeref=res');
    $dom = new DomDocument();
    @$dom->loadHTML ($html);
    $xpath = new DOMXPath ($dom);
    $key3 = $xpath->query ('//*[@class="phonenr"]');
    foreach($key3 as $keys){
    echo $keys->nodeValue ,"<br/> \n";
    }
    
    ?>
    </td>
    </tr>
    </table>
    </html>
    
    
    PHP:
    And i got output as,

    Bar Name
    ADN Bar Café
    Bar Abdelmajid
    Bar Amalfi
    Bar Benjamin (-Gera)
    Bar Bistro Amigos
    Bar Chez Franki
    Bar Croce d'Oro
    Bar Daniela (-Gera)
    Bar Golf
    Bar Gufo

    Address
    rue de Lausanne 59, 1202 Genève
    Könizstrasse 3, 3008 Bern
    Turmstrasse 7, 8330 Pfäffikon ZH
    Im Allmendli 11, 8703 Erlenbach ZH
    Bahnhofstrasse 2, 3360 Herzogenbuchsee
    rue Victor-Tissot 4, 1630 Bulle
    via Motta 3, 6900 Lugano
    Im Allmendli 11, 8703 Erlenbach ZH
    via della Posta 2, 6900 Lugano
    via Girella, 6814 Lamone

    Conduct
    022 731 40 18
    031 381 42 60
    043 535 90 05
    076 232 23 21
    062 961 01 10
    076 332 10 34
    091 921 47 93
    079 780 65 54
    091 921 39 03
    091 967 17 36

    how can i save it in database. please anyone give suggestion.

    thanks in advance.
     
    Nagadurga, Jul 29, 2010 IP