sql selecteert per user op messages op tijd
ik heb een script die data fout selecteer eerst alle messages per users en die echot hij op tijd
bijv.
user1
message3
message2
message1
user2
message3
message2
message1
enz.
en zo doet hij dat bij elke user maar ik zou graag willen dat hij
alle messages op tijd selectteerd
sorry voor de slecht uitleg en titel
ik weet niet hoe ik het anders moet uitleggen
dit is mijn script:
Code (php)
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?php
session_start();
include_once 'php/connect.php';
$user_id = mysqli_real_escape_string($con, $_SESSION['user_id']);
$friends = "SELECT
*
FROM
friends
WHERE
user_id='$user_id'
AND
status='vrienden'
UNION
SELECT
*
FROM
friends
WHERE
friend_id='$user_id'
AND
status='vrienden'
UNION
SELECT
*
FROM
friends
WHERE
user_id='$user_id'
AND
friend_id='$user_id'
AND
status='you'";
$queryf = mysqli_query($con, $friends);
if($queryf == false)
{
echo '<font color="red">Error: ' . mysqli_error($con) . '</font';
exit();
}
while($row = mysqli_fetch_array($queryf))
{
if($row['user_id'] == $user_id)
{
$id = $row['friend_id'];
}
elseif($row['friend_id'] == $user_id)
{
$id = $row['user_id'];
}
if(isset($_GET['limit']))
{
if(is_numeric($_GET['limit']))
{
$limit = mysqli_real_escape_string($con, $_GET['limit']);
}
else
{
$limit = "15";
}
}
else
{
$limit = "15";
}
$select = "SELECT
*
FROM
status
WHERE
user_id='$id'
ORDER BY
time
DESC
LIMIT 0, $limit";
$run = mysqli_query($con, $select);
while($message = mysqli_fetch_array($run))
{
$selectu = "SELECT * FROM users WHERE id='$id'";
$query = mysqli_query($con, $selectu);
$user = mysqli_fetch_array($query);
if($user['profielfoto'] != '')
{
$pf = $user['profielfoto'];
}
else
{
$pf = 'persoon.jpg';
}
echo '<div class="message" onclick="persoon(' . $user['id'] . ')">';
echo '<div class="profielfoto">';
echo '<img src="pf/' . $pf . '" height="80" width="80">';
echo '</div><div class="name"><h2 style="float: right;">';
echo $user['voornaam'] . ' ' . $user['achternaam'] . '</h2></div>';
echo '<div class="txt">';
echo $message['message'] . '</div><br>';
echo '</div>';
}
}
$select = mysqli_query($con, "SELECT * FROM status WHERE user_id='$id'");
$count = mysqli_num_rows($select);
if(isset($_GET['limit']))
{
if(is_numeric($_GET['limit']))
{
$limit = mysqli_real_escape_string($con, $_GET['limit']);
$newlimit = $limit + '10';
if($count <= $limit)
{
echo '<p style="margin-top: 20px; margin-left: 560px;">er zijn geen meer berichten</p>';
}
else
{
echo '<a style="margin-top: 20px; margin-left: 590px;"href="home.php?limit=' . $newlimit . '">laad meer</a>';
}
}
else
{
if($count <= $limit)
{
echo '<p style="margin-top: 20px; margin-left: 560px;">er zijn geen meer berichten</p>';
}
else
{
echo '<a href="home.php?limit=25" style="margin-left: 590px; margin-top: 20px;">laad meer</a>';
}
}
}
else
{
if($count <= $limit)
{
echo '<p style="margin-top: 20px; margin-left: 560px;">er zijn geen meer berichten</p>';
}
else
{
echo '<a href="home.php?limit=25" style="margin-top: 20px; margin-left: 590px; margin-bottom: 50px;">laad meer</a>';
}
}
?>
session_start();
include_once 'php/connect.php';
$user_id = mysqli_real_escape_string($con, $_SESSION['user_id']);
$friends = "SELECT
*
FROM
friends
WHERE
user_id='$user_id'
AND
status='vrienden'
UNION
SELECT
*
FROM
friends
WHERE
friend_id='$user_id'
AND
status='vrienden'
UNION
SELECT
*
FROM
friends
WHERE
user_id='$user_id'
AND
friend_id='$user_id'
AND
status='you'";
$queryf = mysqli_query($con, $friends);
if($queryf == false)
{
echo '<font color="red">Error: ' . mysqli_error($con) . '</font';
exit();
}
while($row = mysqli_fetch_array($queryf))
{
if($row['user_id'] == $user_id)
{
$id = $row['friend_id'];
}
elseif($row['friend_id'] == $user_id)
{
$id = $row['user_id'];
}
if(isset($_GET['limit']))
{
if(is_numeric($_GET['limit']))
{
$limit = mysqli_real_escape_string($con, $_GET['limit']);
}
else
{
$limit = "15";
}
}
else
{
$limit = "15";
}
$select = "SELECT
*
FROM
status
WHERE
user_id='$id'
ORDER BY
time
DESC
LIMIT 0, $limit";
$run = mysqli_query($con, $select);
while($message = mysqli_fetch_array($run))
{
$selectu = "SELECT * FROM users WHERE id='$id'";
$query = mysqli_query($con, $selectu);
$user = mysqli_fetch_array($query);
if($user['profielfoto'] != '')
{
$pf = $user['profielfoto'];
}
else
{
$pf = 'persoon.jpg';
}
echo '<div class="message" onclick="persoon(' . $user['id'] . ')">';
echo '<div class="profielfoto">';
echo '<img src="pf/' . $pf . '" height="80" width="80">';
echo '</div><div class="name"><h2 style="float: right;">';
echo $user['voornaam'] . ' ' . $user['achternaam'] . '</h2></div>';
echo '<div class="txt">';
echo $message['message'] . '</div><br>';
echo '</div>';
}
}
$select = mysqli_query($con, "SELECT * FROM status WHERE user_id='$id'");
$count = mysqli_num_rows($select);
if(isset($_GET['limit']))
{
if(is_numeric($_GET['limit']))
{
$limit = mysqli_real_escape_string($con, $_GET['limit']);
$newlimit = $limit + '10';
if($count <= $limit)
{
echo '<p style="margin-top: 20px; margin-left: 560px;">er zijn geen meer berichten</p>';
}
else
{
echo '<a style="margin-top: 20px; margin-left: 590px;"href="home.php?limit=' . $newlimit . '">laad meer</a>';
}
}
else
{
if($count <= $limit)
{
echo '<p style="margin-top: 20px; margin-left: 560px;">er zijn geen meer berichten</p>';
}
else
{
echo '<a href="home.php?limit=25" style="margin-left: 590px; margin-top: 20px;">laad meer</a>';
}
}
}
else
{
if($count <= $limit)
{
echo '<p style="margin-top: 20px; margin-left: 560px;">er zijn geen meer berichten</p>';
}
else
{
echo '<a href="home.php?limit=25" style="margin-top: 20px; margin-left: 590px; margin-bottom: 50px;">laad meer</a>';
}
}
?>
Toevoeging op 29/01/2014 17:51:46:
Weet iemand een oplossing
Gewijzigd op 30/01/2014 14:48:42 door Christian k
Relevant zijn de queries, en de while lussen waarin ze voorkomen.
Toevoeging op 30/01/2014 15:21:47:
ik heb het verandert naar dit
Code (php)
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
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
<?php
$user_id = mysqli_real_escape_string($con, $_SESSION['user_id']);
$select = "SELECT
*
FROM
status
ORDER BY time DESC ";
$queryse = mysqli_query($con, $select);
if($queryse == false)
{
echo '<font color="red">Error: ' . mysqli_error($con) . '</font><br>';
exit();
}
while($row = mysqli_fetch_array($queryse))
{
$usermessage = mysqli_real_escape_string($con, $row['user_id']);
$check_friend= "SELECT * FROM friends WHERE status='vrienden' AND (user_id='$user_id' OR friend_id='$user_id')";
$querycf = mysqli_query($con, $check_friend);
if($querycf == false)
{
echo '<font color="red">Error: ' . mysqli_error($con) . '</font><br>';
exit();
}
$controle = mysqli_num_rows($querycf);
if($controle != 0)
{
$selectu = "SELECT
*
FROM
users
WHERE
id='$usermessage'";
$query = mysqli_query($con, $selectu);
$user = mysqli_fetch_array($query);
if($user['profielfoto'] != '')
{
$pf = $user['profielfoto'];
}
else
{
$pf = 'persoon.jpg';
}
echo '<div class="message" onclick="persoon(' . $user['id'] . ')">';
echo '<div class="profielfoto">';
echo '<img src="pf/' . $pf . '" height="80" width="80">';
echo '</div><div class="name"><h2 style="float: right;">';
echo $user['voornaam'] . ' ' . $user['achternaam'] . '</h2></div>';
echo '<div class="txt">';
echo $row['message'] . '</div><br>';
echo '</div>';
}
}
?>
$user_id = mysqli_real_escape_string($con, $_SESSION['user_id']);
$select = "SELECT
*
FROM
status
ORDER BY time DESC ";
$queryse = mysqli_query($con, $select);
if($queryse == false)
{
echo '<font color="red">Error: ' . mysqli_error($con) . '</font><br>';
exit();
}
while($row = mysqli_fetch_array($queryse))
{
$usermessage = mysqli_real_escape_string($con, $row['user_id']);
$check_friend= "SELECT * FROM friends WHERE status='vrienden' AND (user_id='$user_id' OR friend_id='$user_id')";
$querycf = mysqli_query($con, $check_friend);
if($querycf == false)
{
echo '<font color="red">Error: ' . mysqli_error($con) . '</font><br>';
exit();
}
$controle = mysqli_num_rows($querycf);
if($controle != 0)
{
$selectu = "SELECT
*
FROM
users
WHERE
id='$usermessage'";
$query = mysqli_query($con, $selectu);
$user = mysqli_fetch_array($query);
if($user['profielfoto'] != '')
{
$pf = $user['profielfoto'];
}
else
{
$pf = 'persoon.jpg';
}
echo '<div class="message" onclick="persoon(' . $user['id'] . ')">';
echo '<div class="profielfoto">';
echo '<img src="pf/' . $pf . '" height="80" width="80">';
echo '</div><div class="name"><h2 style="float: right;">';
echo $user['voornaam'] . ' ' . $user['achternaam'] . '</h2></div>';
echo '<div class="txt">';
echo $row['message'] . '</div><br>';
echo '</div>';
}
}
?>
Toevoeging op 30/01/2014 15:30:08:
ik heb er nieuw topic over begonnen
http://www.phphulp.nl/php/forum/topic/limit-toevoegen-aan-php-code/93772/last/
Gewijzigd op 30/01/2014 14:49:43 door christian k
Christian k op 30/01/2014 14:49:05:
Toevoeging op 30/01/2014 15:30:08:
ik heb er nieuw topic over begonnen
http://www.phphulp.nl/php/forum/topic/limit-toevoegen-aan-php-code/93772/last/
Toevoeging op 30/01/2014 15:30:08:
ik heb er nieuw topic over begonnen
http://www.phphulp.nl/php/forum/topic/limit-toevoegen-aan-php-code/93772/last/
Waarom, wat is er mis met dit topic??
Gewijzigd op 30/01/2014 18:22:27 door Obelix Idefix
het werkt nu een ander probleem maar die is al opgelost