We help IT Professionals succeed at work.

Why is my function giving me empty <li></li> tags?

Last Modified: 2012-05-11
Hi,  as you can see on my page I have an unordered list:


Its only suppose to be listing the materials that are in the jewelry, but its giving blank <li> tags.

Here are the two functions I created to achieve this:

function get_table_material($table) {
	global $conn, $filename, $materials;
    $query = "SELECT material_id FROM " . $table . " WHERE filename='" . $filename . "'";
	$result = mysql_query($query, $conn);
	$row = mysql_fetch_array($result);
	$materials = trim($row['material_id']);
	$materials = str_split($materials);
	return $materials;
function materials() {
    global $conn, $materials;
	$query = "SELECT * FROM materials";
	$query .= " ORDER BY type ASC";

	$result = mysql_query($query, $conn);
	$output = "<ul>";
	while ($rows = mysql_fetch_array($result)) {
		for($i = 0; $i <= count($materials)-1; $i++) {
			if($materials[$i] == $rows['id'] && !empty($rows['type'])) {
				$output .= "<li>" . $rows['type'] . "<li/>";
	$output .= "</ul>";
	return $output;

Open in new window

I even added trim to $materials in get_table_material(), and made one of the requirements in materials()  in the if statement that it could not be an empty row.

Anyone got an suggestions for getting rid of these empty <li> tags??
Watch Question

Top Expert 2011
Unlock this solution and get a sample of our free trial.
(No credit card required)


Geez its always the silliest of things with me. Thanks though!!
I would try doing this
if(($materials[$i] == $rows['id']) && (!empty($rows['type']))) {
				$output .= "<li>" . $rows['type'] . "<li/>";

Open in new window

Try putting extra () around each part of your evaluation, so that they each get evaluated separately from each other and there can be no mix ups.
I would also make sure that the $materials array has the information that you expect, because as you have it now you will end up with an array of single characters and if what you need is ever longer than that you will run into problems.


Will do, thanks halo
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.


Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.