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
https://forums.phpfreaks.com/topic/249410-getting-rownumbers-to-show/
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
}

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.

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;

 

}

 

?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.