• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

[PHP] Anyone got an idea

yarassa

New Member
Anyone got an idea

I have been thinking for a week but i cant find a way to do this:

I have a csv file like this

1521|125|http://anything.com|anyemail@antyemail.com
...
...

think that there is 158 lines like first line...

And i want to write in a page! But everypage has 25 result of course. Anyone got an idea for this???
 
PHP:
<?
$file = "cvs";
$perpage = 25;

function createPages($input = 0, $perpage = 25) {
    global $page, $_SERVER;
    if (empty($input))
        die("createPages(<b>\$input = $input</b>, \$perpage = $perpage");
    if ($input <= $perpage)
        return "« <b>1</b> »";
    if (!$page || $page < 1) {
        $page = 1;
    }
    $pages = ceil($input / $perpage);
    $html = "";
    if ($page > 1) {
        $html .= "<a href=\"".$_SERVER["PHP_SELF"]."?page=".($page-1)."\">«</a> ";
    } else {
        $html .= "« ";
    }
    for($i = 1; $i <= $pages; $i++) {
        if ($i == $page) {
            $html .= "<b>".$i."</b> ";
        } else {
            $html .= "<a href=\"".$_SERVER["PHP_SELF"]."?page=".$i."\">".$i."</a> ";
        }
    }
    if ($page <= $pages-1) {
        $html .= "<a href=\"".$_SERVER["PHP_SELF"]."?page=".($page+1).">»</a> ";
    } else {
        $html .= "» ";
    }
    return $html;
}

$fp = fopen($file,"r");
while(!feof($fp)) {
    $line[] = fgets($fp,4096);
}

$rows = count($line);
$links = createPages($rows,$perpage);
if(!$page) {
    $page = 1;
}

$start = $page*$perpage;
$end = $start+$perpage;

for($i=$start;$i<=$end;$i++) {
    list($1,$2,$3,$4) = explode($line[$i-1]);
    echo "$1 -- $2 -- $3 -- $4<br>";
}

echo $links;
?>
not tested yet, but should work
 
Last edited:
PHP:
<?
$file = "cvs";
$perpage = 25;

function createPages($input = 0, $perpage = 25) {
    global $page, $_SERVER;
    if (empty($input))
        die("createPages(<b>\$input = $input</b>, \$perpage = $perpage");
    if ($input <= $perpage)
        return "« <b>1</b> »";
    if (!$page || $page < 1) {
        $page = 1;
    }
    $pages = ceil($input / $perpage);
    $html = "";
    if ($page > 1) {
        $html .= "<a href=\"".$_SERVER["PHP_SELF"]."?page=".($page-1)."\">«</a> ";
    } else {
        $html .= "« ";
    }
    for($i = 1; $i <= $pages; $i++) {
        if ($i == $page) {
            $html .= "<b>".$i."</b> ";
        } else {
            $html .= "<a href=\"".$_SERVER["PHP_SELF"]."?page=".$i."\">".$i."</a> ";
        }
    }
    if ($page <= $pages-1) {
        $html .= "<a href=\"".$_SERVER["PHP_SELF"]."?page=".($page+1).">»</a> ";
    } else {
        $html .= "» ";
    }
    return $html;
}

if(!$page) {
    $page = 1;
}
$lines = 0:
$fp = fopen($file,"r");
for($i=$page*$perpage;$i<=$page*$perpage+$perpage;$i++) {
    fgets($fp);
    $lines++;
}

for($i=0;$i<=$perpage-1;$i++) {
    if(feof($file)) break;
    else {
        list($1,$2,$3,$4) = explode("|",fgets($fp,4096));
        echo "$1 -- $2 -- $3 -- $4<br>";  // prints the contents
        $lines++;
    }
}

while(!feof($file)) {
    fgets($fp);
    $lines++;
}
$links = createPages($lines,$perpage);

echo $links;
?>
this should print out the lines directly and not read them in an array :)
 
Back
Top