sql >> Databasteknik >  >> RDS >> Mysql

mysql räknas in i PHP-variabeln

Så här:

// Changed the query - there's no need for DISTINCT
// and aliased the count as "num"
$data = mysql_query('SELECT COUNT(`users_id`) AS num FROM `users_table`') or die(mysql_error());

// A COUNT query will always return 1 row
// (unless it fails, in which case we die above)
// Use fetch_assoc for a nice associative array - much easier to use
$row = mysql_fetch_assoc($data);

// Get the number of uses from the array
// 'num' is what we aliased the column as above
$numUsers = $row['num'];


  1. Hur man hämtar matchningsposter över flera tabeller i MySQL

  2. c3p0 hänger i väntan. Tillgänglig med viloläge

  3. PHP PDO Förberedd sats bind NULL-värde

  4. Vänd i Oracle denna väg z/y/x till x/y/z