Highlighting data in a loop

Associate
Joined
4 Feb 2014
Posts
12
I have a while loop setup that grabs data from my database and inserts into tables. What im stuck on and want to do is check the table column name and any ending in the letter 'P' I want to be able to highlight or bold all of the data in that row.

Can someone help me with this code please??

Here is the loop I have:
Code:
// Prints the columns
		echo "<table class='searchTable' border='1';  <tr>"; 
		for($j = 0; $j < mysql_num_fields($result); $j++) {     
		$field_info = mysql_fetch_field($result, $j);     
		echo "<th>{$field_info->name}</th>"; }  
		
		// Print the data 
		
		while($row = mysql_fetch_row($result)) {     
		echo "<tr>";     
			foreach($row as $_column) {   
			      
				echo "<td>{$_column}</td>";     }     
				echo "</tr>"; 
				}  
				
				echo "</table>";
 
Do you mean row or column, I ask because what happens if you get to column 5 of 10 and it's the first column that ends with a 'P'. the formatting for previous columns will have already been done?

Sorry I will rephrase that, as that was incorrect what I said.

I want all the data in columns that end in a 'P' to be highlighted, not rows.
 
Code:
$isP = strtolower‎ (substr($_column, -1)) == 'p';
echo '<td style="' . ($isP ? 'background:green') . '">' . $_column . '</td>';

Im am getting an undefined error for the strtolower function. Not sure what the "?" in $isP ? 'background:green' does, or was that a typo?

Thanks
 
It's erroring due to the space before the brace.

The ? is a ternary operator, think of it as a short hand IF/ELSE

Code:
<?php echo true ? 'True' : 'False'; ?>

Getting an error now on the second line. Unexpected ')'!! Not sure why.
 
Back
Top Bottom