Leden aantal

Gestart doorSanderc16 reacties30 weergaven

17 berichten · pagina 1 van 2

Sanderc

Lid · Topicstarter

Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Wat was dat script nu weer dat weergeeft hoeveel leden je site heeft?

Bedankt
0
Berichten
9.953
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT id FROM leden"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700]);[/COLOR]
?>


Zoiets...? emo
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
of:

[COLOR= #0000BB]<?php
$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT count(id) AS q FROM leden"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
[COLOR= #0000BB]$fetch[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]q[/COLOR][COLOR= #007700]];[/COLOR]
?>
0
Sanderc

Lid · Topicstarter

Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
En als je alle leden wilt zien?
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM leden"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$fetch[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700])) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$fetch[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]naam[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];
}[/COLOR]
?>
0
Berichten
5.897
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Xjessex schreef:
[COLOR= #0000BB]<?php
$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM leden"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$fetch[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700])) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]naam[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];
}[/COLOR]
?>
Moet daar niet $fetch staan ipv $row ?
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Sebastiaanh schreef:
[COLOR= #0000BB]<?php
$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT id FROM leden"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700]);[/COLOR]
?>
Zoiets...? emo
Dus als je alle boeken uit je kast wilt tellen, dan haal je die er eerst uit, stapel je ze op elkaar, en gaat ze dan tellen? (de mysql_num_rows-manier)

Beter is door het direct in MySQL te doen:

SELECT COUNT(1) AS aantal FROM leden


Hierbij tel je ze lopend terwijl je met je vinger over de kaften heen gaat, wat veel efficiënter is.

Het is niet aan te raden om hiervoor een array te gebruiken (mysql_fetch_assoc/-array), gezien je het beste direct het resultaat op kan halen met mysql_result($result,0,0).
0
Berichten
93.699
Reputatie
0
Punten
1,27
Lid sinds
Laatst gezien
Maartenl schreef:
Eerdere citaten tonen
Xjessex schreef:
[COLOR= #0000BB]<?php
$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT * FROM leden"[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/while"]while[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$fetch[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_fetch_assoc"]mysql_fetch_assoc[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700])) {[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [COLOR= #0000BB]$row[/COLOR][COLOR= #007700][[/COLOR][COLOR= #DD0000]naam[/COLOR][COLOR= #007700]] .[/COLOR] [COLOR= #DD0000]<br />[/COLOR][COLOR= #007700];
}[/COLOR]
?>
Moet daar niet $fetch staan ipv $row ?

Ja sorry, foutje emo
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Aarclay schreef:
Eerdere citaten tonen
Sebastiaanh schreef:
[COLOR= #0000BB]<?php
$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT id FROM leden"[/COLOR][COLOR= #007700])[/COLOR] or [URL="http://www.php.net/die"]die[/URL][COLOR= #007700]([/COLOR][URL="http://www.php.net/mysql_error"]mysql_error[/URL][COLOR= #007700]());[/COLOR]
[URL="http://www.php.net/echo"]echo[/URL] [URL="http://www.php.net/mysql_num_rows"]mysql_num_rows[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$query[/COLOR][COLOR= #007700]);[/COLOR]
?>
Zoiets...? emo
Dus als je alle boeken uit je kast wilt tellen, dan haal je die er eerst uit, stapel je ze op elkaar, en gaat ze dan tellen? (de mysql_num_rows-manier)

Beter is door het direct in MySQL te doen:

SELECT COUNT(*) AS aantal FROM leden


Hierbij tel je ze lopend terwijl je met je vinger over de kaften heen gaat, wat veel efficiënter is.

Het is niet aan te raden om hiervoor een array te gebruiken (mysql_fetch_assoc/-array), gezien je het beste direct het resultaat op kan halen met mysql_result($result,0,0).

Je moet eigenlijk zo min mogelijk gebruik maken van " * ". Ik weet niet in hoeverre je met count() alles gaat ophalen, maar over het algemeen staat " * " voor "alles". Je kan dan beter count(1) doen.
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Kijk hier eensL:
http://www.pfz.nl/forum/topic/6902-select-countiets-vs-mysql-num-rows-wat-is-beter/page__view__findpost__p__48027?s=c3f4d609ac7a98fb4ea45d5a8a109bcc

Kan je nagaan hoeveel sneller COUNT() is..
mysql_num_rows() dus nooit gebruiken voor grote aantallen.

toevoeging op 26 februari 2012, 19:40:22:
Rik schreef:
Je moet eigenlijk zo min mogelijk gebruik maken van " * ". Ik weet niet in hoeverre je met count() alles gaat ophalen, maar over het algemeen staat " * " voor "alles". Je kan dan beter count(1) doen.
true...
0
Sanderc

Lid · Topicstarter

Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Het werkt niet, dat van alle leden te zien:

http://radiofock.nl/

Log maar even in met:

Username: Test
Password: Test

(Hoofdlettergevoelig wink)
Van de rest als je bent ingelogd moet je jou niets van aantrekken, ik ben er aan het werken, maar als je vanonder ziet, werkt het aantal leden wel, maar dat van alle leden zien niet confused?
0
Berichten
3.112
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Waarschijnlijk heeft het veld met de naam niet Naam in de database emo
0
Sanderc

Lid · Topicstarter

Berichten
11.263
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Aaah jah bedankt Gamedealer, het noemde username xd smile Vergeten aan te passen. Dat werkt nu wink Nu nog een klein foutje bij registreren sadley Maarjah
0
Thom

Lid

Berichten
10.654
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Wat is je fout bij het registreren? wink
0
Berichten
10.421
Reputatie
4
Punten
0,00
Lid sinds
Laatst gezien
Welke manier gebruik je nou? COUNT() hypocrite?
0

Jouw reactie

Deel je idee, stel een vraag of help een ander verder.

Editor laden…

Praat mee met de One2xs-community.

Inloggen om te reageren