[thelist] PHP, MySQL and Linked List
Hershel Robinson
hershelr at netvision.net.il
Tue May 31 03:01:16 CDT 2005
I have a linked list structure which I am storing in a MySQL database. The
site code is in PHP. A few tasks which the code must do:
1 Display the nodes of the list in order (i.e. traversing the links).
2 Delete and Insert nodes.
3 Move nodes up or down one notch in the list.
I found no brilliant built-in tools to assist with this in PHP (server runs
PHP 4.3) nor MySQL, so I wrote some simple code to handle these issues. Each
row of the table has an ID and a NextID field. The NextID simply points to
the ID of the next node.
The only algorithm about which I am not thrilled is the first one above, to
display the entire list in order. The method I am using is to load the
entire table, putting each node (and all of its relevant data) into a node
object, an instance of a class I defined. Once the entire table is loaded,
the code can then loop through the nodes, beginning with ID 1 (the root),
following the links, until we come to ID 0 which means done.
I am not aware of any better way to do this, and the only negative I really
see in this method is that the entire table must be loaded into PHP data
structures before processing can begin, but this done seem non-ideal.
Anyone have any better ideas?
Thanks,
Hershel
More information about the thelist
mailing list