Reply
Pagination help?
Old 05-08-2008, 12:43 AM Pagination help?
Super Talker

Posts: 128
php code

PHP Code:
<?php
$sortby 
$_SERVER['QUERY_STRING'];

$set '';
if (
$sortby == '') {
    
$sortby 'field3';
    
$set 'y';
}
if (
$sortby == 'field3') {
    
$set 'y';
}
if (
$set == '') {
    echo 
'The variable at the end of the web address did not match one required by the code. Please check the web address for errors.';
    exit;
}
 
$number 0;
$fp fopen('data.txt','r');
if (!
$fp) {echo 'ERROR: Unable to open file.'; exit;}

while (!
feof($fp)) {
    
$line fgets($fp,1024); //use 2048 if very long lines
    
$row++;
 list (
$field1$field2$field3$field4) = split ('\|'$line);
    if (
$sortby == 'field3'$sortkey strtolower($field3);
    
$col[$row] = array($sortkey$field1$field2$field3$field4);
}

fclose($fp);

sort($col);
reset ($col);

$arrays count($col) - 1;

$loop = -1;
while (
$loop $arrays) {
    
$loop++;
       
$number++;
    echo 
'
<td class="td"><div align="center"><a href="'
.$col[$loop][1].'">'.$col[$loop][2].'<br><img src="pets/'.$col[$loop][4].'.png" width="110" class="'.$col[$loop][3].'"></a></div></td>
'
;
   if((
$number 4)==0)
   {
    echo 
"</tr>";
    echo 
"<tr>";
   }
}
?>
field 3 is a number from 1 - 7.

How do I get all the 1's to show up on one page and all the 2's to show up on another, etc.
simster is offline
Reply With Quote
View Public Profile
 
Sponsored Links (We share ad revenue):
 
Old 05-08-2008, 02:08 AM Re: Pagination help?
Junior Talker

Posts: 2
PHP Code:

<?php


function cmp($a$b)
{
    if (
$a[2] == $b[2]) {
        return 
0;
    }
    return (
$a[2] < $b[2]) ? -1;
}

$a[0] = array(32561);
$a[1] = array(35461);
$a[2] = array(31661);


usort($a"cmp");

foreach (
$a as $key => $value) {
    echo 
"\$key: $key\n";
    
var_dump($value)."\n";
}


?>
That sorts $a on the third element in the second dimension. I think that's what you need.

http://us.php.net/manual/en/function.usort.php

Last edited by LogicFlux : 05-08-2008 at 02:13 AM.
LogicFlux is offline
Reply With Quote
View Public Profile
 
Old 05-08-2008, 03:15 AM Re: Pagination help?
Super Talker

Posts: 128
done code

after more than 20 minutes going through the code with my parents (both good SAS coders) I fixed the whole code.
simster is offline
Reply With Quote
View Public Profile
 
Sponsored Links (We share ad revenue):
 
Reply     « Reply to Pagination help?
 

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off




   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML


Page generated in 0.16298 seconds with 14 queries