By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,746 Members | 1,924 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,746 IT Pros & Developers. It's quick & easy.

Sort-Problem

P: n/a
Hi,

with the code below the output is sort by $verantw but $title and
$file in the same row DON'T belong to $verantw.

How do I have to make the sort command that $verantw, $title and $file
in the row "belongs together"?

Hope you understand my problem......

<?php
$handle = opendir('.');
$daten = array();
$daten['files'] = array();
$daten['title_tags'] = array();
$daten['verantw'] = array();
while ($file = readdir($handle)) {
if (substr($file, -4) == '.htm') {
$daten['files'][] = $file;
$html = file_get_contents('./' . $file);
preg_match_all('/!!!!(.*)!!!!/', $html, $matches);
if (isset($matches[1][0])) {
$daten['verantw'][] = $matches[1][0];
}
preg_match_all('!<title>([^<]+)</title>!i', $html, $matches);
if (isset($matches[1][0])) {
$daten['title_tags'][] = $matches[1][0];
}
}
}

sort($daten['verantw']);

$nr = 0;
$max = count($daten['verantw']);
for ($i = 0; $i < $max; $i++) {
echo "<tr>";
echo "<td class=\"text\" width=\"4%\">".++$nr."</td>";

echo "<td class=\"text\" width=\"28%\"><a class=\"link\"
href=\"".$daten['files'][$i]."\"
target=\"_blank\">".$daten['files'][$i]."</a></td>";

echo "<td class=\"verantw\" width=\"25%\">";
if ($daten['verantw'][$i]) echo $daten['verantw'][$i];
else echo '&nbsp;';
echo "</td>";

echo "<td class=\"text\" width=\"35%\">";
if ($daten['title_tags'][$i]) echo $daten['title_tags'][$i];
else echo '&nbsp;';
echo "</td>";
......
?>
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
jagg wrote:
with the code below the output is sort by $verantw but $title and
$file in the same row DON'T belong to $verantw.
Bad array structure.
How do I have to make the sort command that $verantw, $title and $file
in the row "belongs together"?

Hope you understand my problem......

<?php
$handle = opendir('.');
$daten = array();
# $daten['files'] = array();
# $daten['title_tags'] = array();
# $daten['verantw'] = array();

No need for these last three initializations!

while ($file = readdir($handle)) {
if (substr($file, -4) == '.htm') {
### $daten['files'][] = $file;
$html = file_get_contents('./' . $file);
preg_match_all('/!!!!(.*)!!!!/', $html, $matches);
if (isset($matches[1][0])) {
### $daten['verantw'][] = $matches[1][0];
$verantw = $matches[1][0];
// are you sure about $matches[1][0]?
}
preg_match_all('!<title>([^<]+)</title>!i', $html, $matches);
if (isset($matches[1][0])) {
### $daten['title_tags'][] = $matches[1][0];
$title_tags = $matches[1][0];
// again, are you sure about $matches[1][0]? }
$daten[] = array($file, $verantw, $title_tags);
}
}

# sort($daten['verantw']);
usort($daten, 'cmp_function')

/* ***
and cmp_function should be something like

function cmp_function($left, $rite) {
if ($left[1] < $rite[1]) return -1;
return ($left[1] == $rite[1]) ? 0 : 1;
}

$left[1] and $rite[1] are the $verantw column.
*** */

(snip array output)

foreach ($daten as $one_data) {
echo '<tr>';
echo '<td class="whatever" width="33%">', $one_data[0], '</td>';
echo '<td>', $one_data[1], '</td>';
echo '<td>', $one_data[2], '</td>';
echo '</tr>';
}
.....
?>

--
USENET would be a better place if everybody read: | to email me: use |
http://www.catb.org/~esr/faqs/smart-questions.html | my name in "To:" |
http://www.netmeister.org/news/learn2quote2.html | header, textonly |
http://www.expita.com/nomime.html | no attachments. |
Jul 17 '05 #2

P: n/a
Pedro, THANK YOU SO MUCH!!!
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.