Thứ Sáu, 5 tháng 10, 2012

IMPORT DỮ LIỆU QUÁ LỚN TRÊN MYSQL -WAMPSERVER

Có rất nhiều công cụ để hỗ trợ việc backup và restore một cách nhanh chóng. tuy vậy cũng không cần đến phần mềm ta có thể backup và restore ngay trong wamp server  bằng tập lệnh trong dos.
mở mysql console ở  góc của wamp


1. Backup database 
để sử dụng mysqldump trong cửa sổ  cmd ta trỏ đường dẫn lại như sau :
cd C:\wamp\bin\mysql\mysql5.5.8\bin
 rồi gõ
mysqldump -u [tên user] -p [tên database] > [tên file db.sql]
vd với user có tên root mặc định,database là home thì lệnh sẽ là :
mysqldump -u root -p home > homedb.sql
khi chạy lệnh này nó sẽ bắt mình gõ password của user vào. 
  http://lh5.ggpht.com/_03L_Y5U99Eg/TT5xJ51HZPI/AAAAAAAAALo/Q7jzh5UkosM/s640/backup.PNG

b. Backup 1 table  trong database
 Trong database home  có table có tên là posts. Và Mình chỉ muốn backup table posts ra file test.sql thì làm cách này:
Trong cửa sổ Command Prompt chạy lệnh 


cú pháp
 mysqldump --add-drop-table -u [user name] -p [database] [table name1] [table name 2]... > [file name.sql]

2. Restore Database

Việc restore database khá đơn giản. vào mysql console
B0-cd C:\wamp\bin\mysql\mysql5.5.8\bin 
1-Mở cmd đánh lệnh mysql -u [tên user root] -p. Tiếp đến nhập password user root .
2-Trong sell mysql command line, đánh lệnh use [tên database] để chọn database cần restore.
3-Cuối cùng đánh lệnh source tên đường dẫn tới file database cần restore] và enter là xong

Thứ Năm, 4 tháng 10, 2012

[DRUPAL 6 - VIEW] Ẩn tiêu đề và nội dung của field khi không có nội dung

Nice work, here's a slightly modified (cleaner loops?) version, with php short tags replaced by long tags.
<?php/**
* Product Table View customized so that any columns with no data are omitted from display.
*/
foreach ($rows as $count => $row):
    foreach (
$row as $field => $content):
      if (
$content) $column_has_content[ $field ] = true;
    endforeach;
endforeach;
?>



<table class="<?php print $class; ?>">
  <?php if (!empty($title)) : ?>
    <caption><?php print $title; ?></caption>
  <?php endif; ?>
  <thead>
    <tr>    
      <?php foreach ( $header as $field => $label ): ?>
        <?php if ( $column_has_content[ $field ] ): ?>
          <th class="views-field views-field-<?php print $fields[$field]; ?>">
            <?php print $label; ?>
          </th>
        <?php endif;?>
      <?php endforeach; ?>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($rows as $count => $row): ?>
      <tr class="<?php print implode(' ', $row_classes[$count]); ?>">
        <?php foreach ($row as $field => $content): ?>
          <?php if ( $column_has_content[ $field ] ): ?>
            <td class="views-field views-field-<?php print $fields[$field]; ?>">
              <?php print $content; ?>
            </td>
          <?php endif; ?>
        <?php endforeach; ?>
      </tr>
    <?php endforeach; ?>
  </tbody>
</table>

Use preprocessing function

Thank you all for examples. I modified them so column checking code is in preprocessing function.
Put following in template.php
<?php/**
* Removes column headers for columns that do not have content.
*/
function THEME-NAME_preprocess_views_view_table__VIEW-NAME(&$vars) {
 
$rows = $vars['rows'];
 
$column_has_content = array();
  foreach (
$rows as $count => $row) {
    foreach (
$row as $field => $content) {
      if (!empty(
$content)) {
       
$column_has_content[$field] = TRUE;
      }
    }
  }
 
$vars['column_has_content'] = $column_has_content;
}
?>
You can now use $column_has_content variable in views-view-table--VIEW-NAME.tpl.php
<table class="<?php print $class; ?>">
  <?php if (!empty($title)) : ?>
    <caption><?php print $title; ?></caption>
  <?php endif; ?>
  <thead>
    <tr>
      <?php foreach ($header as $field => $label): ?>
      <?php if (  $column_has_content[$field]  ):  ?>
        <th class="views-field views-field-<?php print $fields[$field]; ?>">
          <?php print $label; ?>
        </th>
      <?php endif; ?>
      <?php endforeach; ?>
    </tr>
  </thead>
  <tbody>
    <?php foreach ($rows as $count => $row): ?>
      <tr class="<?php print implode(' ', $row_classes[$count]); ?>">
        <?php foreach ($row as $field => $content): ?>
        <?php if (  $column_has_content[$field]  ):  ?>
          <td class="views-field views-field-<?php print $fields[$field]; ?>">
            <?php print $content; ?>
          </td>
        <?php endif; ?>
        <?php endforeach; ?>
      </tr>
    <?php endforeach; ?>
  </tbody>
</table>
Don't forget to replace VIEW-NAME with name of your view and THEME-NAME with name of your theme.