Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need help to display 10 each column 1

Status
Not open for further replies.

indiantown

Technical User
Apr 29, 2005
25
US
<?

//Now grab a section of that
$db->open(

"SELECT songlist.title, songlist.id, songlist.count_played, songlist.filename, songlist.artist, songlist.album, songlist.duration FROM songlist, category, categorylist WHERE category.name = 'Top 10' AND songlist.id = categorylist.songID AND category.id = categorylist.categoryID ORDER BY songlist.count_played DESC, songlist.date_played ASC LIMIT 20");

$first = $start+1;
$last = min($cnt,$start+$limit);
$rc = $start;



function PutSongRow($song)
{
global $rc, $start, $darkrow, $lightrow;

$rc++;
$bgcolor = $darkrow;
if(($rc % 2)==0) $bgcolor = $lightrow;


PrepareSong($song);
?>

<font size="2" color="#003366"><small><? echo "$rc"; ?>.
<a href="javascript:songinfo(<? echo $song["songid"]; ?>)"><? echo $song["artist"]; ?></a></small></font> <br>
<font size="2" color="#003366"><small>&nbsp;&nbsp;&nbsp;&nbsp;<? echo $song["title"]; ?></small></font><br>



<?
}//PutSongRow

/* ## ===================================================================== ## */
?>


<table width="100%" bgcolor="<? echo $lightrow; ?>" border="0" cellspacing="0" cellpadding="5">
<tr bgcolor="<? echo $darkrow; ?>"><td height="14" colspan="2" class="rightbanner" nowrap>&nbsp;&nbsp;Top 10 Countdown</td></tr>
<tr><td nowrap>

<?
while($song = $db->row())
PutSongRow($song);
?>

</table>


Hi All,

The above script is what I am using to display songs. At present all 20 show alphabetically in the format

1
2
3
4
/
/
/
/
/
/
20

But I want to display in the format


1 11
2 12
/
/
/
10 20

Please help me I am not able to make it happen.

TIA.
 
here is some code for three column presentation

Code:
<?
//show stores first
error_reporting(E_ALL);
mysql_connect("localhost", "root", "root") or die(mysql_error());;
mysql_select_db("test") or die(mysql_error());

$query = "
		select  
			store_title, 
			store_link  
		from 
			store_name  
		order by 
			store_title ASC";

$result = mysql_query($query) or die(mysql_error());


//we add this line because we need to know the number of rows
# $num_rows = mysql_num_rows($result); //YOU DONT NEED THIS


//this section stores all the rows into an array
$start_letter = "";
$cnt = 1;
$table = "<table border=\"1\">";
while ($row  = mysql_fetch_assoc($result)):
	$link = "<a href=\"".$row['store_link']."\">".$row['store_title']."</a>";
	$first_letter = strtoupper(substr($row['store_title'],0,1));
	$ord = ord($first_letter);
	if (
			($start_letter != $first_letter) //change in start letter
			&& 
			(
				($ord<91) 
				&& 
				($ord>64)
			)
		):
		//we know that there has been a change in letter and not a number 
		//newline
		
			switch ($cnt):
				case 2:
					$table .= "<td>&nbsp;</td><td>&nbsp;</td></tr>";
				break;
				case 3;
					$table .= "<td>&nbsp;</td></tr>";
				break;	
			endswitch;
			$start_letter = $first_letter;
			
			$table .= "<tr><td colspan=\"3\">&nbsp;</td></tr>"; //blank line
			$table .= "<tr><td colspan=\"3\">Letter: $start_letter.</td></tr>"; //letter heading
			$table .= "<tr><td>$link</td>";  
			$cnt = 2;	//reset the counter
			
	else:
		//need to know whether this is even
		switch ($cnt):
			case 1:
			$table .= "<tr><td>$link</td>";  			
			break;
			case 2:
			$table .= "<td>$link</td>";  
			break;
			case 3:
			$table .= "<td>$link</td></tr>";  		
			break;
		endswitch;
		if ($cnt === 3):
			$cnt = 1;
		else:
			$cnt++;
		endif;


	endif;
	
endwhile;
//check for a trailing column
switch ($cnt):
		case 2:
		$table .= "<td>&nbsp;</td>";  
		break;
		case 3:
		$table .= "<td>&nbsp;</td><td>$link</td></tr>";  		
		break;
endswitch;

$table .= "</table>";
echo $table;
?>
 
Hi jpadie,

Thanks for all the help. Little glitch... at the end of the table its duplicating the last entry

Letter: Z.
Zdag.com Zearth.com Zinio
Zone labs Zones.com Zones.com

You can see that "Zones.com" is getting duplicated.

Please suggest.
 
sorry - copy and paste gone wrong.

in the final switch statement, case 3: change the $link for a &nbsp;
 
Hi jpadie,

I did

//check for a trailing column
switch ($cnt):
case 2:
$table .= "<td>&nbsp;</td>";
break;
case 3:
$table .= "<td>&nbsp;</td></tr>";
break;
endswitch;

removed "<td>$link</td>" altogether as otherwise its adding another block.

Is that OK?
 
it should be
Code:
switch ($cnt):
    case 2:
	$table .= "<td>&nbsp;</td><td>&nbsp;</td></tr>";       break;
    case 3:
        $table .= "<td>&nbsp;</td></tr>";  		
    break;
endswitch;
 
Hi jpadie...

Thanks for all the help and your time, no words to thank you.

I wanted to show you the final result but instead posting the link here, wanted to PM but it seems we don't have any PM options.

Now my next project for next couple of days is to grab the count of deals/coupons by each store and display.

Once again thanks for your time and all the help.

Regards
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top