kbios
asked on
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>items.id <li>items.title</li></li> <-- for as many items returned by my query
</ul>
Display would look like:
XYZ123
title of item XYZ123
ABC123
title of item ABC123
...
Here is the php code:
<ul id="itemlist">
<?php
$_POST['hiddenItem']; // using parsed item
$conn = mysql_connect("localhost", "X", "X") or die(mysql_error());
mysql_select_db("test");
$item=mysql_real_escape_st ring($_POS T['hiddenI tem']); // 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>";
}
}
?>
</ul>
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 :)
<ul class="itemlist">
<li>items.id <li>items.title</li></li> <-- for as many items returned by my query
</ul>
Display would look like:
XYZ123
title of item XYZ123
ABC123
title of item ABC123
...
Here is the php code:
<ul id="itemlist">
<?php
$_POST['hiddenItem']; // using parsed item
$conn = mysql_connect("localhost",
mysql_select_db("test");
$item=mysql_real_escape_st
$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>";
}
}
?>
</ul>
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 :)
I think you need to write the <li> statement this way
print "<li>".$value."</li>";
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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?
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?
ASKER
I think there may be some conflict with the CSS. Are there any php/CSS issues to be aware of?
ASKER
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.
ASKER
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.