How do I create an unnumbered list in php from mysql data?

Below is my php code to retrieve some data from a mysql db. The db=test, table=items and the fields to display are id and title. I want to create an unnumbered list as follows:

<ul class="itemlist">
  <li> <li>items.title</li></li>        <-- for as many items returned by my query

Display would look like:
title of item XYZ123

title of item ABC123


Here is the php code:

<ul id="itemlist">
    $_POST['hiddenItem'];  // using parsed item
    $conn = mysql_connect("localhost", "X", "X") or die(mysql_error());
    $item=mysql_real_escape_string($_POST['hiddenItem']);  // using parsed item
    $sql = "SELECT id, title FROM items WHERE id = '$item'";
    $result = mysql_query($sql, $conn) or die(mysql_error());
    while($row = mysql_fetch_assoc($result)){
       foreach ($row as $id => $value){
       print "<li>"$value"</li>";

Please use my code snipet in your example not some obscure reference to a previously posted question. I'm new to php and need a little hand holding :)
Who is Participating?
PranjalShahConnect With a Mentor Commented:
Try changing your while loop to this...
while($row = mysql_fetch_array($result)) {
     echo "<li>".$row['id']."<li>".$row['title']."</li></li>";

Open in new window

kbiosAuthor Commented:
Something I've noticed and do not understand. If I change the print statement above to:

print "li $value li";      

the literal string li appears along with the value of $value, BUT if I insert <li> that text does not appear. Any text will work but not with < > I have tried all combnations of single and double quotes but to no avail.
I think you need to write the <li> statement this way
print "<li>".$value."</li>";

Open in new window

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

kbiosAuthor Commented:
thanks for both suggestions. neither one worked.

the contents of 'id' and 'title' display just fine but neither the echo or print statement will display the actual string <li> or </li>. I can replace those tags with other text and the other text appears but not the <li> or </li>. Any suggestions as to why the literal string <li> or </li> does not appear?
kbiosAuthor Commented:
I think there may be some conflict with the CSS. Are there any php/CSS issues to be aware of?
kbiosAuthor Commented:
Thanks. I'm still having the problem but I think it's narrowed down to some issue with my CSS. Your code was helpful, so thanks. It's late and I'm accepting this as the final answer.
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.