Using Php To Display Unordered List

Nov 20, 2005

I have a (MySQL-)database table with columns like:

id study parent_id

How do I display (using php) a tree that looks like this:

<li>category A</li>
<li>sub category A-1</li>
<li>sub category A-2</li>
<li>sub category A-3</li>
<li>category B</li>
<li>sub category B-1</li>
<li>sub category B-2</li>
<li>category C</li>
<li>sub category C-1</li>
<li>sub category C-2</li>

View 1 Replies


Create Unordered List Tree Menu From Data Stored In An Table With The Adjacency List Model?

I need to create a tree menu of "nth" subcategories. I settled on using the adjacency list model for my table structure, because I won't be updating this table very much and this seemed the easiest to implement for my use. I want to style the output using "ul" and "li" tags...I already have a css and jquery solution to do the styling. My problem comes from pulling the data out of the database and using a recursive function via PHP to build the list ... the list is a concatenated string that gets parsed to build the tree. I'm really having a hard time getting the closing "ul" and "li" tags to line up just where they need to be.

Here's my table structure: portfolio_id (int), p_name (varchar), parent_portfolio_id (int) Here's what I want the data to look like when presented:

<li>Portfolio Name
<li>Sub portfolio A


View 2 Replies

Css - Add Odd/even Loop To Unordered List?

Here an example my wordpress post. I want to add some class to the last of <li>

something like <li class='lastli'>
<ul class="tabs">
global $post;
$myposts = get_posts('numberposts=3');


The results I wanted to be like :

<li>Title 1</li>
<li>Title 1</li>
<li class='lastli'>Title 1</li>

Any last of unordered lists will be <li class='lastli'>. Let me know how to do that?

View 3 Replies

How To Create Unordered List

I am creating an Org Chart and I cannot seem to figure out a way to have php create an unordered list in the proper format. Here is my code;

MySQL Database
| category_id | name | lft | rgt |
$localhost = "";
$sql_username = "";
$sql_password = "";


View 9 Replies

Wrap Every 5 Results In Unordered List?

I have an array containing a "Variable" amount of results/entries.

I use foreach as normal to echo the array results.

Problem: I want to wrap every 5 results from the array in Unordered list.

I do not know the total number of results since it's variable. So for example if it contains 18 items. It should display 4 ULs, the first 3 ULs containing 5 results and the last UL contains only the remaining 3 items.

View 5 Replies

Add A Class To A Child Unordered List?

I've successfully added a few classes to the first ul in wordpress' template tag: wp_page_menu, however, I haven't been able to add a class to the child ul nested in the first li.

1.function add_menuclass($ulclass) {
2.return preg_replace('/<ul>/', '<ul class="clearfix rMenu-hor rMenu">', $ulclass, 1);


View 1 Replies

Dynamically Populate An UnOrdered List?

I am attempting following code to populate an UnOrdered List dynamically. The same type of code I am successfully using to populate a DropDown. But when I changed the tags to UnOrdered List, it is not working. When run, it just displays some tags instead of the actual output.Where is the error:


View 4 Replies

Creating Simple Unordered List Menu From XML?

Does anyone have any examples or links to examples of generating a
simple unordered list menu with multiple levels from an XML file? We
are redesigning the navigation on our website and I was hoping to make
this as flexible as possible.

View 1 Replies

Building Unordered List Navigation Menu?

I wrote a dynamic menu based on three table on db which reflects below level frame:

> Section
>> Categories
>>> Subcategory

Here is my code:

echo '<ul>';
$q1 = mysql_query("SELECT * FROM section ORDER BY section_name ASC");
while($getSection = mysql_fetch_array($q1)) {


View 1 Replies

Html - Add Dynamic Classes To An Unordered List?

I'm trying to add consecutive classes to all list-items in a list with the class of 'nav'. Essentially, I want every list-item to have a class of 'nthChild-x', where x represents its position in the list. I'm a major noob to PHP, so be easy.

Here is the current markup:

<ul id="primaryNav" class="nav">
<li>Blah Blah Uno</li>
<li>Blah Blah Dos</li>
<li>Blah Blah Tres</li>

I want this list to be rendered as the following:

<ul id="primaryNav" class="nav">
<li class="nthChild-1">Blah Blah Uno</li>
<li class="nthChild-3">Blah Blah Dos</li>
<li class="nthChild-3">Blah Blah Tres</li>

I know how to do this with JS but need this to be server-side. Also, I don't necessarily want to target the ID of the list because I'd rather do it once and target all lists (though that could be a start).

View 3 Replies

Nested Unordered List For Menu ( Arrays )?

I'm confused as to how to use an associative array to produce a menu with a nested UL. For example, the result I'd like to achieve is:

<li><a href="page1.html">Page 1</a></li>
<li><a href="page2.html">Page 2</a>
<li><a href="page2-1.html">Page 2-1</a></li>


View 2 Replies

Build An Unordered List Dynamically From Json Data

How do I modify this function that dynamically builds a drop down list so that I could build an un-ordered list dynamically from json data.

<script type="text/javascript" language="javascript">
$(document).ready(function() {
jQuery .getJSON("", function (jsonData) {
$.each(jsonData, function (i, j) {

*spec_list* is id of drop down i.e. 'select' here & options i.e. in (j.options) is the field in table which data is received as json. I have 'msg' only table field now which data is to be used to dynamically populate 'ul id="msg"'.

View 1 Replies

Multidimensional Array To Unordered List, Building Up Url Path?

I have a multidimensional array in PHP produced by the great examples of icio and ftrotter (I am use ftrotterrs array in arrays variant):Turn database result into arrayI have made this into a unordered list width this method:

public function outputCategories($categories, $startingLevel = 0)
echo "<ul>


View 2 Replies

Created Style Status Update To An Unordered List?

I've a Facebook/Twitter where the new Status' get added to . I now want to add a "REMOVE" function to it, however, I'm not sure how to best accomplish this. n my list item, create my [a] tag with the unique ID of the status post ID and set a listener classHave jQuery listen for [a] tags with the listener classPOST the ID over to the PHP script to remove the post; if successful return with "ok" or if failed return with "fail"In the callback function, if it's OK, then find the element and remove it

View 1 Replies

Reading HTML Unordered List Into Multidimensional Array

I have some software (Wordpress, actually) that is sending HTML code of an unordered list when I call a particular function. I want to make that list into a multidimensional array. So something like this: Code:

View 3 Replies

How Can Strip The Text Bullet And Then Make That Copy An Unordered List In The HTML?

I have some text coming into a web page from a MySql DB that contains bullets in the copy. The copy cannot be changed as it is also used in a Quark Xpress document we have connected to the DB. So, my question is how can strip the text bullet and then make that copy an Unordered list in the HTML?

This is what I have but and does the indents like a list but no bullets (I guess they are being stripped by the str_replace as well?

echo str_replace(Chr(13), "<p>", ("<ul>".str_replace('ââ¬Â¢', '', $bulletcontent1)."</ul>"));

View 2 Replies

Unordered List Replace Bullet By Image According To Level If Last Level Text As Link?

I was wondering if there is a way to change the the look of wach level of a list. Ex:

Last level, text = link

1st level, has 1 image instead of bullet and text in bold

2nd level as another image as bullet and text in bold

3rd level, if not last level, as another image as bullet and text in bold

Here is where I'm now :

PHP Code:

<style type="text/css">


View 5 Replies

Convert A (nested)HTML Unordered List Of Links To Array Of Links?

I have a regular, nested HTML unordered list of links, and I'd like to scrape it with PHP and convert it to an array. The original list looks something like this:

<li><a href="">First item</a>

View 1 Replies

Drupal - List Of Events With A List Of Timestamps, Grouped By Hour In A Tabular Display?

While refactoring, I am looking for an optimised algorithm for a timetable (calendar) in PHP. I have a list of events which have a list of timestamps. This must be presented in a tabular way. The current code works, but has a) quite some quircks and is b) very inflexible. I am looking to refactor this piece and looking for input on optimised ways.

Example here, notice the header of the table bearing the hours. And the times within that hour being grouped in that column. One event, having two timestamps in one hour can be ignored (may only happen in theory, as per the technical docs)

The table is built with Drupals theme_table(), which I can build up from any array, bearing arrays for each row. the Drupal part, however, is of little interest here :)

Current code (snippets):

//inside function that builds the content for the page linked to above:
$this_morning = _playdates_get_start_of_day_with($timestamp);
$this_night = _playdates_get_end_of_day_with($timestamp);
$nodes = _playdates_load_all_in_range($types, $this_morning, $this_night);
usort($nodes, '_playdates_cmp_titles');
//we now have a list of "nodes", being the events listed in the first column, which have
// a list of playdates, the timestamps. $node->nid is a unique id for each event.
foreach ($nodes as $node) {


View 2 Replies

Unordered Word Search

I've built a search engine that queries a MySQL database. However,
if I enter "foo bar", the engine will search for that phrase exactly,
and will not find "bar foo" nor "foo something bar". How do you
separate words so that the engine finds them individually? I'm thinking
something like

$tokenized = strtok($query, " ")
mysql_query(" SELECT ... FROM ...
while(...){ WHERE ...}

View 2 Replies

Dynamic Unordered Lists

I have searched about for this one but havent quite found the low down i'm looking for but here goes.

I'm trying to dynamically populate an unordered list from an SQL database which will have upto 5 or 6 sub-selections per top level list item so.. it would do something like this: Code:

View 1 Replies

Unordered Input Args


function myfunc($i, $j){

echo myfunc($j=6, $i=3);

I know this doesn't work, but is there some way to do unordered list for input arguments to a function? I want the above function to return 6 by only manipulating the function call.

View 3 Replies

Move Next With Unordered ID Column?

I'm trying to move to the next record in a query using php/MySQL A simplified query is below:

$result = mysql_query("SELECT id FROM table ORDER BY datefield, id ASC");
$row = mysql_fetch_object($result);
$id = $row->id;

This simply selects the table data and orders it by a date field first, then id.Normally, if the query was only ordered by ID, we could be assured that the ID was increasing as we move forward row by row. If this was the case, to get the next row I would use:

$next_result = mysql_query("SELECT id FROM table WHERE id > '$id' ORDER BY id ASC LIMIT 1
$next_row = mysql_fetch_object($next_result);
$next_id = $next_row->id;

This normally works perfectly, however the problem here is that the primary order of the initial query is by a date field, then ID. The date field does not necessarily have any relation to the order of the ID

That means that you can get data ordered like this:

Date | ID
2010-08-01 | 1
2010-08-01 | 4
2010-08-02 | 3
2010-08-02 | 2

You can probably see the problem here.. we cannot move next by simply getting the next highest ID in the query because the ID is not in increasing order.

View 3 Replies

Display List

i'm trying to create a script that - when a visitors visits the page- shows all duplicate entries of a certain field (field is called 'ip'). The script should check the database (column = users) and should list all accounts a ip address has (if it has more than one). If there is only one account for an IP it shouldn't be shown. Only when multiple accounts are made by the same IP i would like it to be listed in a table like : [ip] [accountname1,accountname2,...]

View 7 Replies

How To Automatically Display From A List Box?

I am working on a PHP/HTML form which supports End User queries.

I need the user to select a combination of Airline and corresponding
place of Origin. i,e
Delta - Madison, Dallas, Atlanta
KLM - Amsterdam, Houston, Detroit
Brit - New York, London, Seattle

I have a list of Airlines in a list box. The moment the user selects an
Airline(Delta) from the List box, the list box below it needs to have
(Dallas, Atlanta, Madison) as its options.

How is this done? How do I use a listbox selection as a trigger an
automatically start the next activity?

View 9 Replies

PHP To Display Drop Down List

I'd like to have 3 drop down lists connected.

Department and

Where the options of Department are dependent on what is selected in Division and the options of Section are dependent on what is selected in Department. So far, all the examples I've found have been using JavaScript. Can I do this in PHP as I have no knowledge of JavaScript at all.

View 6 Replies

Copyrights 2005-15, All rights reserved