I have a database that tracks projects, a link to the document, if there are updates and (if there are) links to the updates. The information is actually in two tables: the first contains the information on the projects with a flag to say whether or not there are updates. The update table has all the information about the updates and a column to JOIN the two databases.
How do I count (to set up a loop) the number of updates for each project?
Thanks!
Counting the number of items in a MySQL database
Moderator: General Moderators
- superdezign
- DevNet Master
- Posts: 4135
- Joined: Sat Jan 20, 2007 11:06 pm
Code: Select all
SELECT COUNT(`updates`) FROM `updatesTable`Oh, if it were only that easy... perhaps it is and I am just a dope.
When I try to use COUNT ($update), all I get is 1.
Let me be more specific and see if that helps...
I have the "projreg" table with:
id | proj | url | up (a binary flag)
---+-------+------+-----
1 | ProjA | urlA | 0 (no)
2 | ProjB | urlB | 1 (yes)
3 | ProjC | urlC | 1 (yes)
and I have the "updates" table with:
id | id_proj | update | u_url , where "id_proj" is the link to the "projreg" table:
---+---------+-----------+---------------
1 | 2 | UpdB1 | UpdateURL1
2 | 3 | UpdC1 | UpdateURL2
3 | 3 | UpdC2 | UpdateURL3
4 | 3 | UpdC3 | UpdateURL4
So, Project B has one update and Project C has three updates.
If I put in a loop, I just get "1" returned.
What am I doing wrong?
When I try to use COUNT ($update), all I get is 1.
Let me be more specific and see if that helps...
I have the "projreg" table with:
id | proj | url | up (a binary flag)
---+-------+------+-----
1 | ProjA | urlA | 0 (no)
2 | ProjB | urlB | 1 (yes)
3 | ProjC | urlC | 1 (yes)
and I have the "updates" table with:
id | id_proj | update | u_url , where "id_proj" is the link to the "projreg" table:
---+---------+-----------+---------------
1 | 2 | UpdB1 | UpdateURL1
2 | 3 | UpdC1 | UpdateURL2
3 | 3 | UpdC2 | UpdateURL3
4 | 3 | UpdC3 | UpdateURL4
So, Project B has one update and Project C has three updates.
If I put
Code: Select all
$countup = count($id_proj);What am I doing wrong?
- RobertGonzalez
- Site Administrator
- Posts: 14293
- Joined: Tue Sep 09, 2003 6:04 pm
- Location: Fremont, CA, USA
You use the MySQL count function in the query, not the PHP count() function in the code.