Advertisement

10.07.2008 at 11:31AM PDT, ID: 23794787
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

9.2

Alternating row colors in a WHILE statement

Asked by Simon336697 in PHP Scripting Language

Hi everyone hope you are all well.
Guys I have the following situation in which ive stuck a problem involving returning rows from mysql tables and alternating each row's color.
Ive attached the code in the snippet window.
Im using the modulus operator in a FOR statement, which works fine for alternating row colors when im using a FOR statement. Im using this when performing a mysql query to return ALL rows from a table.

I have another section though, where Id like to alternate row colors. This section filters the result set, but in this case, im using a WHILE statement to get the filtered results back.
The problem here is that I dont know how to alternate row colors when using the WHILE statement, since the alternating row color code is in the format of a 'FOR ($i = 0   blah blah)

Any help on getting the snippet code titled "code for the WHILE (not working with the alternating row color code):"
working would be greatly appreciated.

Thanks guys.


Start Free Trial
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
======================================== THIS WORKS:
 
for ($i=0; $i < $numrows; $i++) {
$rows=mysql_fetch_array($result); // get a row from our result set
// while ($rows = mysql_fetch_array($result)) {   // Commenting out the above 2 lines and uncommenting this one results in the same thing, other than alternating colors. 
 
	if($i % 2) { // if there is a remainder 
	?>
		<tr class="altdelRow_0">
		<?php
		}
	else { // if there is not a remainder we will do the else ?>
		<tr class="altdelRow_1">
		 <?php
		}?>
			<td id="viewtasksidall"><?php echo $rows['id_ctk']; ?></td>
			<td id="viewtasksnameall"><?php echo stripslashes($rows['name_ctk']); ?></td>
			<td id="viewtasksprojectall"><?php echo stripslashes($rows['name_pro']); ?></td>
			<td id="viewtasksdescriptionall"><?php echo $rows['description_ctk']; ?></td>																	
		</tr> 		
	<?php } ?>
 
============================================ code for the WHILE (not working with the alternating row color code):
 
if (isset($_POST['projectid'])) {
	$grab_projectid = $_POST[projectid];		
	$sql_view_tasks =	"SELECT * FROM `$tbl_tasks`, `$tbl_projects` where fk_id_pro_ctk = id_pro AND id_pro = '$grab_projectid'";
	$result_view_tasks = mysql_query($sql_view_tasks);
 ?>
 
	<div id="div_wrapper_tablesort">
		<table id="table_sort" class="sortable">
			<thead><tr><td><b>ID</b></td><td><b>Task Name</b></td><td><b>Project</b></td><td><b>Description</b></td><td id="theaderedit"><b></b></td></tr></thead>
			<tbody>
				<?php while($rows_view_tasks=mysql_fetch_array($result_view_tasks)){ ?>
						<tr>
							<td id="viewtasksid"><?php echo $rows_view_tasks['id_ctk']; ?></td>
							<td id="viewtasksname">
								<a href="<?php echo $query_string_page; ?>" target="_blank"><?php echo stripslashes($rows_view_tasks['name_ctk']); ?></a></td>						
							<td id="viewtasksproject"><?php echo $rows_view_tasks['name_pro']; ?></td>
							<td id="viewtasksdescription"><?php echo $rows_view_tasks['description_ctk']; ?></td>
							<td id="viewtasksradio">						
								<form name="formedit" method="post" action="edit_task.php">		
									<input type="checkbox" name="radioedittask" value="<?php echo $rows_view_tasks['id_ctk']; ?>">	
									<input type="hidden" name="hiddendescription" value="<?php echo htmlspecialchars($rows_view_tasks['description_ctk']); ?>"> 											
							</td>		
						</tr> <?php } ?>	
									<input id="edittaskbutton" type="submit" name="Submit" value="Edit">
								</form>	
			</tbody>
			<tfoot></tfoot>
		</table>
	</div>
<?php } else {  } ?>
 
 
Loading Advertisement...
 
[+][-]10.07.2008 at 11:38AM PDT, ID: 22662195

View this solution now by starting your 14-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP Scripting Language
Sign Up Now!
Solution Provided By: glcummins
Participating Experts: 1
Solution Grade: A
 
 
[+][-]10.07.2008 at 11:55AM PDT, ID: 22662372

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 14-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]10.07.2008 at 11:57AM PDT, ID: 22662408

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 14-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20081112-EE-VQP-43 / EE_QW_2_20070628