/    Sign up×
Community /Pin to ProfileBookmark

How to sort data from a CSV

Hi, i have searched around the web for this, and tried a lot but nothing seems to go well with this.
Right now, i have this script and i want to sort the $parts[0]
The ksort or usort functions don’t sort the parts of the array (if i say it right), so how do i sort it than ?

[code=php]<html>
<head>
<link rel=”stylesheet” type=”text/css” href=”style.css” />
</head>
<body bgcolor=#E2E965 link=#812990 vlink=#812990 alink=#812990 text=black>
</html>
<?PHP
$offset = isset($_GET[‘offset’])?$_GET[‘offset’]:0;
$LinesToDisplay = 6;
$row = $offset + $LinesToDisplay;
$row2 = $offset – $LinesToDisplay;
$file_handle = fopen(“web.txt”, “rb”);

while ((($parts = fgetcsv($file_handle,4096,”|”)) !== FALSE) && ($LinesToDisplay >

0) && (!feof($file_handle)))
{
//new code
//skip first $offset lines
if ($offset– > 0)
{
continue;
}
///////////////////////////

$num = count($parts[1]);
if ( $parts[6] >= 9998)

$parts[0] = ucwords(strtolower($parts[0]));
$parts[1] = ucwords(strtolower($parts[1]));

echo “<p><a class=’popup4′ href=’#’><font size=-1

face=Humanist777BT-ExtraBlackB><b>$parts[0]</b></font>”;
echo “<table><tr><td><i>”;
echo “<span class=’comment’>$parts[1]</span></td></tr></table></i></a>”;
echo “<TABLE BORDER=’0′ cellpadding=’0′ CELLSPACING=’0′><TR><TD WIDTH=’70’

HEIGHT=’20’ BACKGROUND=’pricebackground.jpg’ VALIGN=’bottom’><center><font

color=white>€”. $parts[2] .”</center></td></tr></table>”;
echo “<b><font size=3 color=#D7182A>Op Voorraad In:<br></font>”;
echo (” Amsterdam “);
if ( $parts[4] >= 1 ) echo (“<IMG SRC =green.gif>”).””;
if ( $parts[4] == 0 ) echo (“<IMG SRC =red.gif>”).””;
echo (” Utrecht “);
if ( $parts[5] >= 1 ) echo (“<IMG SRC =green.gif>”).”<div

class=’spacer_black’></div></b>”;
if ( $parts[5] == 0 ) echo (“<IMG SRC =red.gif>”).”<div

class=’spacer_black’></div></b>”;

//new code
//By here we decrement the line to display, when this reaches 0 the loop will

stop
$LinesToDisplay–;
//////////////////////////////
}
fclose($file_handle);
?>
<html>
<BR><a href=”occasion.php?offset=<?php echo $row2;?>”>Previous</a> – <a

href=”occasion.php?offset=<?php echo $row;?>”>Next</a></html>[/code]

to post a comment
PHP

0Be the first to comment 😎

×

Success!

Help @madmega spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.17,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...