Bonjour,


Je vous montre ici une image de ma table dans phpMyAdmin:

Nom : phpsql.png
Affichages : 245
Taille : 104,2 Ko

Actuellement j'utilise ce script en php :

MaListeDeContact("Louis") :
Code php : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
 
<?php
$nick_me = "Louis";
 
$sql = "SELECT * FROM messages WHERE 
nickname_a='$nick_me' and deleting_nickname_me=''
or
nickname_receiver='$nick_me' and nickname_b=nickname_me and deleting_nickname_receiver=''
or
nickname_receiver='$nick_me' and nickname_a=nickname_me and deleting_nickname_receiver=''
order by id desc";
//problème
 
$reponse = mysqli_query($bddi,$sql);
 
$nbr = mysqli_num_rows($reponse); 
 
$boolean = "";
$i = 0;
while ($donnees = mysqli_fetch_array($reponse) )
{
	if ( $donnees[nickname_receiver] != $nick_me ) {
		$nick = $donnees[nickname_receiver];	
	}
	else {
		$nick = $donnees[nickname_a];	
	}
 
?>
id:<?=$donnees[id]?>, from:<?=$nick?>, status:<?=$donnees[status];?>, time: <?=$donnees[timestamp];?><br>
<?php
}
 
$i++;
 
?>

La réponse est:

id:51, from:Mo, status:read, time: 1472365868
id:50, from:Mooky, status:unread, time: 1472365723
id:49, from:Mooky, status:read, time: 1472365680
id:48, from:Mooky63, status:read, time: 1472365670
id:47, from:Mooky, status:read, time: 1472365625
id:45, from:Mooky, status:read, time: 1472365344
id:44, from:Mooky, status:read, time: 1472365333
id:40, from:Mooky, status:read, time: 1472351004
id:39, from:Mooky, status:read, time: 1472350940
id:38, from:Mooky3, status:unread, time: 1472350260
id:37, from:Mooky, status:read, time: 1472350243
id:36, from:Mooky, status:read, time: 1472350199
id:35, from:Mooky, status:read, time: 1472350140
id:34, from:Mooky, status:read, time: 1472349994
id:33, from:Mooky, status:read, time: 1472349976
id:32, from:Mooky, status:read, time: 1472349953
id:31, from:Mooky, status:read, time: 1472349320
id:30, from:Mooky, status:read, time: 1472349237
id:29, from:Mooky, status:read, time: 1472349212
id:28, from:Mooky, status:read, time: 1472349199
Explications :

J'essaye de faire un système pour créer une liste de contacts à partir d'un call qui est: "MaListeDeContact("Louis")" , pour cela il faut regarder à la fois dans "nickname_me" et "nickname_receiver" pour qu'il affiche tous ces contacts.

Les problème les voici :
1) Il faut que le status "unread" s'affiche toujours dans les premiers, il ne faut pas de "read" entre eux (dans l'ordre avec timestamp ou id) comme avec cette ligne par exemple qui doit être tout en haut: id:50, from:Mooky, status:unread, time: 1472365723 et aussi celle ci : id:38, from:Mooky3, status:unread, time: 1472350260

2) Il faut afficher les pseudos en "from" une seule fois sans doublons, il doit récupérer toujours le dernier status=unread les plus récents et ensuite il affiche les "read".


Je vous montre un exemple pour mieux comprendre ce que je voudrais afficher, ceci est un montage fait à la main:

id:50, from:Mooky, status:unread, time: 1472365723
id:38, from:Mooky3, status:unread, time: 1472350260
id:51, from:Mo, status:read, time: 1472365868
id:48, from:Mooky63, status:read, time: 1472365670
Je cherche une solution pour afficher ceci en php/mysql, est-ce quelqu'un pourrait m'aider?

Merci.


Table sql :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
-- phpMyAdmin SQL Dump
-- version 4.0.10.14
-- http://www.phpmyadmin.net
--
-- Client: localhost:3306
-- Généré le: Dim 28 Août 2016 à 16:52
-- Version du serveur: 5.5.50-cll
-- Version de PHP: 5.6.20
 
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
 
 
/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8 */;
 
--
-- Base de données: `espaceli_thechat`
--
 
-- --------------------------------------------------------
 
--
-- Structure de la table `messages`
--
 
CREATE TABLE IF NOT EXISTS `messages` (
  `id` int(11) NOT NULL AUTO_INCREMENT,
  `message` text NOT NULL,
  `time` text NOT NULL,
  `timestamp` text,
  `nickname_me` text NOT NULL,
  `nickname_receiver` text NOT NULL,
  `status` varchar(6) NOT NULL,
  `deleting_nickname_me` text NOT NULL,
  `deleting_nickname_receiver` text NOT NULL,
  `nickname_a` text NOT NULL,
  `nickname_b` text NOT NULL,
  PRIMARY KEY (`id`)
) ENGINE=MyISAM  DEFAULT CHARSET=latin1 AUTO_INCREMENT=52 ;
 
--
-- Contenu de la table `messages`
--
 
INSERT INTO `messages` (`id`, `message`, `time`, `timestamp`, `nickname_me`, `nickname_receiver`, `status`, `deleting_nickname_me`, `deleting_nickname_receiver`, `nickname_a`, `nickname_b`) VALUES
(45, '0002', '', '1472365344', 'Louis', 'Mooky', 'read', '', '', 'Louis', 'Mooky'),
(2, '01', '', '1472339529', 'Test', 'Mooky', 'unread', '', '', 'Test', 'Mooky'),
(3, 'testt', '', '1472339781', 'Test', 'Mooky', 'read', '', '', 'Test', 'Mooky'),
(4, 'testtt', '', '1472342897', 'Test', 'Mooky', 'read', '', '', 'Test', 'Mooky'),
(5, 'testtttt', '', '1472342951', 'Test', 'Mooky', 'read', '', '', 'Test', 'Mooky'),
(6, '01', '', '1472342962', 'Test', 'Mooky', 'read', '', '', 'Test', 'Mooky'),
(44, 'testtt', '', '1472365333', 'Louis', 'Mooky', 'read', '', '', 'Louis', 'Mooky'),
(8, '\nffff', '', '1472344869', 'Test', 'Mooky', 'read', '', '', 'Test', 'Mooky'),
(10, 'testtt', '', '1472347777', 'Test', 'Mooky', 'read', '', '', 'Test', 'Mooky'),
(11, 'p', '', '1472347781', 'Test', 'Mooky', 'read', '', '', 'Test', 'Mooky'),
(12, '\nm', '', '1472347782', 'Test', 'Mooky', 'read', '', '', 'Test', 'Mooky'),
(14, 'p', '', '1472347887', 'Test', 'Mooky', 'read', '', '', 'Test', 'Mooky'),
(16, '\np', '', '1472347945', 'Test', 'Mooky', 'read', '', '', 'Test', 'Mooky'),
(23, 'p', '', '1472348315', 'Test', 'Mooky', 'read', '', '', 'Test', 'Mooky'),
(26, 'ppp', '', '1472348654', 'Test', 'Mooky', 'read', '', '', 'Test', 'Mooky'),
(20, 'ppp', '', '1472348257', 'Test', 'Mooky', 'read', '', '', 'Test', 'Mooky'),
(25, 'testttt', '', '1472348606', 'Test', 'Mooky', 'read', '', '', 'Test', 'Mooky'),
(28, 'pppp', '', '1472349199', 'Mooky', 'Louis', 'read', '', '', 'Mooky', 'Louis'),
(29, 'pp', '', '1472349212', 'Mooky', 'Louis', 'read', '', '', 'Mooky', 'Louis'),
(30, 'ppp\n', '', '1472349237', 'Mooky', 'Louis', 'read', '', '', 'Mooky', 'Louis'),
(31, 'pp', '', '1472349320', 'Mooky', 'Louis', 'read', '', '', 'Mooky', 'Louis'),
(32, 'ppp\n', '', '1472349953', 'Mooky', 'Louis', 'read', '', '', 'Mooky', 'Louis'),
(33, 'pppp', '', '1472349976', 'Mooky', 'Louis', 'read', '', '', 'Mooky', 'Louis'),
(34, 'pppp', '', '1472349994', 'Mooky', 'Louis', 'read', '', '', 'Mooky', 'Louis'),
(35, 'testttt', '', '1472350140', 'Mooky', 'Louis', 'read', '', '', 'Mooky', 'Louis'),
(36, 'testtt', '', '1472350199', 'Mooky', 'Louis', 'read', '', '', 'Mooky', 'Louis'),
(37, 'p', '', '1472350243', 'Mooky', 'Louis', 'read', '', '', 'Mooky', 'Louis'),
(38, 'ppp', '', '1472350260', 'Mooky3', 'Louis', 'unread', '', '', 'Mooky3', 'Louis'),
(39, 'pp', '', '1472350940', 'Mooky', 'Louis', 'read', '', '', 'Mooky', 'Louis'),
(40, 'ppppppppppppppppppppppp', '', '1472351004', 'Mooky', 'Louis', 'read', '', '', 'Mooky', 'Louis'),
(46, 'p', '', '1472365612', 'Mooky', 'Louis2', 'read', '', '', 'Mooky', 'Louis2'),
(47, 'gg', '', '1472365625', 'Louis', 'Mooky', 'read', '', '', 'Louis', 'Mooky'),
(48, 'ffffffffffffffff', '', '1472365670', 'Louis', 'Mooky63', 'read', '', '', 'Louis', 'Mooky63'),
(49, 'mmmm', '', '1472365680', 'Mooky', 'Louis', 'read', '', '', 'Mooky', 'Louis'),
(50, 'jjhgg', '', '1472365723', 'Mooky', 'Louis', 'unread', '', '', 'Mooky', 'Louis'),
(51, 'testMo', '', '1472365868', 'Mo', 'Louis', 'read', '', '', 'Mo', 'Louis');
 
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;