PS. even doorgaan op wat ik eerder zei ...
De reactie van Aad klopt ook.
Maar denk ook: de voornaamste reden waarom je deftig filtert op mySQL-niveau is om de data-trafiek database -> apache (php) zo klein mogelijk te houden.
Je hebt echter de data van alle records nodig. Dan kan je even goed een beetje minder energie steken in de sql query
-----
Ik heb iets uitgewerkt. (nogal quick & dirty, voorlopig)
Probeer dit al eens uit. Volgens mij doet dit al bijna wat je nodig hebt.
Best even testen op een aparte test-database
Ik stuur een sql export mee.
Dan nog exporteren naar csv ...
<?php
/*
CREATE TABLE IF NOT EXISTS users (
id int(10) unsigned NOT NULL AUTO_INCREMENT,
username varchar(60) NOT NULL DEFAULT '',
pass varchar(32) NOT NULL DEFAULT '',
email varchar(64) DEFAULT '',
mode tinyint(4) NOT NULL DEFAULT '0',
PRIMARY KEY (id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;
INSERT INTO users (id, username, pass, email, mode) VALUES
(2, 'wrupucicha', '7ca62315c9b9e0b46d7fb4aaf287bd30', 'wrupucicha@localhost', 0),
(3, 'tranubiwr', '', 'tranubiwr@localhost', 0),
(4, 'lonehesac', '72540b4a4eb73db2b1cd0d30b5e79cac', 'lonehesac@localhost', 0),
(5, 'buthiueph', '33330f42a4de4bee9c10b4f702fb8b9b', 'buthiueph@localhost', 0),
(6, 'speshigut', '2735cbc0677f66f6b5c8ef5ac009bd82', 'speshigut@localhost', 0),
(7, 'driswu', '11a97797dc59536a95949bb4f9d779b3', 'driswu@localhost', 0),
(8, 'kamecrolac', '77813980d48a32d642353fd8876ccf68', 'kamecrolac@localhost', 0),
(9, 'stiphislod', 'de6c1dbdd7c20b692516fdafc281bc59', 'stiphislod@localhost', 0),
(10, 'drukesh', '1ea73311475652082690252f4e0b8a4c', 'drukesh@localhost', 0),
(11, 'hemutihefro', 'bfa0c373b636831d3bd35f6a412011e5', 'hemutihefro@localhost', 0),
(12, 'buthiueph', '333b', 'buthiueph@localhost', 0),
(13, 'Tom', '', 'driswu@localhost', 0),
(14, 'Freddy', 'dcd0ff2c99c6b7f384e84e4304a27f98', 'tranubiwr@localhost', 0);
*/
$records = array();
$temp_record = null;
$max_records = 100;
$con = mysql_connect( 'localhost', 'root', '' );
mysql_select_db('phphulp');
$sql = "
SELECT
id, username, pass, email
FROM users
ORDER BY email, id DESC
";
$res = mysql_query($sql);
while ($row = mysql_fetch_assoc($res)) {
add_record($row, $temp_record, $records);
}
// save last record
save_record($temp_record);
echo '<pre>' . print_r($records, TRUE) . '</pre>';
function add_record($row, &$temp_record, &$records) {
if (empty($temp_record)) {
$temp_record = $row;
}
if ($row['email'] === $temp_record['email']) {
// alle velden van $record overlopen, indien een veld leeg is, proberen we het veld uit $row te halen
foreach ($temp_record as $key=>$field) {
if ($key === 'email') {
continue;
}
if (is_empty($field)) {
$temp_record[$key] = $row[$key];
}
}
}
else { // wwe hebben een nieuw record, met verschillend e-mail-adres. Nu pas gaan we het vorige recors opslaan
save_record($temp_record);
$temp_record = $row;
}
}
function is_empty($string) {
// ik zet het in een aparte functie. Indien nodig kan dit gemakkelijk geoptimaliseerd worden
return
trim($string) === ''
? TRUE
: FALSE;
}
function save_record(&$record) {
global $records; // een beetje quick & dirty. ... tja ...
$records[count($records)] = $record;
}
?>