473,785 Members | 2,261 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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>";
......
?>
Jul 17 '05 #1
2 1746
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_conten ts('./' . $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($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>';
}
.....
?>

--
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
2011
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 lists (or tuples) in place by using a simple variant of the current idiom, i.e. list_of_lists.sort(*columns) where *columns is a tuple that specifies the column order for the sort. If *columns is left blank, the sort ought to work as it does...
1
2284
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, ascending = True): ' Sort lists or dictionaries by the specified key' t = type(container)
4
3768
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
4678
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
4491
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 lot faster with both methods using .NET 1.1, that's why I am pretty sure its a (rather serious) bug. Below you can find C# test case that should allow you to reproduce this error, to run it you will need to put 2 data files into current directory...
0
2765
by: Raj | last post by:
We are on a db2 v8.2 (fix 8) with DPF & intra parllelism. Below are sort related configuration settings ----------------------------------------------------------------------------------------------------------------------------------- Sort heap threshold (4KB) (SHEAPTHRES) = 200000 Sort heap thres for shared sorts (4KB) (SHEAPTHRES_SHR) = (SHEAPTHRES) ...
10
5615
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
16637
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 bubble sort(use when we have to 100 items: bubble sort is effective),shell sort is effective when one has to sort near abt 5000 items..selection sort is effective for sorting 1000 items...and more than 1000 and less than 5000 items if u have to sort use...
3
5194
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
10559
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 format was different. Basically you can sort a class having members LastName (string), FirstName (string) and Age (int) according to whether you want to sort by Last Name, First Name or Age, using the .Sort function
0
9484
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10350
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10157
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10097
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8983
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6742
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5386
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5518
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2887
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.