473,387 Members | 1,365 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

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_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
2 1727
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
Pedro, THANK YOU SO MUCH!!!
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Thomas Philips | last post by:
I recently had the need to sort a large number of lists of lists, and wondered if an improvement to the Decorate-Sort-Undecorate idiom is in the works. Ideally, I would like to sort the list of...
1
by: Kamilche | last post by:
I've written a generic sort routine that will sort dictionaries, lists, or tuples, either by a specified key or by value. Comments welcome! import types def sort(container, key = None,...
4
by: its me | last post by:
Let's say I have a class of people... Public Class People Public Sex as String Public Age as int Public Name as string end class And I declare an array of this class...
99
by: Shi Mu | last post by:
Got confused by the following code: >>> a >>> b >>> c {1: , ], 2: ]} >>> c.append(b.sort()) >>> c {1: , ], 2: , None]}
48
by: Alex Chudnovsky | last post by:
I have come across with what appears to be a significant performance bug in ..NET 2.0 ArrayList.Sort method when compared with Array.Sort on the same data. Same data on the same CPU gets sorted a...
0
by: Raj | last post by:
We are on a db2 v8.2 (fix 8) with DPF & intra parllelism. Below are sort related configuration settings ...
10
by: Woody Ling | last post by:
In 32 bits DB2 environment, is it meaningful to set sheapthres larger than 256MB for the following case.. 1. Intra-parallel is ON 2. Intra-parallel is OFF
5
by: neehakale | last post by:
I know that heap sort,quick sort and merg sort are the faster sorting algoritms than the bubble sort,selection sort,shell sort and selection sort. I got an idea,in which situation we can use...
3
by: aRTx | last post by:
I have try a couple of time but does not work for me My files everytime are sortet by NAME. I want to Sort my files by Date-desc. Can anyone help me to do it? The Script <? /* ORIGJINALI
3
by: raylopez99 | last post by:
This is an example of using multiple comparison criteria for IComparer/ Compare/CompareTo for List<and Array. Adapted from David Hayden's tutorial found on the net, but he used ArrayList so the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.