如何设置没有MySQL数据的分页

时间:2013-01-13 20:15:00

标签: php pagination

我的任务是列出从文件夹名称开始的数据(产品详细信息)及其在服务器上的位置。 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);

1 个答案:

答案 0 :(得分: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;


?>