Bericht weergeven indien geen resultaat
Ik heb hier een postvak-in script. Maar als er nu geen berichten in staan, dan geeft die niks weer. Ik zou graag hiervan een melding willen plaatsen indien geen berichten.
Dit is het 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
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
<?php
echo'
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td class="start" width="10%"> </td>
<td class="start" width="30%">Onderwerp</td>
<td class="start" width="30%">Afzender</td>
<td class="start" width="20%">Datum</td>
<td class="start" width="10%"> </td>
</tr>';
$perpagina = 15;
if(!isset($_GET['page'])) {
$_GET['page'] = 0;
}
if ($_GET['page'] >= 0 && floor($_GET['page']) == $_GET['page']) {
$start = $_GET['page'] * $perpagina;
} else {
$start = 0;
}
$berichten = mysql_query("SELECT id, inbox_read, onderwerp, afzender, datum FROM berichten WHERE geaddresseerde = '" . $own['id'] . "' AND inbox = 'True' ORDER BY id LIMIT $start,$perpagina");
while($bericht = mysql_fetch_assoc($berichten)) {
if($bericht['inbox_read'] == "True") {
$email = "email_open";
} else {
$email = "email";
}
if(strlen($bericht['onderwerp']) > 25) {
$bericht['onderwerp'] = substr($bericht['onderwerp'], 0, 25) . '...';
}
if(!is_numeric($bericht['afzender'])) {
$afzender = $bericht['afzender'];
} else {
$afzender = '<a href="index.php?p=profile&uid=' . $bericht['afzender'] . '">' . special_check($bericht['afzender']) . '</a>';
}
echo'
<tr>
<td class="list" width="10%"><img src="images/icons/' . $email . '.gif"></td>
<td class="list" width="30%"><a href="index.php?p=messages&action=view&id=' . $bericht['id'] . '">' . $bericht['onderwerp'] . '</a></td>
<td class="list" width="30%">' . $afzender . '</td>
<td class="list" width="20%">' . date("d-m H:i", strtotime($bericht['datum'])) . '</td>
<td class="list" width="10%"><a href="index.php?p=messages&action=delete&id=' . $bericht['id'] . '"><img src="images/icons/cross.gif" border="0"></a></td>
</tr>
';
}
echo"</table><center>";
$users = mysql_query("SELECT * FROM berichten WHERE geaddresseerde = '" . $own['id'] . "' AND inbox = 'True'");
$paginas = floor((mysql_num_rows($users)-1)/($perpagina));
if($paginas >= 0) {
if($_GET['page'] > 0) {
echo"<a href=index.php?p=messages&page=" . ($_GET['page'] - 1) . ">« Vorige</a>";
} else {
echo"« Vorige";
}
for($i=0;$i <= $paginas;$i++) {
if($_GET['page'] == $i) {echo' | <b style="text-decoration: underline">';echo $i+1 .'</b>';} else {echo' | <a href="index.php?p=messages&page='. $i .'">'; echo $i+1 .'</a>';}
}
if($_GET['page'] < $paginas) {
echo" | <a href=index.php?p=messages&page=";
echo $_GET['page']+1 . ">Volgende »</a>";
}
else {
echo" | Volgende »";
}
}
echo"</center>";
?>
echo'
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td class="start" width="10%"> </td>
<td class="start" width="30%">Onderwerp</td>
<td class="start" width="30%">Afzender</td>
<td class="start" width="20%">Datum</td>
<td class="start" width="10%"> </td>
</tr>';
$perpagina = 15;
if(!isset($_GET['page'])) {
$_GET['page'] = 0;
}
if ($_GET['page'] >= 0 && floor($_GET['page']) == $_GET['page']) {
$start = $_GET['page'] * $perpagina;
} else {
$start = 0;
}
$berichten = mysql_query("SELECT id, inbox_read, onderwerp, afzender, datum FROM berichten WHERE geaddresseerde = '" . $own['id'] . "' AND inbox = 'True' ORDER BY id LIMIT $start,$perpagina");
while($bericht = mysql_fetch_assoc($berichten)) {
if($bericht['inbox_read'] == "True") {
$email = "email_open";
} else {
$email = "email";
}
if(strlen($bericht['onderwerp']) > 25) {
$bericht['onderwerp'] = substr($bericht['onderwerp'], 0, 25) . '...';
}
if(!is_numeric($bericht['afzender'])) {
$afzender = $bericht['afzender'];
} else {
$afzender = '<a href="index.php?p=profile&uid=' . $bericht['afzender'] . '">' . special_check($bericht['afzender']) . '</a>';
}
echo'
<tr>
<td class="list" width="10%"><img src="images/icons/' . $email . '.gif"></td>
<td class="list" width="30%"><a href="index.php?p=messages&action=view&id=' . $bericht['id'] . '">' . $bericht['onderwerp'] . '</a></td>
<td class="list" width="30%">' . $afzender . '</td>
<td class="list" width="20%">' . date("d-m H:i", strtotime($bericht['datum'])) . '</td>
<td class="list" width="10%"><a href="index.php?p=messages&action=delete&id=' . $bericht['id'] . '"><img src="images/icons/cross.gif" border="0"></a></td>
</tr>
';
}
echo"</table><center>";
$users = mysql_query("SELECT * FROM berichten WHERE geaddresseerde = '" . $own['id'] . "' AND inbox = 'True'");
$paginas = floor((mysql_num_rows($users)-1)/($perpagina));
if($paginas >= 0) {
if($_GET['page'] > 0) {
echo"<a href=index.php?p=messages&page=" . ($_GET['page'] - 1) . ">« Vorige</a>";
} else {
echo"« Vorige";
}
for($i=0;$i <= $paginas;$i++) {
if($_GET['page'] == $i) {echo' | <b style="text-decoration: underline">';echo $i+1 .'</b>';} else {echo' | <a href="index.php?p=messages&page='. $i .'">'; echo $i+1 .'</a>';}
}
if($_GET['page'] < $paginas) {
echo" | <a href=index.php?p=messages&page=";
echo $_GET['page']+1 . ">Volgende »</a>";
}
else {
echo" | Volgende »";
}
}
echo"</center>";
?>
Bedankt!
Code (php)
1
2
3
4
5
6
7
2
3
4
5
6
7
<?php
if(mysql_num_rows($result)>1) {
// er zijn geen berichten
} else {
// er zijn wel berichten, plaats hier je while-loop
}
?>
if(mysql_num_rows($result)>1) {
// er zijn geen berichten
} else {
// er zijn wel berichten, plaats hier je while-loop
}
?>
Gewijzigd op 14/10/2011 21:58:33 door - Ariën -
Bedankt voor het reageren op mijn topic.
Zou het script dan zo komen?
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
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
<?php
echo'
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td class="start" width="10%"> </td>
<td class="start" width="30%">Onderwerp</td>
<td class="start" width="30%">Afzender</td>
<td class="start" width="20%">Datum</td>
<td class="start" width="10%"> </td>
</tr>';
$perpagina = 15;
if(!isset($_GET['page'])) {
$_GET['page'] = 0;
}
if ($_GET['page'] >= 0 && floor($_GET['page']) == $_GET['page']) {
$start = $_GET['page'] * $perpagina;
} else {
$start = 0;
}
if(mysql_num_rows($result)>1) {
echo "INBOX LEEG!";
} else {
$berichten = mysql_query("SELECT id, inbox_read, onderwerp, afzender, datum FROM berichten WHERE geaddresseerde = '" . $own['id'] . "' AND inbox = 'True' ORDER BY id LIMIT $start,$perpagina");
while($bericht = mysql_fetch_assoc($berichten)) {
if($bericht['inbox_read'] == "True") {
$email = "email_open";
} else {
$email = "email";
}
if(strlen($bericht['onderwerp']) > 25) {
$bericht['onderwerp'] = substr($bericht['onderwerp'], 0, 25) . '...';
}
if(!is_numeric($bericht['afzender'])) {
$afzender = $bericht['afzender'];
} else {
$afzender = '<a href="index.php?p=profile&uid=' . $bericht['afzender'] . '">' . special_check($bericht['afzender']) . '</a>';
}
echo'
<tr>
<td class="list" width="10%"><img src="images/icons/' . $email . '.gif"></td>
<td class="list" width="30%"><a href="index.php?p=messages&action=view&id=' . $bericht['id'] . '">' . $bericht['onderwerp'] . '</a></td>
<td class="list" width="30%">' . $afzender . '</td>
<td class="list" width="20%">' . date("d-m H:i", strtotime($bericht['datum'])) . '</td>
<td class="list" width="10%"><a href="index.php?p=messages&action=delete&id=' . $bericht['id'] . '"><img src="images/icons/cross.gif" border="0"></a></td>
</tr>
';
}
echo"</table><center>";
$users = mysql_query("SELECT * FROM berichten WHERE geaddresseerde = '" . $own['id'] . "' AND inbox = 'True'");
$paginas = floor((mysql_num_rows($users)-1)/($perpagina));
if($paginas >= 0) {
if($_GET['page'] > 0) {
echo"<a href=index.php?p=messages&page=" . ($_GET['page'] - 1) . ">« Vorige</a>";
} else {
echo"« Vorige";
}
for($i=0;$i <= $paginas;$i++) {
if($_GET['page'] == $i) {echo' | <b style="text-decoration: underline">';echo $i+1 .'</b>';} else {echo' | <a href="index.php?p=messages&page='. $i .'">'; echo $i+1 .'</a>';}
}
if($_GET['page'] < $paginas) {
echo" | <a href=index.php?p=messages&page=";
echo $_GET['page']+1 . ">Volgende »</a>";
}
else {
echo" | Volgende »";
}
}
echo"</center>"; }
?>
echo'
<table width="100%" cellpadding="0" cellspacing="0">
<tr>
<td class="start" width="10%"> </td>
<td class="start" width="30%">Onderwerp</td>
<td class="start" width="30%">Afzender</td>
<td class="start" width="20%">Datum</td>
<td class="start" width="10%"> </td>
</tr>';
$perpagina = 15;
if(!isset($_GET['page'])) {
$_GET['page'] = 0;
}
if ($_GET['page'] >= 0 && floor($_GET['page']) == $_GET['page']) {
$start = $_GET['page'] * $perpagina;
} else {
$start = 0;
}
if(mysql_num_rows($result)>1) {
echo "INBOX LEEG!";
} else {
$berichten = mysql_query("SELECT id, inbox_read, onderwerp, afzender, datum FROM berichten WHERE geaddresseerde = '" . $own['id'] . "' AND inbox = 'True' ORDER BY id LIMIT $start,$perpagina");
while($bericht = mysql_fetch_assoc($berichten)) {
if($bericht['inbox_read'] == "True") {
$email = "email_open";
} else {
$email = "email";
}
if(strlen($bericht['onderwerp']) > 25) {
$bericht['onderwerp'] = substr($bericht['onderwerp'], 0, 25) . '...';
}
if(!is_numeric($bericht['afzender'])) {
$afzender = $bericht['afzender'];
} else {
$afzender = '<a href="index.php?p=profile&uid=' . $bericht['afzender'] . '">' . special_check($bericht['afzender']) . '</a>';
}
echo'
<tr>
<td class="list" width="10%"><img src="images/icons/' . $email . '.gif"></td>
<td class="list" width="30%"><a href="index.php?p=messages&action=view&id=' . $bericht['id'] . '">' . $bericht['onderwerp'] . '</a></td>
<td class="list" width="30%">' . $afzender . '</td>
<td class="list" width="20%">' . date("d-m H:i", strtotime($bericht['datum'])) . '</td>
<td class="list" width="10%"><a href="index.php?p=messages&action=delete&id=' . $bericht['id'] . '"><img src="images/icons/cross.gif" border="0"></a></td>
</tr>
';
}
echo"</table><center>";
$users = mysql_query("SELECT * FROM berichten WHERE geaddresseerde = '" . $own['id'] . "' AND inbox = 'True'");
$paginas = floor((mysql_num_rows($users)-1)/($perpagina));
if($paginas >= 0) {
if($_GET['page'] > 0) {
echo"<a href=index.php?p=messages&page=" . ($_GET['page'] - 1) . ">« Vorige</a>";
} else {
echo"« Vorige";
}
for($i=0;$i <= $paginas;$i++) {
if($_GET['page'] == $i) {echo' | <b style="text-decoration: underline">';echo $i+1 .'</b>';} else {echo' | <a href="index.php?p=messages&page='. $i .'">'; echo $i+1 .'</a>';}
}
if($_GET['page'] < $paginas) {
echo" | <a href=index.php?p=messages&page=";
echo $_GET['page']+1 . ">Volgende »</a>";
}
else {
echo" | Volgende »";
}
}
echo"</center>"; }
?>
Bedankt!
Dus maak een query die daar de berichten ophaalt.
Overigens mis ik ook foutafhandeling op je query.
if(mysql_num_rows($result)>1)
moet je veranderen in
if(mysql_num_rows($result)>=1)
Als je dat niet doet en er is slechts 1 resultaat, dan word deze niet meegenomen.
Code (php)
1
2
3
4
5
6
7
8
9
10
11
12
2
3
4
5
6
7
8
9
10
11
12
<?php
if(mysql_num_rows($result) != 0){
//Resultaat is ongelijk aan 0 dus er zijn resultaten
}
else {
//Er is geen resultaat
}
?>
if(mysql_num_rows($result) != 0){
//Resultaat is ongelijk aan 0 dus er zijn resultaten
}
else {
//Er is geen resultaat
}
?>