[PHP/SQL]Count geeft rare uitslag

Pagina: 1
Acties:
  • 44 views sinds 30-01-2008

  • HyperioN
  • Registratie: April 2003
  • Laatst online: 24-05 20:06
Ik ben voor mezelf (ter educatie) een gastenboek aan het schrijven in php icm mysql.

nu wil ik het aantal berichten tellen:

code:
1
2
$aantalberichten = mysql_query("SELECT COUNT(*) FROM berichten");
echo $aantalberichten;


Nu zou deze dus gewoon het aantal berichten moeten weergeven, maar wat hij laat zien is:
code:
1
Resource id #3


echter, als ik exact dezelfde query uitvoer in phpMyAdmin doet hij het wel!

wat gaat hier mis?

[ Voor 3% gewijzigd door HyperioN op 29-02-2004 18:52 ]


Verwijderd

oeh, dit is wel erg basic
je moet je values eerst fetchen
PHP:
1
2
3
result = mysql_query("SELECT COUNT(*) FROM berichten");
list($count) = mysql_fetch_row($result);
print $count;

[ Voor 19% gewijzigd door Verwijderd op 29-02-2004 18:58 ]


  • igmar
  • Registratie: April 2000
  • Laatst online: 12-05 15:46

igmar

ISO20022

BvR-HyPeRiOn schreef op 29 februari 2004 @ 18:52:
nu wil ik het aantal berichten tellen:

code:
1
2
$aantalberichten = mysql_query("SELECT COUNT(*) FROM berichten");
echo $aantalberichten;


Nu zou deze dus gewoon het aantal berichten moeten weergeven, maar wat hij laat zien is:
code:
1
Resource id #3


echter, als ik exact dezelfde query uitvoer in phpMyAdmin doet hij het wel!

wat gaat hier mis?
Dat je geen manuals leest :

'
Description

resource mysql_query ( string query [, resource link_identifier])
'

Daar staat 'resource'. Een stukje verderop staat :

'
Only for SELECT,SHOW,DESCRIBE or EXPLAIN statements, mysql_query() returns a new result identifier that you can pass to mysql_fetch_array() and other functions dealing with result tables. When you are done with the result set, you can free the resources associated with it by calling mysql_free_result(). Although, the memory will automatically be freed at the end of the script's execution.
'

MAW : mysql_query() voert alleen de query uit, het uiteindelijke resultaat moet je met een andere functie ophalen.

  • .oisyn
  • Registratie: September 2000
  • Laatst online: 01:00

.oisyn

Moderator Devschuur®

Demotivational Speaker

Zie igmar, je hebt echt totaal geen moeite gedaan

Give a man a game and he'll have fun for a day. Teach a man to make games and he'll never have fun again.


Dit topic is gesloten.