PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
cheerio
Forum Newbie
Posts: 18 Joined: Sat Aug 13, 2005 4:52 pm
Post
by cheerio » Sat Sep 03, 2005 3:19 pm
hey i'm just making a comment board heres the function that displays the old entries:
Code: Select all
function showold($file,$badwordsarray,$cleanword) {
switch($_GET[badlang]) {
case off:
$filter = 0;
break;
default:
$filter = 1;
break;
}
$contents_old = file_get_contents($file);
if($filter) {
echo "<font class='valid'>bad words filter is ON. click <a href='?badlang=off'>here</a> to turn it off</font>";
$contents_old = str_ireplace($badwordsarray,$cleanword,$contents_old);
} else {
echo "<font class='invalid'>bad words filter is OFF! click <a href='index.php'>here</a> to turn it on</font>";
}
$row = explode("|line|",$contents_old);
?>
<table class="old">
<?php
for($i = 0;$i < count($row);$i++)
{
list($name,$contact,$subject,$date,$comment) = explode("|#|",$row[$i]);
$color1 = "#DDDDDD";
$color2 = "#EEEEEE";
$style = ($i % 2==1) ? "$color1" : "$color2";
echo '
<tr>
<td rowspan="2" class="leftold" title="Post #'.$i.'">'.$i.'</td>
<td rowspan="2" class="leftold" ><font title="Poster\'s Name">'.$name.'</font><br>[ <font class="oldleft" title="Email/Sn of '.$name.'">'.$contact.'</font> ]</td>
<td class="rightold" title="Subject of Post"><b>Subject:</b><i>'.$subject.'</i></td>
<td class="rightold" title="Date/Time Posted"><b>Date/Time:</b><i>'.$date.'</i></td>
</tr>
<tr>
<td class="rightold" style="background-color:#EEEEEE" colspan=2 title="'.$name.'\'s Comment">'.$comment.'</td>
</tr>
';
}
echo '</table>';
}
what i want it to do is sort by variable, $date but can't figure out how
thanks in advanced
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Sep 03, 2005 3:25 pm
first thing, you'll have to store up the broken apart bits like so:
Code: Select all
$rows = explode("|line|",$contents_old);
foreach($rows as $row => $data)
{
$rows[$row] = explode("|#|",$row[$i]);
}
then I'd suggest using
usort() with your own function that will sort based on the date.
cheerio
Forum Newbie
Posts: 18 Joined: Sat Aug 13, 2005 4:52 pm
Post
by cheerio » Sat Sep 03, 2005 3:39 pm
:'( i'm dont follow that too well..i don't know what to do next now :'(
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Sep 03, 2005 3:42 pm
do you not understand the code, or the usort() part?
cheerio
Forum Newbie
Posts: 18 Joined: Sat Aug 13, 2005 4:52 pm
Post
by cheerio » Sat Sep 03, 2005 3:43 pm
the code. I got confused at like the $rows[$row] line
s.dot
Tranquility In Moderation
Posts: 5001 Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana
Post
by s.dot » Sat Sep 03, 2005 3:52 pm
$rows[$row] would be the KEY $row (which references the VALUE) of ARRAY $rows
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
cheerio
Forum Newbie
Posts: 18 Joined: Sat Aug 13, 2005 4:52 pm
Post
by cheerio » Sat Sep 03, 2005 8:34 pm
so now how would i be able to echo like name, contact, comment, etc???? is it still possible for me to use the list command?
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Sep 03, 2005 8:42 pm
if using a foreach, you can use list() with the value variable.
cheerio
Forum Newbie
Posts: 18 Joined: Sat Aug 13, 2005 4:52 pm
Post
by cheerio » Sat Sep 03, 2005 8:57 pm
Code: Select all
$rows = explode("|line|",$contents_old);
?>
<table class="old">
<?php
$i = 0;
while($i < count($rows)) {
foreach($rows as $row => $data) {
$rows[$row] = explode("|#|",$row[$i]);
list($name,$contact,$subject,$date,$comment,$ip) = $data;
echo '
<tr>
<td rowspan="2" class="leftold" title="Post #'.$i.'">'.$i.'</td>
<td rowspan="2" class="leftold" ><font title="Poster\'s Name">'.$name.'</font><br>[ <font class="oldleft" title="Email/Sn of '.$name.'">'.$contact.'</font> ]</td>
<td class="rightold" title="Subject of Post"><b>Subject:</b><i>'.$subject.'</i></td>
<td class="rightold" title="Date/Time Posted"><b>Date/Time:</b><i>'.$date.'</i></td>
<td class="rightold" title="IP of '.$name.'"><b>IP:</b><i>'.$ip.'</i></td>
</tr>
<tr>
<td class="rightold" style="background-color:#EEEEEE" colspan=3 title="'.$name.'\'s Comment">'.$comment.'</td>
</tr>
';
$i++;
}
echo '</table>';
}
}
?>
i did something wrong in that script...it onlu echos the first letter of for any of the variable like name contact, comments, etc
btw thanks for alot of replies sorry i keep asking for more i just can't get it to work :'(
im kind of new to PHP so...
feyd
Neighborhood Spidermoddy
Posts: 31559 Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA
Post
by feyd » Sat Sep 03, 2005 9:34 pm
the list and echo does not go inside that loop. That loop is for setting up the data so you can sort it. You need an additional loop that runs over $rows after being sorted.
cheerio
Forum Newbie
Posts: 18 Joined: Sat Aug 13, 2005 4:52 pm
Post
by cheerio » Sun Sep 04, 2005 10:39 am
oh