wondered if someone could point me in the direction...
I have a query that pulls out 'n' number of stoppages associated to one or more waterways.
A sample query might be such as:
Code: Select all
<?php
SELECT stoppages.type, stoppages.name, stoppages.wway_id, waterways.name AS wwayname FROM stoppages LEFT JOIN waterways ON stoppages.wway_id = waterways.id WHERE stoppages.wway_id = 253 OR stoppages.wway_id = 2 OR stoppages.wway_id = 3 OR stoppages.wway_id = 4 AND stoppages.start_date >= "2004-07-31"
?>Code: Select all
type: name: wway_id: wwayname: start_date:-
r, this is the third stoppage, 276, River Brue, 2004-10-10
s, this is the sixth stoppages, 3, Ashby Canal, 2004-10-10
r, this is the seventh stoppage, 3, Ashby Canal, 2004-08-09
r, this is the eigth stoppage, 3, Ashby Canal, 2004-09-29Code: Select all
<?php
while($data = mysql_fetch_array($result, MYSQL_ASSOC)) {
//create an array whose index is the waterway name
//then create a sub array to hold each stoppage details for that waterway
$search_results = array($data['wwayname'] => array( "type" => $data['type'], "name" => $data['name']) );
} // wend
?>Code: Select all
<?php
if( is_array($search_results) ) {
//loop over $search_results array
print_r($search_results);
foreach($search_results AS $wwayname => $val) {
$html .= "$wwayname : $val[type] : $val[name]<br />";
}
}
else {
$html .= '<p>No results found</p>';
}
?>One is that if I have more than 1 stoppage on a waterway it will overwrite a previous entry in the array for a waterway with the same name .e.g:
Code: Select all
<?php
$search_results = array($data['wwayname'] => array( "type" => $data['type'], "name" => $data['name']) );
//could be translated as
$search_results = array(Ashby Canal => array("type" => r, "name" => this is the seventh stoppage) );
// which is then written over by the eigth stoppage
?>Anyone pass on any hints where I could hold multiple stoppage records per waterway and then how to iterate over the array created to geth the data written to the screen?
Sorry for the verbosity, but I thought better to give too much info than too little.
TIA