Hi there, I've tried googling this, but I'm not sure what to search for... What I have is a table that holds gig dates for my band. I have it to where it only shows for the year I want to look at. What I want is when I display a certain year (2008 for example) I want to have the entries numbered so I can just see how many there are total. I have the code to just give me a row count, but can't seem to get each entry numbered like this: 1. Lucky Lounge - 8/9/2008 2. Bob's Place - 8/15/2008 3. And so on... Can you help me with this? Thanks!
if you are doign a while() loop through the entries, do this. $i = 1; while(getrow) { //print your data, including $i $i++; }
alternatively you can use ordered list tag <ol> <li>First data</li> <li>Second data</li> <li>Third data</li> </ol> HTML:
Thank you for the help. Can you tell me how that would fit into what I already have? <? $hostname = "localhost"; $username = "****"; $password = "****"; $usertable = "****"; $database = "****"; $todate = date("Y-m-d"); $year = date("Y"); MYSQL_CONNECT($hostname, $username, $password) OR DIE("DB connection unavailable"); @mysql_select_db( "$database") or die( "Unable to select database"); $query="SELECT * FROM $usertable WHERE date < '$todate' AND year='$year' ORDER BY date DESC"; $result=mysql_query($query) or die(mysql_error()); if (mysql_num_rows($result) == 0) { echo "<div class=\"text\" align=\"center\"><b>That year was not found</b></div>"; } else { while ($row = mysql_fetch_assoc($result)) { echo "<table width=\"345\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td width=\"100%\"><span class=\"bigtext\"\"><i><b>" . $row['day'] . "</b> - <b>" . $row['disp_date'] . " @ " . $row['timestart'] . " " . $row['ampm'] . "</b></i></span></td> </tr> </table></td> </tr> <tr> <td class=\"text\">" . $row['location'] . "<br> <div class=\"text\">Paid: $" . $row['paid'] . "</div></td> </tr> </table><center><hr size=\"1\" color=\"white\"></center>"; } } ?> PHP:
$i = 0; while ($row = mysql_fetch_assoc($result)) { echo "<table width=\"345\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td><table width=\"100%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\"> <tr> <td width=\"100%\"><span class=\"bigtext\"\"><i><b>{$i} " . $row['day'] . "</b> - <b>" . $row['disp_date'] . " @ " . $row['timestart'] . " " . $row['ampm'] . "</b></i></span></td> </tr> </table></td> </tr> <tr> <td class=\"text\">" . $row['location'] . "<br> <div class=\"text\">Paid: $" . $row['paid'] . "</div></td> </tr> </table><center><hr size=\"1\" color=\"white\"></center>"; $i++; } } PHP:
For further design, you can change the background of TD tags while its number ($i) is even or odd. function is_even($i){ // calculate $i here // if $i = even, return TRUE } if(is_even($i)=TRUE){ // print background-color = red else { //print background-color = blue, for example } Code (markup):