Sort-Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jagg

    Sort-Problem

    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_conten ts('./' . $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>";
    ......
    ?>
  • Pedro Graca

    #2
    Re: Sort-Problem

    jagg wrote:[color=blue]
    > with the code below the output is sort by $verantw but $title and
    > $file in the same row DON'T belong to $verantw.[/color]

    Bad array structure.
    [color=blue]
    > 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();[/color]

    # $daten['files'] = array();
    # $daten['title_tags'] = array();
    # $daten['verantw'] = array();

    No need for these last three initializations !

    [color=blue]
    > while ($file = readdir($handle )) {
    > if (substr($file, -4) == '.htm') {[/color]

    ### $daten['files'][] = $file;
    [color=blue]
    > $html = file_get_conten ts('./' . $file);
    > preg_match_all( '/!!!!(.*)!!!!/', $html, $matches);
    > if (isset($matches[1][0])) {[/color]

    ### $daten['verantw'][] = $matches[1][0];
    $verantw = $matches[1][0];
    // are you sure about $matches[1][0]?
    [color=blue]
    > }
    > preg_match_all( '!<title>([^<]+)</title>!i', $html, $matches);
    > if (isset($matches[1][0])) {[/color]

    ### $daten['title_tags'][] = $matches[1][0];
    $title_tags = $matches[1][0];
    // again, are you sure about $matches[1][0]?[color=blue]
    > }[/color]

    $daten[] = array($file, $verantw, $title_tags);
    [color=blue]
    > }
    > }
    >[/color]

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

    /* ***
    and cmp_function should be something like

    function cmp_function($l eft, $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>';
    }
    [color=blue]
    > .....
    > ?>[/color]


    --
    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. |

    Comment

    • jagg

      #3
      Re: Sort-Problem

      Pedro, THANK YOU SO MUCH!!!


      Comment

      Working...