PDA

View Full Version : [PHP] Anyone got an idea



yarassa
February 8th, 2003, 16:11
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???

CareBear
February 8th, 2003, 16:30
which scripting language?

yarassa
March 17th, 2003, 13:48
php!!!

hohoho
March 17th, 2003, 15:56
<?
$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 "&#xAB; <b>1</b> &#xBB;";
if (!$page || $page < 1) {
$page = 1;
}
$pages = ceil($input / $perpage);
$html = "";
if ($page > 1) {
$html .= "<a href=\"".$_SERVER["PHP_SELF"]."?page=".($page-1)."\">&#xAB;</a>&#xA0;";
} else {
$html .= "&#xAB;&#xA0;";
}
for($i = 1; $i <= $pages; $i++) {
if ($i == $page) {
$html .= "<b>".$i."</b>&#xA0;";
} else {
$html .= "<a href=\"".$_SERVER["PHP_SELF"]."?page=".$i."\">".$i."</a>&#xA0;";
}
}
if ($page <= $pages-1) {
$html .= "<a href=\"".$_SERVER["PHP_SELF"]."?page=".($page+1).">&#xBB;</a>&#xA0;";
} else {
$html .= "&#xBB;&#xA0;";
}
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

yarassa
March 18th, 2003, 13:10
thank you...

hohoho
March 18th, 2003, 13:26
i'll post a better version tomorrow :D

hohoho
March 19th, 2003, 01:50
<?
$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 "&#xAB; <b>1</b> &#xBB;";
if (!$page || $page < 1) {
$page = 1;
}
$pages = ceil($input / $perpage);
$html = "";
if ($page > 1) {
$html .= "<a href=\"".$_SERVER["PHP_SELF"]."?page=".($page-1)."\">&#xAB;</a>&#xA0;";
} else {
$html .= "&#xAB;&#xA0;";
}
for($i = 1; $i <= $pages; $i++) {
if ($i == $page) {
$html .= "<b>".$i."</b>&#xA0;";
} else {
$html .= "<a href=\"".$_SERVER["PHP_SELF"]."?page=".$i."\">".$i."</a>&#xA0;";
}
}
if ($page <= $pages-1) {
$html .= "<a href=\"".$_SERVER["PHP_SELF"]."?page=".($page+1).">&#xBB;</a>&#xA0;";
} else {
$html .= "&#xBB;&#xA0;";
}
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 :)