Welcome to WebmasterWorld Guest from 3.80.60.248

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

Count a multi-dimensional array

     
9:17 am on Jul 25, 2011 (gmt 0)

New User

5+ Year Member

joined:July 25, 2011
posts: 4
votes: 0


I am using this query to display available artwork.

$query = "SELECT * FROM artwork WHERE status = 'available' ORDER BY associated DESC";
$result = mysql_query($query);

In this table there is also a variable called $artistId which is not set. I would like to get a count
on all the available artworks done by specific artists. How would I go about getting these numbers for
all artists?

Thanks in advance,

Lindsay
10:27 am on July 25, 2011 (gmt 0)

Junior Member from IN 

10+ Year Member

joined:Nov 3, 2002
posts: 91
votes: 0


I'm just typing off the top of my head but you should get the idea

Do you want something like

SELECT COUNT(*) from artwork GROUP BY artistId
9:43 pm on July 25, 2011 (gmt 0)

New User

5+ Year Member

joined:July 25, 2011
posts: 4
votes: 0


Hi Chris,

How would you grab the counts for each artist?

I did this but it isn't working.

$query = "SELECT COUNT(*) from artwork GROUP BY artistId";
$result = mysql_query($query);

echo $result;

Thanks.
5:40 am on July 26, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month

joined:Oct 15, 2004
posts:942
votes: 0


Try this:

$query = "SELECT artistId, COUNT(artistId) as artictCount From artwork GROUP BY artistId";
$result = mysql_query($query);
$row = mysql_fetch_array($result);
echo 'Artist with id '.$row['artistId'].' has '.$row['artictCount'].' records';
10:38 pm on July 26, 2011 (gmt 0)

New User

5+ Year Member

joined:July 25, 2011
posts: 4
votes: 0


Amazing Omoutop!

Just what I needed... I put the echo in a while loop and now am grabbing the amount of piece available per artists!

$query3 = "SELECT *, COUNT(artistId) as artistCount FROM artwork WHERE status = 'available' GROUP BY artistId";
$result3 = mysql_query($query3);

while($row = mysql_fetch_array($result3)) {

echo $row['firstName'].'&nbsp;'.$row['lastName'].'#'.$row['artistCount'].'<br />';

}

Now I am trying to get each artworks # out of the total number. Can I get find this from the current query or would I have to write a new one?

Thanks!

Lindsay
11:11 pm on Aug 26, 2011 (gmt 0)

New User

5+ Year Member

joined:July 25, 2011
posts: 4
votes: 0


Hi! I need to write a query that gets the # of the art piece that is associated with a specific artist in a database. The query above tells me how many available pieces each artist has in the database but I need to be able to get the number of the piece in the list of artists work.

Any thoughts?
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members