Jump to content

Getting Rownumbers to show


JKing

Recommended Posts

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>";

}

 

?>

Link to comment
Share on other sites

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
}

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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;

 

}

 

?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.