Php mysql how to display the number of albums an artist has?
-
$dbQuery="select id, name from artists where name like '$keyword%' order by name asc limit 15"; $dbResult=mysql_query($dbQuery); echo mysql_num_rows($dbResult)."\n"; while ($dbRow=mysql_fetch_array($dbResult)) { // for each artist, return the number of albums belonging to that artist // use a separate query here to obtain the number // return the number after the artist's name in the echo statement, separated with a '^' (1b) echo $dbRow["id"]."^".$dbRow["name"]."\n"; Have this code and as you can see i have to write another dbquery that will display the number of albums an artist has. I also have to modify this piece of code function showArtists() { if (ajaxObject.readyState==4) { var artistsArray=ajaxObject.responseText.spl… var numArtists=artistsArray[0]; var htmlStr=""; for (var i=1; i<=numArtists; i++) { var artistDetails=artistsArray[i].split("^")… htmlStr+="<div onmouseover='javascript:suggestOver(this… "; htmlStr+="onmouseout='javascript:sugge… "; htmlStr+="onclick='javascript:setArtis… "; // add the number of albums in brackets after the artist's name in the next line (1b) htmlStr+="class='suggest_link'>" + artistDetails[1] + "</div> "; so that it will be displayed on the webpage. Anyone know how i do this, im new to php and mysql.
-
Answer:
you'll probably have to us a join with another table. but as you don't describe wihch tables you have, i can only guess... SELECT count(*) FROM artists ar JOIN albums al ON ar.id = al.artist_id; or something like that. however it would be way more efficient to include the album count in the first query. making a query, and then for each result issunig a new query is usually very bad design...
Laura at Yahoo! Answers Visit the source
Related Q & A:
- How To Build Business Directory Using Php Mysql?Best solution by Stack Overflow
- How to Display an Image in PDF, which is retrieved from MySql Database :JSP and iText?Best solution by Stack Overflow
- How can I make a living as an artist?Best solution by Yahoo! Answers
- How do I create multiple photo albums for my Ipod Touch?Best solution by Yahoo! Answers
- How do you go about becoming a tattoo artist?Best solution by Yahoo! Answers
Just Added Q & A:
- How many active mobile subscribers are there in China?Best solution by Quora
- How to find the right vacation?Best solution by bookit.com
- How To Make Your Own Primer?Best solution by thekrazycouponlady.com
- How do you get the domain & range?Best solution by ChaCha
- How do you open pop up blockers?Best solution by Yahoo! Answers
For every problem there is a solution! Proved by Solucija.
-
Got an issue and looking for advice?
-
Ask Solucija to search every corner of the Web for help.
-
Get workable solutions and helpful tips in a moment.
Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.