aaricwon Posted February 18, 2008 Share Posted February 18, 2008 I am working on www.bjjnews.org/problems I would like each row to begin with a number. I don't want it to be the ID number, I just want to know how many rows I have so the first would always be 1, then 2, 3,4,5,6 etc Link to comment https://forums.phpfreaks.com/topic/91771-is-there-an-easy-way-to-include-a-row-count/ Share on other sites More sharing options...
suttercain Posted February 18, 2008 Share Posted February 18, 2008 Sure, just post the code and I'll show you. But it's going to be like this $i = 1 before your loop... then $i++ before ending your loop. SC Link to comment https://forums.phpfreaks.com/topic/91771-is-there-an-easy-way-to-include-a-row-count/#findComment-470019 Share on other sites More sharing options...
aaricwon Posted February 18, 2008 Author Share Posted February 18, 2008 <style type="text/css"> <!-- .style1 {color: #FF0000} --> </style> <p align="center"><img src="imgs/world-bar.png" width="770" height="59" /> <form name="form" action="<?php echo(htmlentities($_SERVER['PHP_SELF'])); ?>" method="get"> <div align="center"> <p><a href="form.html" class="style1">Report a Problem Order</a></p> <? include 'search.php'; ?> </p> </div> </form> <p align="center">Sort by: <a href="displaytable_date.php">Date</a>, <a href="displaytable_oracle.php">Oracle Order</a>, <a href="displaytable_customer.php">Customer</a> , <a href="displaytable_who.php">Reported by</a><br>Edit/Update Info: <a href="http://www.bjjnews.org/problems/updates.php">Edit Problem Orders</a> , <a href="http://www.bjjnews.org/problems/delete.php">Delete Problem Orders</a> <div align=center><strong><p>Sorted by: <u>DATE</u></strong><p></div> <?php If($PAGE_RESULT != null && $search != NULL && $search != '%'){ echo($PAGE_RESULT); }else{ $conn = mysql_connect($dbhost, $dbuser, $dbpass) or die('Error connecting to mysql'); $dbname = 'bjjnews_problemorders'; mysql_select_db($dbname); $query = "SELECT * FROM problems1 ORDER BY field_6 ASC"; $result = mysql_query($query); echo "<table border='1' cellspacing='0'> <tr> <th bgcolor='FFFFCC'>Oracle Order</th> <th bgcolor='FFFFCC'>Customer</th> <th bgcolor='FFFFCC'>Customer PO</th> <th bgcolor='FFFFCC'>Problem</th> <th bgcolor='FFFFCC'>Reported by</th> <th bgcolor='FFFFCC'>Date</th> <th bgcolor='FFFFCC'>Status</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr bgcolor='CCCCCC'>"; echo "<td>" . $row['field_1'] . "</td>"; echo "<td>" . $row['field_2'] . "</td>"; echo "<td>" . $row['field_3'] . "</td>"; echo "<td>" . $row['field_4'] . "</td>"; echo "<td>" . $row['field_5'] . "</td>"; echo "<td>" . $row['field_6'] . "</td>"; echo "<td>" . $row['field_7'] . "</td>"; echo "</tr>"; } echo "</table>"; } ?> [code] [/code] Link to comment https://forums.phpfreaks.com/topic/91771-is-there-an-easy-way-to-include-a-row-count/#findComment-470022 Share on other sites More sharing options...
suttercain Posted February 18, 2008 Share Posted February 18, 2008 Sha zam zam... change while($row = mysql_fetch_array($result)) { echo "<tr bgcolor='CCCCCC'>"; echo "<td>" . $row['field_1'] . "</td>"; echo "<td>" . $row['field_2'] . "</td>"; echo "<td>" . $row['field_3'] . "</td>"; echo "<td>" . $row['field_4'] . "</td>"; echo "<td>" . $row['field_5'] . "</td>"; echo "<td>" . $row['field_6'] . "</td>"; echo "<td>" . $row['field_7'] . "</td>"; echo "</tr>"; } echo "</table>"; } to $i = 1; while($row = mysql_fetch_array($result)) { echo "<tr bgcolor='CCCCCC'>"; echo "<td>$i</td>"; echo "<td>" . $row['field_2'] . "</td>"; echo "<td>" . $row['field_3'] . "</td>"; echo "<td>" . $row['field_4'] . "</td>"; echo "<td>" . $row['field_5'] . "</td>"; echo "<td>" . $row['field_6'] . "</td>"; echo "<td>" . $row['field_7'] . "</td>"; echo "</tr>"; $i++;//increment by one } echo "</table>"; } Note I changed the first column to the number. If you still want to retain the id number, you'll need to add a new column. SC Link to comment https://forums.phpfreaks.com/topic/91771-is-there-an-easy-way-to-include-a-row-count/#findComment-470025 Share on other sites More sharing options...
aaricwon Posted February 18, 2008 Author Share Posted February 18, 2008 THANKS!!! Link to comment https://forums.phpfreaks.com/topic/91771-is-there-an-easy-way-to-include-a-row-count/#findComment-470028 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.