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

Posted on 2011-04-26
Medium Priority
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??
Question by:FairyBusiness
  • 2

Accepted Solution

Rik-Legger earned 2000 total points
ID: 35469856
You have the ending syntax wrong,
it should be:

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

Open in new window


Author Comment

ID: 35469904
Geez its always the silliest of things with me. Thanks though!!
LVL 13

Expert Comment

ID: 35469986
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.

Author Comment

ID: 35470014
Will do, thanks halo

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to dynamically set the form action using jQuery.
Suggested Courses
Course of the Month14 days, 11 hours left to enroll

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question