I am trying to use dijkstra's algorithm to find the shortest path between two points. The algorithm currently uses data in the format of:
$neighbors[A] = array(B => 2, C => 1, D => 4);
$neighbors[B = array(A => 2, C => 1, E => 4);
However, this data is hard-coded in the example I am using. I would like to extract this data from a mysql database to dynamically fill the array using a while or for loop.
How would I extract the data from the database to provide the data in the same format i.e.
$neighbours[node] = array(link, link, link)
the database stores the data in records such as:
Node: A
Links: B => 2, C=> 1, D => 4
I am familiar with extracting data from the database, but I'm not sure how to fill the arrays.
Thanks for your help!
Bert.