-1

私の仕事は、フォルダーの名前とサーバー上の場所から始まるデータ(製品の詳細)を一覧表示することです。MySQLは使用されておらず、残念ながら手に負えないため、ページ付けの問題が発生しています...どんな助けでも大歓迎です。

これが私のコードです...これは醜いですが、完璧に機能します...すべての結果がそのまま表示されるだけです!

<div style="width:750px;">
<?php

$ALL_PARTS = array();

// LOOP THROUGH MEMBERS RESOURCES ROOT FOLDER TO FIND ALL MEMBER RESOURCES FOLDERS

foreach (glob("root_folder/sub_folder/*",GLOB_ONLYDIR) as $ROOT_FOLDERS_PATH) {

// WE CAN NOW FIND ALL RELEVANT FOLDERS CONTAINING THE DATA NEEDED

       foreach (glob("$ROOT_FOLDERS_PATH/offers/*",GLOB_ONLYDIR) as $RESOURCE_FOLDERS_PATH) {

           $FIXED_PRODUCT_CODE = file_get_contents("$RESOURCE_FOLDERS_PATH/fixed-product-code.txt", true);
           $PRODUCT_TITLE = file_get_contents("$RESOURCE_FOLDERS_PATH/product-title.txt", true);
           $PRODUCT_DESCRIPTION = file_get_contents("$RESOURCE_FOLDERS_PATH/product-description.txt", true);

// WE NOW NEED TO RETURN THE PRODUCT IMAGE NAME WHICH IS IN ANOTHER LOCATION
// FIRST CREATE ARRAY OF ITEMS TO FILTER OUT IN RESULT

$ignore = Array(".", "..", "$RESOURCE_FOLDERS_PATH/assets/product_img/index.php", "$RESOURCE_FOLDERS_PATH/assets/product_img/.htaccess");

// GO GET THE IMAGE NAME AND PATH

foreach (glob("$RESOURCE_FOLDERS_PATH/assets/product_img/*") as $GET_IMAGE_NAME) {

// IF WE HAVE AN IMAGE AND PRODUCT CODE, DEFINE OPENING WRAPPER DIV AND THE IMAGE
// THEN DEFINE THE URL TO THE PRODUCT AND CLOSE THE WRAPPER DIV

     if((!in_array($GET_IMAGE_NAME, $ignore)) && (!empty($GET_IMAGE_NAME)) && (!empty($FIXED_PRODUCT_CODE)) ){

         $PART_1 = "<div style='width:355px; margin:0 0 20px 0; padding:10px; float:left; height:130px;'>";
         $PART_2 = "<div style='float:left; height:150px; padding-right:10px;'><img src='" . $GET_IMAGE_NAME . "' width='100' alt='' /></div>";
         $PART_3 = "<div><a href='subscriber_offers.php?product=" . md5($FIXED_PRODUCT_CODE) ."'>" . $PRODUCT_TITLE ."</a><p>" . $PRODUCT_DESCRIPTION  . "</p></div>";
         $PART_4 = "</div>";

     }
}

// PUT DEFINED PARTS TOGETHER 

$ALL_PARTS[$PRODUCT_TITLE] = $PART_1 . $PART_2 . $PART_3 . $PART_4;

    }
}

ksort($ALL_PARTS);

foreach($ALL_PARTS as $PRODUCT){
echo $PRODUCT;
}
?>
</div>

これにより、製品リストがアルファベット順に表示されます。

    ksort($ALL_PARTS);

    foreach($ALL_PARTS as $PRODUCT){
    echo $PRODUCT;
}

しかし、ページネーションスクリプトでアクセスできるように、$arrに$ALL_PARTS配列のすべてのデータを含めるにはどうすればよいですか?

以下は、関連するループの最後の反復を私に与えるだけです...(明らかに)

$arr = array($PRODUCT);
4

1 に答える 1

1

最初に並べ替え可能なデータ配列を作成し、次に配列を使用してhtmlを生成するサンプルコード:

<?

// LOOP THROUGH MEMBERS RESOURCES ROOT FOLDER TO FIND ALL MEMBER RESOURCES FOLDERS


$data=array();

foreach (glob("root_folder/sub_folder/*",GLOB_ONLYDIR) as $ROOT_FOLDERS_PATH) {

// WE CAN NOW FIND ALL RELEVANT FOLDERS CONTAINING THE DATA NEEDED

    foreach (glob("$ROOT_FOLDERS_PATH/offers/*",GLOB_ONLYDIR) as $RESOURCE_FOLDERS_PATH) {

        $FIXED_PRODUCT_CODE = file_get_contents("$RESOURCE_FOLDERS_PATH/fixed-product-code.txt", true);
        $PRODUCT_TITLE = file_get_contents("$RESOURCE_FOLDERS_PATH/product-title.txt", true);
        $PRODUCT_DESCRIPTION = file_get_contents("$RESOURCE_FOLDERS_PATH/product-description.txt", true);

        // WE NOW NEED TO RETURN THE PRODUCT IMAGE NAME WHICH IS IN ANOTHER LOCATION
        // FIRST CREATE ARRAY OF ITEMS TO FILTER OUT IN RESULT

        $ignore = Array(".", "..", "$RESOURCE_FOLDERS_PATH/assets/product_img/index.php", "$RESOURCE_FOLDERS_PATH/assets/product_img/.htaccess");

        // GO GET THE IMAGE NAME AND PATH

        foreach (glob("$RESOURCE_FOLDERS_PATH/assets/product_img/*") as $GET_IMAGE_NAME) {

        // IF WE HAVE AN IMAGE AND PRODUCT CODE, DEFINE OPENING WRAPPER DIV AND THE IMAGE
        // THEN DEFINE THE URL TO THE PRODUCT AND CLOSE THE WRAPPER DIV

            if((!in_array($GET_IMAGE_NAME, $ignore)) && (!empty($GET_IMAGE_NAME)) && (!empty($FIXED_PRODUCT_CODE)) ){
                       /* push data to array*/
               $data[]=array( 'title'=> $PRODUCT_TITLE, 'descr'=> $PRODUCT_DESCRIPTION , 'img'=>$GET_IMAGE_NAME, 'code'=>md5($FIXED_PRODUCT_CODE));

            }
        }
    }
}

/* now sort array arbitrarily using "asort()"*/
asort( $data);

/* now create html */
$ALL_PARTS='';
foreach( $data as $row){

    $ALL_PARTS. = "<div style='width:355px; margin:0 0 20px 0; padding:10px; float:left; height:130px;'>";
    $ALL_PARTS. = "<div style='float:left; height:150px; padding-right:10px;'><img src='" . $row['img'] . "' width='100' alt='' /></div>";
    $ALL_PARTS. = "<div><a href='subscriber_offers.php?product=" . $row['code'] ."'>" . $row['title'] ."</a><p>" . $row['descr']  . "</p></div>";
    $ALL_PARTS. = "</div>";

}
echo $ALL_PARTS;


?>
于 2013-01-13T21:09:03.227 に答える