2012-03-23 36 views
3

你能幫我解決嗎? 我需要在php中顯示.dbf表的註冊表,並具有以下代碼。如何使用php查看foxpro註冊表

<html> 
    <form method="get"> 
     <input type="text" name="nrdoc"></input> 
     <input type="submit"></input> 
    </form> 

<?php 
if(isset ($_GET['nrdoc'])){ 
$thefile = "winges/vcabdoc.DBF"; 
if($thefile){ 
include('./dbf_class.php'); 
$dbf = new dbf_class($thefile); 
$num_rec=$dbf->dbf_num_rec; 
$field_num=$dbf->dbf_num_field; 
$endexct = $timer->end(); 

    echo("<blockquote>File Name : $thefile<br>Number of Records : $num_rec<br>Number of Fields : $field_num</blockquote>"); 
    echo('<table border=1 cellspacing=0>'); 
    echo('<tr>'); 
    echo('<td>No.&nbsp;</td>'); 

    for($j=0; $j<$field_num; $j++){ 
     echo '<td>&nbsp;'.$dbf->dbf_names[$j]['name']; 
      if ($dbf->dbf_names[$j]['type']!='M') { 
       echo '<br>Length='.$dbf->dbf_names[$j]['len']; 
      } 
     echo '<br>Type='.$dbf->dbf_names[$j]['type'].'</td>'; 
    } 
    echo '</tr>'; 


    $i=$_GET['nrdoc']; 
     if ($row === $dbf->getRow("SELECT *, FROM winges/vcabdoc.dbf WHERE 'VCANUM' == $i")) { 
      echo('<tr>'); 
      echo('<td align="right">'.str_pad($i+1, 3, "0", STR_PAD_LEFT).'</td>'); 
       for($j=0; $j<$field_num; $j++){ 
        if ($dbf->dbf_names[$j]['type']=='N') { 
         echo '<td align="right">'; 
        } 
        else { 
         echo '<td align="left">'; 
        } 
      echo htmlentities($row[$j]).'&nbsp;</td>'; 
      } 
      echo '<tr>'; 
     } 
} 
    echo('</table>'); 
} 
?> 
</html> 

的dbf_class.php是http://www.phpclasses.org

而且它總是返回數據庫中的第一數據線,請幫助我。

在此先感謝。

若昂

+0

如果定時器類有無關的問題,然後將其刪除,並給它的引用,使代碼更小。並且稍微清理一下代碼......這相當難看。 – Flukey 2012-03-23 14:35:34

+0

看看現在好不好。 – 2012-03-23 14:42:55

+0

您正在加入'dbf_class.php' - 對操作非常重要。那從哪裏來的? [phpclasses.org](http://www.phpclasses.org/package/1302-PHP-Extract-information-from-a-DBF-database-file.html)? – Orbling 2012-03-23 14:49:31

回答

1

我發現了一個簡單的方法來從.DBF使用Perl庫XBASE 使用這個庫我寫了讀取指定的文件和輸出JSON字符串小腳本提取數據。

# foxpro2json.pl 
use File::Basename; 
use XBase; 
$filename=$ARGV[0]; 

my $table = new XBase $filename or die XBase->errstr; 
my @fields = $table->field_names; 
my $cursor = $table->prepare_select(); 
my $return = ''; 
my $i = 0; 

while (my @row = $cursor->fetch) { 
    $json = '{'; 
    $i = 0; 
    foreach $val (@row) { 
    $val =~ s/(['"\/\\])/\\$1/g; 
    $json .= '"'.$fields[$i].'":"'.$val.'",'; 
    $i++; 
    } 
    $json = substr($json, 0, -1); 
    $json .= '},'; 
    $return .= $json; 
} 
$return = substr($return, 0, -1); 
print '['.$return.']'; 

這是我如何把這個文件我的PHP代碼中:

exec('/usr/bin/perl /var/www/foxpro2json.pl /var/www/myfilename.dbf', $json); 
$array = json_decode($json[0], true); 
+0

謝謝你們,它已經解決了。 (: – 2012-03-30 10:20:16