رفتن به مطلب

تبدیل دیتابیس به اکسل


پست های پیشنهاد شده

سلام

من یه فایل php دارم که مقادیر یک جدول دیتابیس رو رو به اکسل تبدیل میکنه

از شما خواهش میکنم اگه کسی بلد هست کد های مربوط به اتصال به دیتابیس رو تغییر بده که با وردپرس به دیتابیس وصل بشه و عملیات تبدیل رو انجام بده:

<?php
//--------------------------------------------------------------------------
// This is where you specify your Database connection stuff
//
// mysql_connect -- Open a connection to a MySQL Server / die -- Alias of exit()
//
//--------------------------------------------------------------------------
$db_name = "wordpress"; //This is your database Name
$link = mysql_connect("localhost", "root", "") or die("Could not connect to server!");
//This is your table name. This is a one table config to do more table you will need to rework the code.
$table_name = 'thems';
$select_db = mysql_select_db($db_name, $link); // mysql_select_db -- Select a MySQL database
mysql_query("SET NAMES 'utf8'");
$query = "SELECT * FROM " . $table_name;
$result = mysql_query($query, $link) or die("Could not complete database query"); //mysql_query -- Send a MySQL query
$num = mysql_num_rows($result); //mysql_num_rows -- Get number of rows in result
$num2=mysql_num_fields($result);
$query="SHOW COLUMNS FROM ".$table_name;
$result1=mysql_query($query);
//$fields=mysql_fetch_array($result1);
$header="";
for ($i = 0; $i < $num2; $i++) {
$header .= mysql_field_name($result, $i) . "\t";
}
if ($num != 0) {
//--------------------------------------------------------------------------
// XML Header Tag Goes Here
//--------------------------------------------------------------------------
$_xml ="<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\r\n";
$_xml.="<dataroot xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\r\n";
//--------------------------------------------------------------------------
// This while loop loops throught the data found from the above query and
// generates the XML Doc.
//--------------------------------------------------------------------------
while ($row = mysql_fetch_array($result)) { //mysql_fetch_array -- Fetch a result row as an associative array, a numeric array, or both.
while ($row=mysql_fetch_array($result)){
$_xml .="\t<Table1>\r\n";
mysql_data_seek($result1,0);
$i=0;
while($f=mysql_fetch_array($result1)){
if($row[$i]<>'') $_xml.="\t\t<".$f[0].">".$row[$i]."</".$f[0].">\r\n";
$i++;
}
$_xml.="\t</Table1>\r";
}
}
$_xml.="</dataroot>";
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment; filename=filename.xls");
header("Pragma: no-cache");
header("Expires: 0");
header("Lacation: excel.htm?id=yes");
print "$_xml";
} else {
echo "No Records found";
}
?>

ویرایش شده توسط mohamadali1374
لینک به ارسال

سلام ممنون از جوابتون

من خودم با دیتابیس در وردپرس کار کردم ولی این کدی که در بالا قرار دادم یکم گیجم کرده خواهش میکنم لااقل در مورد 6 تا خط اول که مربوط به اتصال به دیتابیس هستند یه توضیحی بدبید که ازز کدوم تابع ورد پرسی استفاده کنم.

خواهش میکنم کمک کنید

لینک به ارسال

دیتابیستو از رو وردپرس و هرجایی که هست دانلود کن و با نرم افزار زیر به هر دیتابیسی میخوای تبدیل کن

http://p30download.com/fa/entry/37073/

لینک به ارسال

مشکل از دیتابیس نیست ؛ مشکل ار اتصال به دیتابیس با وردپرس (wpdb$)هست

کدی که در بالا قرار دادم با استفاده از دستورات mysql که در php استفاده میشن به دیتابیس متصل میشه ولی من میخوام یکم کمکم کنید تا این دستورات رو به دستوراتی که برای اتصال به دیتابیس در وردپرس بکار میره تبدیل کنم.

لطفا کمک کنید

لینک به ارسال

خب نکته اول اینه که شما کانکشن دیگه نیاز نداری و دستورت mysql_connect باید حذف بشه.

برای اجرای کوئری select هم مثال داخل لینکی که دادم زیاده:


global $wpdb;
$results = $wpdb->get_results( 'SELECT * FROM wp_options WHERE option_id = 1', OBJECT );

لینک به ارسال

کد رو به این شکل تغییر دادم ولی از کل صفحه خروجی اکسل میگیره

لطفا شما یه نگاه کنید و مشکلاتش رو به هم بگید.

global $wpdb;
//$link = mysql_connect("localhost", "root", "") or die("Could not connect to server!");
//This is your table name. This is a one table config to do more table you will need to rework the code.
$table_name = 'them';
//$select_db = mysql_select_db($db_name, $link); // mysql_select_db -- Select a MySQL database
//mysql_query("SET NAMES 'utf8'");
echo $query = "SELECT * FROM " . $table_name;
//$d=$wpdb->prepare($query);
$result=$wpdb -> get_results($query); //mysql_query -- Send a MySQL query

echo $num= $wpdb->get_var("SELECT COUNT(*) FROM them");
//mysql_num_rows -- Get number of rows in result
//$num2="4";
//$query="SHOW COLUMNS FROM ".$table_name;
//$result1=array('id','tt','aa','kk');

$num2=4;
$query="SELECT id FROM".$table_name;
$result1=$wpdb->get_col($query);
//$fields=mysql_fetch_array($result1);
$header="id Emails Name MOF";
if ($num != 0) {
//--------------------------------------------------------------------------
// XML Header Tag Goes Here
//--------------------------------------------------------------------------
$_xml ="<?xml version='1.0' encoding='UTF-8' standalone='yes'?>\r\n";
$_xml.="<dataroot xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>\r\n";
//--------------------------------------------------------------------------
// This while loop loops throught the data found from the above query and
// generates the XML Doc.
//--------------------------------------------------------------------------
foreach ( $result as $row) { //mysql_fetch_array -- Fetch a result row as an associative array, a numeric array, or both.
foreach ( $result as $row){
$_xml .="\t<Table1>\r\n";
//mysql_data_seek($result1,0);
$i=0;
foreach($result1 as $f5){
if($row[$i]<>'') $_xml.="\t\t<".$f5($i).">".$row[$i]."</".$f5($i).">\r\n";
$i++;
}
$_xml.="\t</Table1>\r";
}
}
$_xml.="</dataroot>";
header("Content-Type: application/vnd.ms-excel; charset=utf-8");
header("Content-Disposition: attachment; filename=filename.xls");
header("Pragma: no-cache");
header("Expires: 0");
header("Lacation: excel.htm?id=yes");
print "$_xml";
} else {
echo "No Records found";
}

لینک به ارسال

به گفتگو بپیوندید

هم اکنون می توانید مطلب خود را ارسال نمایید و بعداً ثبت نام کنید. اگر حساب کاربری دارید، برای ارسال با حساب کاربری خود اکنون وارد شوید .

مهمان
ارسال پاسخ به این موضوع ...

×   شما در حال چسباندن محتوایی با قالب بندی هستید.   حذف قالب بندی

  تنها استفاده از 75 اموجی مجاز می باشد.

×   لینک شما به صورت اتوماتیک جای گذاری شد.   نمایش به صورت لینک

×   محتوای قبلی شما بازگردانی شد.   پاک کردن محتوای ویرایشگر

×   شما مستقیما نمی توانید تصویر خود را قرار دهید. یا آن را اینجا بارگذاری کنید یا از یک URL قرار دهید.

×
×
  • اضافه کردن...