RyanMinor Posted June 23, 2010 Share Posted June 23, 2010 I am trying to automatically number the rows returned from a recordset. The recordset is displaying in a repeat region. I want the numbering to start at 1. I have looked around online and found some code, but my page is just displaying the last record for every row (there are 48 rows in the DB, so each row is numbered 48). Here is what I have so far: <?php include ('restrict.php' ); ?> <?php require_once('../Connections/conndb.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $SSAdv_colors1 = array("#CCCCCC","#FFFFFF"); $SSAdv_k1 = 0; $SSAdv_m1 = 0; $SSAdv_change_every1 = 1; mysql_select_db($database_conndb, $conndb); $query_rsadmin = "SELECT id, firstname, lastname, address, city, `state`, zip, phone, email, organization, insertdate FROM TrioGrants ORDER BY insertdate DESC"; $rsadmin = mysql_query($query_rsadmin, $conndb) or die(mysql_error()); $row_rsadmin = mysql_fetch_assoc($rsadmin); $totalRows_rsadmin = mysql_num_rows($rsadmin); ?><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>TRIO Grants</title> <style type="text/css"> <!-- .style4 {color: #FFFFFF; font-weight: bold; } --> </style> </head> <body> <table width="720" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><a href="index.php"><img src="../images/sss.banner.gif" width="720" height="74" border="0" /></a></td> </tr> <tr> <td><div align="center"><strong>Administrator Page</strong><br /> </div> </table> <br /> <table width="70%" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td width="50%"><div align="left">Washington, DC Registration Report<br /> as of <?php echo date("F j, Y, g:i a"); ?> (<a href="excel.php">Generate Report</a>)</div></td> <td width="50%"><div align="right">Total Number of Registrants: <?php echo $totalRows_rsadmin ?> </div></td> </tr> <tr> <td colspan="2"><table width="100%" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td bgcolor="#000000" class="style4">#</td> <td bgcolor="#000000"><span class="style4">Name</span></td> <td bgcolor="#000000"><span class="style4">Organization</span></td> <td bgcolor="#000000"><span class="style4">City</span></td> <td bgcolor="#000000"><span class="style4">State</span></td> </tr> <?php do { ?> <?php for ($i = 0; $i<$totalRows_rsadmin; $i++) { $number = $i+1; } ?> <tr bgcolor="<?php if($SSAdv_m1%$SSAdv_change_every1==0 && $SSAdv_m1>0){ $SSAdv_k1++; } print $SSAdv_colors1[$SSAdv_k1%count($SSAdv_colors1)]; $SSAdv_m1++; ?>"> <td><?php echo $number ?></td> <td><a href="detail.php?id=<?php echo $row_rsadmin['id']; ?>"><?php echo stripslashes($row_rsadmin['firstname']); ?> <?php echo stripslashes($row_rsadmin['lastname']); ?></a></td> <td><?php echo stripslashes($row_rsadmin['organization']); ?></td> <td><?php echo $row_rsadmin['city']; ?></td> <td><?php echo $row_rsadmin['state']; ?></td> </tr> <?php } while ($row_rsadmin = mysql_fetch_assoc($rsadmin)); ?> </table></td> </tr> <tr> <td colspan="2"> </td> </tr> </table> </body> </html> <?php mysql_free_result($rsadmin); ?> Quote Link to comment https://forums.phpfreaks.com/topic/205670-automatically-numbering-rows-with-repeat-region/ Share on other sites More sharing options...
Psycho Posted June 23, 2010 Share Posted June 23, 2010 <?php include ('restrict.php' ); ?> <?php require_once('../Connections/conndb.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue; $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue); switch ($theType) { case "text": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "long": case "int": $theValue = ($theValue != "") ? intval($theValue) : "NULL"; break; case "double": $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL"; break; case "date": $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL"; break; case "defined": $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue; break; } return $theValue; } } $SSAdv_colors1 = array("#CCCCCC","#FFFFFF"); mysql_select_db($database_conndb, $conndb); $query_rsadmin = "SELECT id, firstname, lastname, address, city, `state`, zip, phone, email, organization, insertdate FROM TrioGrants ORDER BY insertdate DESC"; $rsadmin = mysql_query($query_rsadmin, $conndb) or die(mysql_error()); $row_rsadmin = mysql_fetch_assoc($rsadmin); $totalRows_rsadmin = mysql_num_rows($rsadmin); $output = ''; $rowCount = 0; while ($row_rsadmin = mysql_fetch_assoc($rsadmin)) { $rowCount++; $bgcolor = $SSAdv_colors1[($rowCount%count($SSAdv_colors1))]; $firstname = stripslashes($row_rsadmin['firstname']); $lastName = stripslashes($row_rsadmin['lastname']); $organization = stripslashes($row_rsadmin['organization']); $output .= "<tr bgcolor=\"{$bgcolor}\">\n"; $output .= "<td>{$row}</td>\n"; $output .= "<td><a href=\"detail.php?id={$row_rsadmin['id']}\">{$firstname} {$lastName}</a></td>\n"; $output .= "<td>{$organization}</td>\n"; $output .= "<td>{$row_rsadmin['city']}</td>\n"; $output .= "<td>{$row_rsadmin['state']}</td>\n"; $output .= "</tr>\n"; } mysql_free_result($rsadmin); $currentDate = date("F j, Y, g:i a"); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>TRIO Grants</title> <style type="text/css"> <!-- .style4 {color: #FFFFFF; font-weight: bold; } --> </style> </head> <body> <table width="720" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><a href="index.php"><img src="../images/sss.banner.gif" width="720" height="74" border="0" /></a></td> </tr> <tr> <td><div align="center"><strong>Administrator Page</strong><br /> </div> </table> <br /> <table width="70%" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td width="50%"><div align="left">Washington, DC Registration Report<br /> as of <?php echo $currentDate; ?> (<a href="excel.php">Generate Report</a>)</div></td> <td width="50%"><div align="right">Total Number of Registrants: <?php echo $rowCount ?> </div></td> </tr> <tr> <td colspan="2"><table width="100%" border="0" align="center" cellpadding="5" cellspacing="0"> <tr> <td bgcolor="#000000" class="style4">#</td> <td bgcolor="#000000"><span class="style4">Name</span></td> <td bgcolor="#000000"><span class="style4">Organization</span></td> <td bgcolor="#000000"><span class="style4">City</span></td> <td bgcolor="#000000"><span class="style4">State</span></td> </tr> <?php $output; ?> </table></td> </tr> <tr> <td colspan="2"> </td> </tr> </table> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/205670-automatically-numbering-rows-with-repeat-region/#findComment-1076296 Share on other sites More sharing options...
RyanMinor Posted June 24, 2010 Author Share Posted June 24, 2010 Wow, you really modified my code. I thought there might be a quick change to what I already had there. Thanks, I'll give it a try when I get home from work and let you know how it goes. Ryan Quote Link to comment https://forums.phpfreaks.com/topic/205670-automatically-numbering-rows-with-repeat-region/#findComment-1076764 Share on other sites More sharing options...
RyanMinor Posted June 25, 2010 Author Share Posted June 25, 2010 OK, I just had a chance to give it a shot and on the first try there was no data being displayed. After looking at the code closer I realized that the variable was named $row in the output of the recordset so I renamed it to $rowCount, and also I had to add "echo" to $output variable down below. Your help is greatly appreciated. Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/205670-automatically-numbering-rows-with-repeat-region/#findComment-1077341 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.