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

Hi,  as you can see on my page I have an unordered list:

http://www.auroriella.com/bracelet.php?item=b3

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);
	confirm_query($result);
	$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);
	confirm_query($result);
	$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??
FairyBusinessAsked:
Who is Participating?
 
Rik-LeggerConnect With a Mentor Commented:
You have the ending syntax wrong,
it should be:

$output .= "<li>" . $rows['type'] . "</li>";

Open in new window


0
 
FairyBusinessAuthor Commented:
Geez its always the silliest of things with me. Thanks though!!
0
 
haloexpertsexchangeCommented:
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.
0
 
FairyBusinessAuthor Commented:
Will do, thanks halo
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.