Sorry, bout that. My brain wasn't working right. It was a lot simpler than I thought. Forget the foreach. I used a counter. :-[ PJ wrote: > The more I get into arrays, the less I understand. > I have a ridiculously simple task which excapes me completely. > I need to ouput all fields in 1 column from 1 table in two phases sorted > alphabetically. > So, I have the query, I have the results. But since I need to split the > list into 2 parts, I need indexes. I cannot use the table index as it > does not correspond to the alphabetical order of the data column. In > order to get the index, I sort the resulting array and that now gives me > 34 arrays each containing an array of my results. Wonderful! > But how do I now extract the arrays from the array? > > Here is what I'm trying to do: > > $SQL = "SELECT category > FROM categories > ORDER BY category ASC > "; > $category = array(); > if ( ( $results = mysql_query($SQL, $db) ) !== false ) { > while ( $row = mysql_fetch_assoc($results) ) { > $category[$row['category']] = $row; > } > sort($category); > //var_dump($category); > echo "<table >"; > $count = mysql_num_rows($results); > $lastIndex = $count/2 -1; echo $lastIndex; > $ii = 0; > $cat = ''; > //print_r($category['0']['category']); > foreach($category as $index => $value) { > $ii++; > if ($ii != $lastIndex) { > $cat .= "$value, "; > } > else { > $cat .= " & $value<br />"; > } > $catn = preg_replace("/[^a-zA-Z0-9]/", "", $cat); > //echo "<pre>$category</pre>"; > echo "<tr> > <td><a href='../categories/", $catn, ".php'>", $cat, "</a> > </td> > </tr>" ; > } > } > echo "</table>"; > > What should I be using in the foreach line? > Please help! > > -- unheralded genius: "A clean desk is the sign of a dull mind. " ------------------------------------------------------------- Phil Jourdan --- pj@xxxxxxxxxxxxx http://www.ptahhotep.com http://www.chiccantine.com/andypantry.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php