TIME NOW
World current time now,
CALENDAR
Calendar monthly, yearly
login GOLD PRICE, RATE
login HOROSCOPE
login DICTIONARIES, LISTS
login SCIENCE EDUCATION RELIGION
login FINANCE, BUSINESS
login WORLD COUNTRIES, WIKI

PHP scripts, code, examples, tutorial

Previous articlePage bottomNext article  ALL TOPICS

PHP. MYSQL. Insert into table from text file

 Insertion part: <?php

$link        = mysql_connect( 'localhost', 'user', 'pass' );
$db_selected = mysql_select_db( 'db', $link );
mysql_query( 'SET NAMES utf8' );
mysql_query( 'SET CHARACTER SET urf8' );

$mon = 1;

for ( $mon = 1; $mon <= 12; $mon++ ) {

    $names = file( "$mon.inc" );
    
    
    
    foreach ( $names as $k => $v ) {

        if ( !trim( $v ) )
            continue;
        $arr  = explode( ":", $v );
        $arr1 = explode( ",", $arr[ 1 ] );
        
        $day = trim( $arr[ 0 ] );
        foreach ( $arr1 as $vv ) {
            $name = trim( $vv );
            
            
            
            $q = "insert into t_names set lang = 'ru-RU' , name= '$name', `data2` = '$mon' , `data3` = '$day' , data1 = '" . str_pad( $mon, 2, "0", STR_PAD_LEFT ) . "." . str_pad( $day, 2, "0", STR_PAD_LEFT ) . "'";
            echo "$q<BR>";
            mysql_query( $q ) or die( mysql_error() );
            
        } //$arr1 as $vv
        
    } //$names as $k => $v

} //$mon = 1; $mon <= 12; $mon++

?>
 
Previous articlePage topNext article  ALL TOPICS



 Use username: Guest, Anonymous, Programmer






QUOTES:
Sex alleviates tension. Love causes it.
Woody Allen
Don't trust the person who has broken faith once.
William Shakespeare
Any philosophy that can be put in a nutshell belongs there.
Sydney Harris