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

Posted on 2011-04-26
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
    LVL 8

    Accepted Solution

    You have the ending syntax wrong,
    it should be:

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

    Open in new window


    Author Comment

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

    Expert Comment

    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

    Will do, thanks halo

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Title # Comments Views Activity
    MySQL tables for vtiger CRM 4 28
    What is a timing leak? (in plain english) 7 31
    GPS save in database 19 20
    Issues with signature 19 19
    As this topic comes over and over again in different forms, I've finally decided to write a short (yea, right...) article / tutorial about pagination with PHP with MySQL database. There are dozens of these kind of tutorials, I know - I wanted to mak…
    Deprecated and Headed for the Dustbin By now, you have probably heard that some PHP features, while convenient, can also cause PHP security problems.  This article discusses one of those, called register_globals.  It is a thing you do not want.  …
    The viewer will learn how to count occurrences of each item in an array.
    The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now