lovephp Posted November 8, 2012 Share Posted November 8, 2012 how do i do it guys? here is the code while($res = mysql_fetch_array($result)) { $id = $res['id']; $date = $res['time']; $newdate = date("D, j M, Y", $date); if($res['approval'] == "Yes"){ echo "<tr align='center' bgcolor='#CDE861'>"; }else if($res['approval'] == "No"){ echo "<tr align='center' bgcolor='#F28598'>"; }else{ echo "<tr align='center' bgcolor='#EDA553'>"; } echo"<td><font color='black'>" .$res['randid']."</font></td>"; echo"<td><font color='black'>" .strtoupper($res['center'])."</font></td>"; echo"<td><font color='black'>" .$res['customer_name']."</font></td>"; echo"<td><font color='black'>". $res['home_phone']. "</font></td>"; echo"<td><font color='black'>". $newdate. "</font></td>"; if($res['approval'] == "Yes"){ echo"<td>Approved</td>"; }else if($res['approval'] == "No"){ echo"<td>Rejected</td>"; }else{ echo"<td>Pending</td>"; } echo"<td> <a href ='view.php?id=$id'><center>Click to View </center></a></td>"; if($name=='off'){ echo ''; i want to the rows to display results by numbering like 1. id name etc etc 2. id name etc etc Quote Link to comment Share on other sites More sharing options...
requinix Posted November 8, 2012 Share Posted November 8, 2012 What have you tried so far? Quote Link to comment Share on other sites More sharing options...
lovephp Posted November 8, 2012 Author Share Posted November 8, 2012 i tried <ol> <td>content</td></ol> but did not work i get 1. 1. everywhere Quote Link to comment Share on other sites More sharing options...
Psycho Posted November 8, 2012 Share Posted November 8, 2012 Some notes first: 1. The FONT tags have been deprecated for many, many years! 2. Simplify your logic by determining the values to display at the beginning of the loop and then do the output after. To add the row numbers, just add a variable and increment and output it on each iteration. $rowNo = 0; while($res = mysql_fetch_array($result)) { $rowNo++; //Increment Row Number $date = date("D, j M, Y", $res['time']); $center = strtoupper($res['center']); if($res['approval'] == "Yes") { $approvalText = "Approved": $approvalColor = '#CDE861'; } else if($res['approval'] == "No") { $approvalText = "Rejected": $approvalColor = '#F28598'; } else { $approvalText = "Pending": $approvalColor = '#EDA553'; } echo "<tr align='center' bgcolor='{$approvalColor}'>\n"; echo " <td style='color:black;'>{$rowNo}</td>"; echo " <td style='color:black;'>{$res['randid']}</td>"; echo " <td style='color:black;'>{$center}</td>"; echo " <td style='color:black;'>{$res['customer_name']}</td>"; echo " <td style='color:black;'>{$res['home_phone']}</td>"; echo " <td style='color:black;'>{$date}</td>"; echo " <td>{$approvalText}</td>"; echo " <td><a href ='view.php?id={$res['id']}'><center>Click to View </center></a></td>\n"; //And continue on for other rows echo "</tr>\n"; } Quote Link to comment Share on other sites More sharing options...
lovephp Posted November 8, 2012 Author Share Posted November 8, 2012 Some notes first: 1. The FONT tags have been deprecated for many, many years! 2. Simplify your logic by determining the values to display at the beginning of the loop and then do the output after. To add the row numbers, just add a variable and increment and output it on each iteration. $rowNo = 0; while($res = mysql_fetch_array($result)) { $rowNo++; //Increment Row Number $date = date("D, j M, Y", $res['time']); $center = strtoupper($res['center']); if($res['approval'] == "Yes") { $approvalText = "Approved": $approvalColor = '#CDE861'; } else if($res['approval'] == "No") { $approvalText = "Rejected": $approvalColor = '#F28598'; } else { $approvalText = "Pending": $approvalColor = '#EDA553'; } echo "<tr align='center' bgcolor='{$approvalColor}'>\n"; echo " <td style='color:black;'>{$rowNo}</td>"; echo " <td style='color:black;'>{$res['randid']}</td>"; echo " <td style='color:black;'>{$center}</td>"; echo " <td style='color:black;'>{$res['customer_name']}</td>"; echo " <td style='color:black;'>{$res['home_phone']}</td>"; echo " <td style='color:black;'>{$date}</td>"; echo " <td>{$approvalText}</td>"; echo " <td><a href ='view.php?id={$res['id']}'><center>Click to View </center></a></td>\n"; //And continue on for other rows echo "</tr>\n"; } thanks for this mate really helpful. but im still not sure how to go on about doing the numbering? Quote Link to comment Share on other sites More sharing options...
requinix Posted November 8, 2012 Share Posted November 8, 2012 Perhaps you missed it? To add the row numbers, just add a variable and increment and output it on each iteration. $rowNo = 0; while($res = mysql_fetch_array($result)) { $rowNo++; //Increment Row Number $date = date("D, j M, Y", $res['time']); $center = strtoupper($res['center']); if($res['approval'] == "Yes") { $approvalText = "Approved": $approvalColor = '#CDE861'; } else if($res['approval'] == "No") { $approvalText = "Rejected": $approvalColor = '#F28598'; } else { $approvalText = "Pending": $approvalColor = '#EDA553'; } echo "<tr align='center' bgcolor='{$approvalColor}'>\n"; echo " <td style='color:black;'>{$rowNo}</td>"; echo " <td style='color:black;'>{$res['randid']}</td>"; echo " <td style='color:black;'>{$center}</td>"; echo " <td style='color:black;'>{$res['customer_name']}</td>"; echo " <td style='color:black;'>{$res['home_phone']}</td>"; echo " <td style='color:black;'>{$date}</td>"; echo " <td>{$approvalText}</td>"; echo " <td><a href ='view.php?id={$res['id']}'><center>Click to View </center></a></td>\n"; //And continue on for other rows echo "</tr>\n"; } Quote Link to comment Share on other sites More sharing options...
JamesThePanda Posted November 9, 2012 Share Posted November 9, 2012 <?php echo $i++ ;?> Quote Link to comment Share on other sites More sharing options...
JamesThePanda Posted November 9, 2012 Share Posted November 9, 2012 (edited) $rowNo = 0; while($res = mysql_fetch_array($result)) { $rowNo++; //Increment Row Number $date = date("D, j M, Y", $res['time']); $center = strtoupper($res['center']); if($res['approval'] == "Yes") { $approvalText = "Approved": $approvalColor = '#CDE861'; } else if($res['approval'] == "No") { $approvalText = "Rejected": $approvalColor = '#F28598'; } else { $approvalText = "Pending": $approvalColor = '#EDA553'; }?> <tr align='center' bgcolor='<?php {$approvalColor} \n ?>'> <td style='color:black;'><?php {$rowNo}; ?></td> <td style='color:black;'><?php {$res['randid']}; ?></td> <td style='color:black;'><?php {$center}; ?></td> <td style='color:black;'><?php {$res['customer_name']}; ?></td> <td style='color:black;'><?php {$res['home_phone']}; ?></td> <td style='color:black;'><?php {$date}; ?></td> <td><?php {$approvalText}; ?></td> <td><a href ="view.php?id=<?php {$res['id']}; ?>"><center>Click to View </center></a></td><br /> //And continue on for other rows </tr><br /><?php } sorry but thats the better way to right it instead of using all the echo codes Edited November 9, 2012 by JamesThePanda Quote Link to comment Share on other sites More sharing options...
trq Posted November 9, 2012 Share Posted November 9, 2012 sorry but thats the better way to right it instead of using all the echo codes In your opinion of course. Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted November 9, 2012 Share Posted November 9, 2012 sorry but thats the better way to right it instead of using all the echo codes Note that code like the following will give a parse error about an unexpected '}'. <td style='color:black;'><?php {$rowNo}; ?></td> You still need an echo statement and the curly quotes aren't needed. Also, the inline styles could be replaced with a style sheet. <tr><td><?php echo $rowNo; ?></td></tr> Quote Link to comment Share on other sites More sharing options...
lovephp Posted November 9, 2012 Author Share Posted November 9, 2012 this $rowNo gives me only 1 in every rows Quote Link to comment Share on other sites More sharing options...
cyberRobot Posted November 9, 2012 Share Posted November 9, 2012 this $rowNo gives me only 1 in every rows What does your code look like? Quote Link to comment Share on other sites More sharing options...
lovephp Posted November 9, 2012 Author Share Posted November 9, 2012 oh got it i added $num = 1; and then i did $row++ Quote Link to comment Share on other sites More sharing options...
lovephp Posted November 9, 2012 Author Share Posted November 9, 2012 thnks you friends u guys rock \m/ Quote Link to comment Share on other sites More sharing options...
JamesThePanda Posted November 9, 2012 Share Posted November 9, 2012 In your opinion of course. yes in my opinion of course. Quote Link to comment 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.