Click here to Skip to main content
15,891,864 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
PHP
$result = mysql_query("SELECT titel, COUNT(titel) AS numbers FROM users WHERE accid = '$showid'") or die (mysql_error());
$row = mysql_fetch_array($result);
echo $row ['numbers'];


$showid is available.
I don´t get an error.
In the database are two entries.
But it always shows 0 *cunfused*
Posted

titel ?

This SQL should not run. If you're doing a count, you need a group by in order to select individual values, to.

SELECT titel, COUNT(titel) AS numbers FROM users WHERE accid = '$showid' group by titel

Also, I think this will look for $showid as a string in your database, are you sure that's what you want ? I think you want this value to look something up from the form, and I don't think it will, as it stands.
 
Share this answer
 
Comments
Chi Ller 10-Jan-13 17:03pm    
But now it shows nothing
Yes I need accid = '$showid' because different people can use it and for everyone I want to show only his entrys
Christian Graus 10-Jan-13 17:06pm    
I think that this will pass the string '$showid' to the SQL, and not pass through any sort of id.
Chi Ller 10-Jan-13 17:08pm    
ok you´re right. Without $showid it works. But now how can I just show the guy with the id 10 his number of entries?
Christian Graus 10-Jan-13 17:12pm    
I don't do PHP, but there has to be a way to look up that value, then pass it in to the SQL.
Chi Ller 10-Jan-13 17:14pm    
ok thank you (:
You either select an aggregate on it's own (select count(*) from table), or an aggregate based on some grouping (select field, count(*) from table group by field). Your query makes no real sense, since you can not select a row and an aggregate in the same query.
 
Share this answer
 
Comments
Chi Ller 10-Jan-13 17:01pm    
You mean this should work:
$result = mysql_query("SELECT COUNT(*) AS numbers FROM users WHERE accid = '$showid'") or die (mysql_error());
$row = mysql_fetch_array($result);
echo $row ['numbers'];
Zoltán Zörgő 10-Jan-13 17:02pm    
Is should.
Chi Ller 10-Jan-13 17:04pm    
But the number is also 0 instead of 2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900