JKing Posted October 19, 2011 Share Posted October 19, 2011 Hello We have a php call to create a Top 100 release list and we've got the artists and CD title showing but want to add Numbers next to each (like a normal chart). We've tried a few things but just can't get it yet. I'm wondering if someone could take a quick look and let me know if there's a call I need to include within the backend and "echo"? Thanks for any help you can provide. Jess _____________________________________ REQUIRE CODE $arrIndex = 0; while ( $row = mysql_fetch_array( $rs ) ) { $cdId = $row["cdId"]; //$obj2->query( "SELECT digicd.title as cdtitle, tg.shortcode, tg.title as genretitle FROM digicd, digicdgenre cg, tbl_Genre tg where digicd.id=cg.cdId and cg.name=tg.shortcode and cg.cdid=".$cdId ); $rs2 = mysql_query( "SELECT rownum, digicd.title, ab.BandName FROM digicd, artistBand ab where digicd.bandId=ab.id and digicd.id=".$cdId ); while ( $row2 = mysql_fetch_array( $rs2 ) ) { $cdTitle = $row2["title"]; $bandName = $row2["BandName"]; $arrDigiTop[$arrIndex][0] = $cdId; $arrDigiTop[$arrIndex][1] = $cdTitle; $arrDigiTop[$arrIndex][2] = $bandName; $arrIndex++; } } //print_r($arrDigiTop); return $arrDigiTop; ___________________________________________________________________ PHP PAGE ON THE WEBSITE (View it http://www.radiodirectx.com/TopDigi.php) <? $topDigiCount = 100; $arrDigiTop = getGlobalDigiChartTop ( $topDigiCount ); for ( $i = 0; $i < sizeof($arrDigiTop) ; $i++ ) { echo "<TR>"; echo "<TD> <FONT face=Verdana, Arial, Helvetica, sans-serif size=1> <IMG height=8 alt=GO! src='images/arrow_right.gif' width=8 border=0></FONT> <a href='/radio/front_end/media/DigiCDDetails.php?id={$arrDigiTop[$i][0]}'>{$arrDigiTop[$i][2]} - {$arrDigiTop[$i][1]}</a></font> </TD>"; echo "</TR>"; } ?> Quote Link to comment Share on other sites More sharing options...
msaz87 Posted October 19, 2011 Share Posted October 19, 2011 Well a simple thing to do would just add something like this to your loop: $num = 1; // define what number you want the list to start at // loop begins while ( $row = mysql_fetch_array( $rs ) ) { echo $num."<br/>"; $num++; // number increments by 1 each time loop repeats } Quote Link to comment Share on other sites More sharing options...
requinix Posted October 19, 2011 Share Posted October 19, 2011 You have $i right there in the loop. Use $i+1 as your number. Quote Link to comment Share on other sites More sharing options...
JKing Posted October 19, 2011 Author Share Posted October 19, 2011 Thanks for the reply and help. I'm really green so I have to ask - where would I place the loop info you posted? THX J Quote Link to comment Share on other sites More sharing options...
Psycho Posted October 19, 2011 Share Posted October 19, 2011 You should NEVER run queries in loops!!! As to your last question. As requinix stated you have a value $i which goes from 0 to 99, so just use $i + 1 and display next to each record. But, you should really modify that code so you are not running queries in a loop. I'll take a look and see if I can provide you something. EDIT: Where is the query that provides the first result set $rs? EDIT #2: Font tags? Really? Those have been deprecated for years. Quote Link to comment Share on other sites More sharing options...
JKing Posted October 19, 2011 Author Share Posted October 19, 2011 Thanks mjdamato, requinix & msaz87for your info and help! re: font tags - it's old code - from about 2005. Here is the full code: http://www.radiodirectx.com/TopDigi.php This is the require code - <?php function getGlobalDigiChartTop ( $topCount = 10 ) { $arrDigiTop = array(); $rs = mysql_query( "select cs.cdId, count(*) as dcount from digisongcounter sc, digicdsample cs where sc.songId = cs.id group by cs.cdId order by dcount desc limit 0,".$topCount ); /* For every CD, get list of Cd Genre */ $arrIndex = 0; while ( $row = mysql_fetch_array( $rs ) ) { $cdId = $row["cdId"]; //$obj2->query( "SELECT digicd.title as cdtitle, tg.shortcode, tg.title as genretitle FROM digicd, digicdgenre cg, tbl_Genre tg where digicd.id=cg.cdId and cg.name=tg.shortcode and cg.cdid=".$cdId ); $rs2 = mysql_query( "SELECT digicd.title, ab.BandName FROM digicd, artistBand ab where digicd.bandId=ab.id and digicd.id=".$cdId ); while ( $row2 = mysql_fetch_array( $rs2 ) ) { $cdTitle = $row2["title"]; $bandName = $row2["BandName"]; $arrDigiTop[$arrIndex][0] = $cdId; $arrDigiTop[$arrIndex][1] = $cdTitle; $arrDigiTop[$arrIndex][2] = $bandName; $arrIndex++; } } //print_r($arrDigiTop); return $arrDigiTop; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.