Friday, April 13, 2012

To export you sql to excel file

" . mysql_error() . "
" . mysql_errno()); //select database $Db = @mysql_select_db($DB_DBName, $Connect) or die("Couldn't select database:
" . mysql_error(). "
" . mysql_errno()); //execute query $result = @mysql_query($sql,$Connect) or die("Couldn't execute query:
" . mysql_error(). "
" . mysql_errno()); while($row = mysql_fetch_assoc($result)) { //print_r($result); $data[]=array('ID'=>$row[ID],'First_name'=>$row[user_nicename],'Last_name'=>$row[display_name]); } //echo sizeof($data); $key=0; foreach($data as $id) { $sql1="SELECT * FROM wp_usermeta where user_id=".$id['ID']; //echo $sql1; $result1 = @mysql_query($sql1,$Connect); while($row1 = mysql_fetch_assoc($result1)) { $k=$row1[meta_key]; $v=$row1[meta_value]; $data[$key][$k]=$v; //$data[]=array('ID'=>$row1[ID]); } $key++; } /* echo"
";
    print_r($data);
    echo"
"; */ $field=array('League','First Name','Last Name','Gender','DOB','AHC No.','Address','Postal Code','Parent /Guardian One information Last Name','Parent /Guardian One information First Name','Parent /Guardian One Phone','Parent /Guardian One Email','Parent /Guardian Two information Last Name','Parent /Guardian Two Information First Name','Parent /Guardian Two Home','Parent /Guardian Two Email','Community ID','Medical Issues?','Post 1 Volunteer','Post 1 Name','Shirt Size','Post 2 Volunteer','Post 2 Name','Shirt Size','Who I'd like to Volunteer with First','Who I'd like to Volunteer with Last','How Registered'); if (isset($w) && ($w==1)) { $file_type = "msword"; $file_ending = "doc"; }else { $file_type = "vnd.ms-excel"; $file_ending = "xls"; } //header info for browser: determines file type ('.doc' or '.xls') header("Content-Type: application/$file_type"); header("Content-Disposition: attachment; filename=database_dump.$file_ending"); header("Pragma: no-cache"); header("Expires: 0"); if (isset($w) && ($w==1)) //check for $w again { $sep="\t"; $new="\n"; foreach($field as $attri) { echo $attri.$sep; } echo $new; $keys=0; foreach($data as $data_con){ /** 1.League***/ if($data_con['select7']) { echo $data_con['select7']; echo $sep; } else { echo $sep; } /** 2.First name***/ if($data_con['First_name']) { echo $data_con['First_name']; echo $sep; } else { echo $sep; } /** 3.Last name***/ if($data_con['Last_name']) { echo $data_con['Last_name']; echo $sep; } else { echo $sep; } /** 4.Gender***/ if($data_con['radiobutton_Gender']) { echo $data_con['radiobutton_Gender']; echo $sep; } else { echo $sep; } /** 5.DOB***/ if($data_con['dob3']) { echo $data_con['dob1'].'-'.$data_con['dob2'].'-'.$data_con['dob3']; echo $sep; } else { echo $sep; } /** 6.AHC No.***/ if($data_con['Community']) { echo $data_con['Community']; echo $sep; } else { echo $sep; } /** 7.Address ***/ if($data_con['uadd']) { echo $data_con['uadd']; echo $sep; } else { echo $sep; } /** 8.Postal Code ***/ if($data_con['pcode']) { echo $data_con['pcode']; echo $sep; } else { echo $sep; } /** 9.Parent /Guardian One information Last Name ***/ if($data_con['g1_lname']) { echo $data_con['g1_lname']; echo $sep; } else { echo $sep; } /** 10.Parent /Guardian One information First Name ***/ if($data_con['g1_fname']) { echo $data_con['g1_fname']; echo $sep; } else { echo $sep; } /** 11.Parent /Guardian One Phone ***/ if($data_con['g1_ph']) { echo $data_con['g1_ph']; echo $sep; } else { echo $sep; } /** 12.Parent /Guardian One Email ***/ if($data_con['g1_email']) { echo $data_con['g1_email']; echo $sep; } else { echo $sep; } /** 13.Parent /Guardian Two information Last Name ***/ if($data_con['g2_lname']) { echo $data_con['g2_lname']; echo $sep; } else { echo $sep; } /** 14.Parent /Guardian Two Information First Name ***/ if($data_con['g2_fname']) { echo $data_con['g2_fname']; echo $sep; } else { echo $sep; } /** 15.Parent /Guardian Two Phone ***/ if($data_con['g2_ph']) { echo $data_con['g2_ph']; echo $sep; } else { echo $sep; } /** 16.Parent /Guardian Two Email ***/ if($data_con['g2_email']) { echo $data_con['g2_email']; echo $sep; } else { echo $sep; } /** 17.Community ID ***/ if($data_con['Community']) { echo $data_con['Community']; echo $sep; } else { echo $sep; } /** 18.Medical Issues? ***/ if($data_con['HealthCare']) { echo $data_con['HealthCare']; echo $sep; } else { echo $sep; } /** 19.Post 1 Volunteer ***/ if($data_con['Volunteer_position1']) { echo $data_con['Volunteer_position1']; echo $sep; } else { echo $sep; } /** 20.Post 1 Name ***/ if($data_con['Volunteer_name1']) { echo $data_con['Volunteer_name1']; echo $sep; } else { echo $sep; } /** 21.Shirt Size ***/ if($data_con['Shirt_size1']) { echo $data_con['Shirt_size1']; echo $sep; } else { echo $sep; } /** 22.Post 2 Volunteer ***/ if($data_con['Volunteer_position2']) { echo $data_con['Volunteer_position2']; echo $sep; } else { echo $sep; } /** 23.Post 2 Name ***/ if($data_con['Volunteer_name2']) { echo $data_con['Volunteer_name2']; echo $sep; } else { echo $sep; } /** 24.Shirt Size ***/ if($data_con['Shirt_size2']) { echo $data_con['Shirt_size2']; echo $sep; } else { echo $sep; } /** 25.Who I'd like to Volunteer with First ***/ if($data_con['volunteerwithfname']) { echo $data_con['volunteerwithfname']; echo $sep; } else { echo $sep; } /** 26.Who I'd like to Volunteer with Last ***/ if($data_con['volunteerwithlname']) { echo $data_con['volunteerwithlname']; echo $sep; } else { echo $sep; } /** 27.How Registered ***/ if($data_con['Fees']) { echo $data_con['Fees']; echo $sep; } else { echo $sep; } echo $new; } }else{ $sep="\t"; $new="\n"; foreach($field as $attri) { echo $attri.$sep; } echo $new; $keys=0; foreach($data as $data_con){ /** 1.League***/ if($data_con['select7']) { echo $data_con['select7']; echo $sep; } else { echo $sep; } /** 2.First name***/ if($data_con['First_name']) { echo $data_con['First_name']; echo $sep; } else { echo $sep; } /** 3.Last name***/ if($data_con['Last_name']) { echo $data_con['Last_name']; echo $sep; } else { echo $sep; } /** 4.Gender***/ if($data_con['radiobutton_Gender']) { echo $data_con['radiobutton_Gender']; echo $sep; } else { echo $sep; } /** 5.DOB***/ if($data_con['dob3']) { echo $data_con['dob1'].'-'.$data_con['dob2'].'-'.$data_con['dob3']; echo $sep; } else { echo $sep; } /** 6.AHC No.***/ if($data_con['Community']) { echo $data_con['Community']; echo $sep; } else { echo $sep; } /** 7.Address ***/ if($data_con['uadd']) { echo $data_con['uadd']; echo $sep; } else { echo $sep; } /** 8.Postal Code ***/ if($data_con['pcode']) { echo $data_con['pcode']; echo $sep; } else { echo $sep; } /** 9.Parent /Guardian One information Last Name ***/ if($data_con['g1_lname']) { echo $data_con['g1_lname']; echo $sep; } else { echo $sep; } /** 10.Parent /Guardian One information First Name ***/ if($data_con['g1_fname']) { echo $data_con['g1_fname']; echo $sep; } else { echo $sep; } /** 11.Parent /Guardian One Phone ***/ if($data_con['g1_ph']) { echo $data_con['g1_ph']; echo $sep; } else { echo $sep; } /** 12.Parent /Guardian One Email ***/ if($data_con['g1_email']) { echo $data_con['g1_email']; echo $sep; } else { echo $sep; } /** 13.Parent /Guardian Two information Last Name ***/ if($data_con['g2_lname']) { echo $data_con['g2_lname']; echo $sep; } else { echo $sep; } /** 14.Parent /Guardian Two Information First Name ***/ if($data_con['g2_fname']) { echo $data_con['g2_fname']; echo $sep; } else { echo $sep; } /** 15.Parent /Guardian Two Phone ***/ if($data_con['g2_ph']) { echo $data_con['g2_ph']; echo $sep; } else { echo $sep; } /** 16.Parent /Guardian Two Email ***/ if($data_con['g2_email']) { echo $data_con['g2_email']; echo $sep; } else { echo $sep; } /** 17.Community ID ***/ if($data_con['Community']) { echo $data_con['Community']; echo $sep; } else { echo $sep; } /** 18.Medical Issues? ***/ if($data_con['HealthCare']) { echo $data_con['HealthCare']; echo $sep; } else { echo $sep; } /** 19.Post 1 Volunteer ***/ if($data_con['Volunteer_position1']) { echo $data_con['Volunteer_position1']; echo $sep; } else { echo $sep; } /** 20.Post 1 Name ***/ if($data_con['Volunteer_name1']) { echo $data_con['Volunteer_name1']; echo $sep; } else { echo $sep; } /** 21.Shirt Size ***/ if($data_con['Shirt_size1']) { echo $data_con['Shirt_size1']; echo $sep; } else { echo $sep; } /** 22.Post 2 Volunteer ***/ if($data_con['Volunteer_position2']) { echo $data_con['Volunteer_position2']; echo $sep; } else { echo $sep; } /** 23.Post 2 Name ***/ if($data_con['Volunteer_name2']) { echo $data_con['Volunteer_name2']; echo $sep; } else { echo $sep; } /** 24.Shirt Size ***/ if($data_con['Shirt_size2']) { echo $data_con['Shirt_size2']; echo $sep; } else { echo $sep; } /** 25.Who I'd like to Volunteer with First ***/ if($data_con['volunteerwithfname']) { echo $data_con['volunteerwithfname']; echo $sep; } else { echo $sep; } /** 26.Who I'd like to Volunteer with Last ***/ if($data_con['volunteerwithlname']) { echo $data_con['volunteerwithlname']; echo $sep; } else { echo $sep; } /** 27.How Registered ***/ if($data_con['Fees']) { echo $data_con['Fees']; echo $sep; } else { echo $sep; } echo $new; } } ?>

No comments:

Post a Comment