Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Old 06-19-2010, 10:14 AM Sort by Date
Novice Talker

Posts: 11
Trades: 0
I am creating a news system using flatfile database and im having a problem sorting them by date (newest date first)

here is my script
PHP Code:
<?php
$fp 
file("news/news.db");
//$data = fread($fp, filesize($fp)); 
$k 0;
foreach(
$fp as $key => $val
{
   
//explode that data into a new array:  
   
$data[$key] = explode("||"$val);
}
$i++;
$i 0;
for(
$k 0$k sizeof($fp); $k++) 

?><head>
<link rel="stylesheet" href="style.css" type="text/css">
</head>

<table width="95%"  border="1">
  <tr>
    <td align="left"><?php echo "" $data[$k][0] . ""?></td>
  </tr>
  <tr>
    <td><?php echo "" $data[$k][1] . ""?></td>
  </tr>
  <tr>
    <td><?php echo "" $data[$k][3] . ""?></td>
  </tr>
  <tr>
    <td><?php echo usort($data[$k][2]); ?></td>
  </tr>
</table>
<?php 
if(++$i 4) break;
 }
?>
__________________
~Fear the one they call Smackie for thy who tries and kills thee thy will be died before sunrise Death 10:1~
Smackie is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-19-2010, 10:29 AM Re: Sort by Date
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
You can build a user function to sort with and call it by usort() of the array.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 06-19-2010, 10:31 AM Re: Sort by Date
Novice Talker

Posts: 11
Trades: 0
i tried that it gave me this warning

Quote:
Warning: Wrong parameter count for usort() in
sorry i haven't messed with flatfile databased in a long time lol.
__________________
~Fear the one they call Smackie for thy who tries and kills thee thy will be died before sunrise Death 10:1~

Last edited by Smackie; 06-19-2010 at 10:34 AM..
Smackie is offline
Reply With Quote
View Public Profile
 
Old 06-19-2010, 12:01 PM Re: Sort by Date
tripy's Avatar
Do not try this at home!

Posts: 3,621
Name: Thierry
Location: I'm the uber Spaminator !
Trades: 0
http://php.net/manual/en/function.usort.php
__________________
Only a biker knows why a dog sticks his head out the window.
tripy is offline
Reply With Quote
View Public Profile Visit tripy's homepage!
 
Reply     « Reply to Sort by Date
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB 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.66863 seconds with 12 queries