Empty value check when iterating through array

I have an array that is created in a WHILE loop (fetches values from the database, assigns, then generates a simple UL. On the rare occasions that the UL has an empty LI, I would like for it to simply generate “nothing” (something like white-space or whatever).

In order to do this, I believe I’ll have to check for empty values in the array during the iterations. How would I do this exactly?

Below is the code I’m working with and I welcome input on how to improve what I have thus far:

	function fs_chart(){
		$chart[] = '';
		$result = mysql_query("SELECT * FROM fs_members");
		$count = mysql_num_rows($result);
		$i=0;
		while($row = mysql_fetch_array($result)){
			//if(in_array('',$row)){echo $row[];}//Create condition logic to handle empty array values...
			if($i % 2){$class[] = 'even';}else{$class[] = 'odd';}
			$chart[] = '<ul class="inline '.$class[$i].'">
							<li><a href="#" title="'.$row['first_name'].'">'.$row['first_name'].'</a></li>
							<li><a href="#" title="'.$row['middle_name'].'">'.$row['middle_name'].'</a></li>
							<li><a href="#" title="'.$row['last_name'].'">'.$row['last_name'].'</a></li>
							<li><a href="#" title="'.$row['department'].'">'.$row['department'].'</a></li>
							<li><a href="#" title="'.$row['office_phone_number'].'">'.$row['office_phone_number'].'</a></li>
							<li><a href="#" title="'.$row['office_room_number'].'">'.$row['office_room_number'].'</a></li>
							<li><a href="#" title="'.$row['membership_length'].'">'.$row['membership_length'].'</a></li>
							<li><a href="#" title="'.$row['university_tenure'].'">'.$row['university_tenure'].'</a></li>
							<li><a href="#" title="Delete">Delete</a></li>
						</ul>';
						$i++;
		}
		foreach($chart as $value){echo $value;}
	}

I know there’s a lot of room for improvement here, so again, I welcome any suggestions. :slight_smile:

$str = '<ul class="inline '.$class[$i].'">';

if (!empty($row['first_name']))
    $str .= '<li><a href="#" title="'.$row['first_name'].'">'.$row['first_name'].'</a></li>';

if (!empty($row['middle_name']))
    $str .= '<li><a href="#" title="'.$row['middle_name'].'">'.$row['middle_name'].'</a></li>';

//... etc for all the <li>

$str .= '</ul>';
$chart[] = $str;

Unrelated – $class can just as easily be a string, there’s no reason to use an ever-growing array to assign the class name for the <ul>.

$class = ($class == 'even') ? 'odd' : 'even';
$str = '<ul class="inline ' . $class . '">';

Yeah, I still have a hard time with some basic concepts but I’m finding that the more I actually code instead of reading about, the more I improve.

Anyway, thanks for your excellent input Dan. :slight_smile: