<? $result1 = mysql_query("SELECT COUNT(*) FROM users"); ?> <table border=0 class=middle> <tr> <td> Wir wir haben <b> <? echo $result1; ?> </b> Mitglieder. </td> </tr> </table>
![](https://forum.falloutstudios.org/public/style_images/master/icon_users.png)
![](https://forum.falloutstudios.org/public/style_images/master/profile/default_large.png)
[MySQL] "SELECT COUNT()"
Started By Sgt. Rho, Mar 07 2008 10:06
5 replies to this topic
#1
Posted 07 March 2008 - 10:06
I got a problem with that function. It either says "1", "10", or "Resource ID#2"....
#2
Posted 07 March 2008 - 11:54
That's because mysql_query doesn't return the results directly, but rather returns a 'resource' that you need to use for subsequent functions that access the data.
$result = mysql_query('whatever', $connection);
$array = mysql_fetch_assoc($result)
Returns one row of the result, as an associative array, with $array['column name'] = 'value';
$array = mysql_fetch_row($result)
Returns one row of the result, as a numeric array, with indexes ordered like the SELECT query. I.e. the first column in the SELECT is index 0, second is index 1, etc.
$result = mysql_query('whatever', $connection);
$array = mysql_fetch_assoc($result)
Returns one row of the result, as an associative array, with $array['column name'] = 'value';
$array = mysql_fetch_row($result)
Returns one row of the result, as a numeric array, with indexes ordered like the SELECT query. I.e. the first column in the SELECT is index 0, second is index 1, etc.
CodeCat
![Posted Image](http://i63.photobucket.com/albums/h129/codecat42/userbars/openmoddingalliance_logo.png)
![Posted Image](http://i136.photobucket.com/albums/q168/thedrofevil/1000Editscopy.png)
Go dtiomsaítear do chód gan earráidí, is go gcríochnaítear do chláir go réidh. -Old Irish proverb
![Posted Image](http://i63.photobucket.com/albums/h129/codecat42/userbars/openmoddingalliance_logo.png)
![Posted Image](http://i136.photobucket.com/albums/q168/thedrofevil/1000Editscopy.png)
Go dtiomsaítear do chód gan earráidí, is go gcríochnaítear do chláir go réidh. -Old Irish proverb
#3
Posted 07 March 2008 - 19:11
So I'd need to change it to this?:
<? $result1 = mysql_query("SELECT * FROM users"); $nousers = mysql_fetch_assoc($result1['ID']); ?> <table border=0 class=middle> <tr> <td> Wir wir haben <b> <? echo $nousers; ?> </b> Mitglieder. </td> </tr> </table>
Edited by Master_Chief, 07 March 2008 - 19:12.
#6
Posted 08 March 2008 - 23:08
$make = $_GET['make']; if ($make == "upgroups") { $Name = $_POST['Name']; $ID = $_POST['ID']; echo $Name."<br>".$ID; include('inc/acces.inc.php'); mysql_connect($sqlserv, $sqluser, $sqlpass); mysql_select_db("usr_web23_3"); $sql = "UPDATE groups SET Name='$Name' WHERE 'GID' = '$ID'"; if (mysql_query($sql)) { echo "geht"; } else { echo "geht nicht" . mysql_error() . "<br>"; }
I got another problem...this script won't work
![:P](http://forum.falloutstudios.org/public/style_emoticons/default/worried.gif)
EDIT: It misteriously works suddenly O.o
Edited by Master_Chief, 09 March 2008 - 10:53.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users