SobiPro出口 - 无限循环

时间:2014-03-26 01:52:16

标签: php mysql sobipro

下面的代码是一个导出工具,我基本上是查询SobiPro数据库,提取条目(公司)列表以及相关的自定义字段。

我在这里偶然发现了一个无限循环。有些部分仅用于注明ID,因此请忽略公司/电子邮件/电话/等部分。

以下信息将导出为CSV,因此将这些信息配对至关重要。

以下是我的代码。有什么想法吗?

$ideas = mysql_query("SELECT itemid FROM jos_sobi2_item") or die(mysql_error());

while ($row = mysql_fetch_array($ideas)) {
    $info[] = $row['itemid'];
}

foreach($info as $item) {
$entryID = $item['itemid'];
$queryfields = mysql_query("SELECT fieldid, data_txt, itemid FROM jos_sobi2_fields_data WHERE itemid = '". $entryID ."'");
//$queryfields = mysql_query("SELECT fieldid, data_txt, itemid FROM `jos_sobi2_fields_data` WHERE `itemid` = '$entryID'");

while ($rowqueryfields = mysql_fetch_array($queryfields)) {
    $rowfields[] = $rowqueryfields;
}
foreach($rowfields as $item) {  
    // Primarily what I need is name, company and contact info such as phone, email fax web!
    $contactPerson = '9'; // Name
    $city = '3'; // City
    $state = '5'; // State
    $phone = '10'; // Phone
    $email = '7'; // Email
    $fax = '11';
    $website = '8';     

    if($item['fieldid'] == 9) {
        echo '<strong>Name: </strong>' .$item['data_txt'] . '</br>';
    }
    if($item['fieldid'] == 3) {
        //echo '<strong>City: </strong>' .$item['data_txt'] . '</br>';
    }
    if($item['fieldid'] == 5) {
        //echo '<strong>State: </strong>' .$item['data_txt'] . '</br>';
    }
    if($item['fieldid'] == 10) {
        //echo '<strong>Phone: </strong>' .$item['data_txt'] . '</br>';
    }
    if($item['fieldid'] == 7) {
        //echo '<strong>Email: </strong>' .$item['data_txt'] . '</br>';
    }
    if($item['fieldid'] == 8) {
        //echo '<strong>Website: </strong>' .$item['data_txt'] . '</br>';
    }
}
}

2 个答案:

答案 0 :(得分:0)

尝试这样的事情:

$sql = "SELECT I.itemID, fieldid, data_txt FROM jos_sobi2_item I";
$sql .= " JOIN jos_sobi2_fields_data D on D.itemID = I.itemID";

if( $result = mysql_query( $sql ) ) {
   while( $row = mysql_fetch_array( $result ) ) {
      switch( $row['fieldid'] ) {
        case 9:
           echo '<strong>Name: </strong>' .$item['data_txt'] . '</br>';
           break;
        case 3:
           echo //whatever goes here
           break;
        // other cases
      }
   } else {
      // database error so echo or whatever

}

我没有尝试过,所以不要因为任何轻微的语法错误而责怪我;)

希望它有所帮助。玩得开心......

答案 1 :(得分:0)

为什么不简单地使用SobiPro ImEx App?