我用print_r()把数据以数组的形式读出来了,输出数据如下:
Array ( [[email protected]] => Array ( [email] => [email protected] [name] => cuiguangm [group] => ) [[email protected]] => Array ( [email] => [email protected] [name] => 悠悠 [group] => 常用联系人 ) [[email protected]] => Array ( [email] => [email protected] [name] => lesen [group] => ) [[email protected]] => Array ( [email] => [email protected] [name] => [email protected] [group] => ) ) 怎么把这些信息读到数据库中呢?只要email,name就可以。因为刚刚学,还不会,希望大家帮帮我。

解决方案 »

  1.   

    mysql_query("INSERT语句"),具体看PHP手册
      

  2.   

    不会写insert语句。因为上面输出的数组不是单独的变量,怎么用insert插入呢?请告诉指教
      

  3.   

    //大体这样
    mysql_connect('地址', '数据库用户名', '数据库用户密码') or die('数据库连接失败');
    //mysql_query('set names gbk');//设置数据库读取数据的编码
    $arr = array();//假如$arr是你的那个数字
    foreach($arr as $v){
    $sql = 'inesrt into table_name(email, name) values("'.$v['email'].'", "'.$v['name'].'")';
    //或者$sql = 'update table_name set email = "'.$v['email'].'" where xxx = xxx';
    mysql_query($sql);
    }
      

  4.   

    foreach($array as $v){
    根据键读取取$v['email'] 然后mysql_query()
    }