Mysql in php ophalen

Gestart doorRiick16 reacties47 weergaven

17 berichten · pagina 1 van 2

Riick

Lid · Topicstarter

Berichten
3.425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Hallo,
Ik wil graag op mijn site weergeven: er zijn (AANTAL LEDEN) voor gegaan.
Dus een soort leden teller zeg maar, hoe moet ik dit doen?

Het komt neer op een php code die de tabel users telt uit me database...
0
Berichten
4.912
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
$users = mysql_query("select * from leden");
$ echo = mysql_num_rows($users);

echo $echo;


zoiets
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Query:

SELECT count(lidId) as AantalUsers FROM leden

Even fetchen en je bent klaar wink
0
Riick

Lid · Topicstarter

Berichten
3.425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Huh, nu snap ik het even niet... wat is het nou?
0
Berichten
6.485
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
het kan allebei. Bij die van Alemaaltje haal je de hele tabel op, wat dus absoluut niet tactisch is. Bij Rik tel (count) je het aantal leden.

Je moet dus gewoon die van Rik gebruiken.

$query = mysql_query("SELECT count(lidId) as AantalUsers FROM leden");
$fetch = mysql_fetch_assoc($query);

echo $fetch["AantalUsers"];
0
Erik

Lid

Berichten
7.109
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Je hebt PHP niet geopend? emo
0
Berichten
15.446
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 count(lidId) as AantalUsers FROM leden"[/COLOR][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]"AantalUsers"[/COLOR][COLOR= #007700]];[/COLOR]
?>


zo dus even doen smile
0
Riick

Lid · Topicstarter

Berichten
3.425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Nu heb ik een complete error confused
0
Rik

Lid

Berichten
18.393
Reputatie
0
Punten
0,04
Lid sinds
Laatst gezien
Je hebt nog geen connectie met de database gemaakt.
0
Berichten
5.795
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
[COLOR= #0000BB]<?php
$server[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]localhost[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// mysql server/host[/COLOR]
[COLOR= #0000BB]$user[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// mysql gebruikersnaam[/COLOR]
[COLOR= #0000BB]$pass[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// mysql wachtwoord[/COLOR]
[COLOR= #0000BB]$database[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// mysql database[/COLOR]

[URL="http://www.php.net/mysql_connect"]mysql_connect[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$server[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$user[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$pass[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$database[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #0000BB]$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT count(lidId) as AantalUsers FROM leden"[/COLOR][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]"AantalUsers"[/COLOR][COLOR= #007700]];[/COLOR]
?>


dan moet je even boven aan de 4 vars invullen
0
Berichten
3.461
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Misschien eerst een php lesje volgen, @TS...
0
Berichten
5.957
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Rogier schreef:
het kan allebei. Bij die van Alemaaltje haal je de hele tabel op, wat dus absoluut niet tactisch is. Bij Rik tel (count) je het aantal leden.

Je moet dus gewoon die van Rik gebruiken.
$query = mysql_query("SELECT count(lidId) as AantalUsers FROM leden");
$fetch = mysql_fetch_assoc($query);

echo $fetch["AantalUsers"];


Ten eerste iss het alemaalTe ten tweede was het in dit geval smiegels emo
0
Riick

Lid · Topicstarter

Berichten
3.425
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Ik ga geen php leren voor zo iets kleins, en ik snap er nou helemaal geen ruk meer van...
0
Berichten
3.461
Reputatie
0
Punten
0,00
Lid sinds
Laatst gezien
Zoals Daiman al zei:

[COLOR= #0000BB]<?php
$server[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000]localhost[/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// mysql server/host[/COLOR]
[COLOR= #0000BB]$user[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// mysql gebruikersnaam[/COLOR]
[COLOR= #0000BB]$pass[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// mysql wachtwoord[/COLOR]
[COLOR= #0000BB]$database[/COLOR] [COLOR= #007700]=[/COLOR] [COLOR= #DD0000][/COLOR][COLOR= #007700];[/COLOR] [COLOR= #FF8000]// mysql database[/COLOR]

[URL="http://www.php.net/mysql_connect"]mysql_connect[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$server[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$user[/COLOR][COLOR= #007700],[/COLOR][COLOR= #0000BB]$pass[/COLOR][COLOR= #007700]);[/COLOR]
[URL="http://www.php.net/mysql_select_db"]mysql_select_db[/URL][COLOR= #007700]([/COLOR][COLOR= #0000BB]$database[/COLOR][COLOR= #007700]);[/COLOR]

[COLOR= #0000BB]$query[/COLOR] [COLOR= #007700]=[/COLOR] [URL="http://www.php.net/mysql_query"]mysql_query[/URL][COLOR= #007700]([/COLOR][COLOR= #DD0000]"SELECT count(lidId) as AantalUsers FROM leden"[/COLOR][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]"AantalUsers"[/COLOR][COLOR= #007700]];[/COLOR]
?>


En bij de bovenste 4 variabelen even je gegevens van je database invullen. smile
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