I know this is probably very easy, but I have searched Google and not found what I'm looking for. I'm probably not searching for the right terms. I have a small table that looks like this
+----+------+-------+| ID | TYPE | COLOR || 1 | dell | black || 2 | acer | green || 3 | dell | red || 4 | dell | blue || 5 | hp | white || 6 | hp | brown |+----+------+-------+
Acer1. greenDell1. black2. blue3. redHP1. brown2. white
5/4/2009 8:28:47 AM
http://us3.php.net/manual/en/mysqli-result.fetch-assoc.phpExamples, explanations, etc.
5/4/2009 9:22:55 AM
And here's a slightly ugly, untested solution:
<?php// Connect$mysqli = new mysqli('localhost', 'root', 'PASSWORD', 'tww');// Query string$query = 'SELECT type, color FROM vertigo ORDER BY type, color';// Get the data$result = $mysqli->query($query);// Loop through the data (as an associative array)while ($row = $result->fetch_assoc()){ // Echo type and open ordered list if type is different than previous itteration if (strcmp($row['type'], $prev_type)) { echo '</ol>' . "\n"; echo $row['type'] . "\n"; echo '<ol>' . "\n"; } // Echo color echo '<li>' . $row['color'] . '</li>' . "\n"; // Previous type flag $prev_type = $row['type'];}
5/4/2009 10:05:50 AM
^^ what's the advantage of that over using a foreach loop? also, it won't help if he's not using PHP 5.0.7+/MySQL 4.1.13+ (which he probably is, but it's something to think about)i have no experience with the "improved" functions...are they just as fast?[Edited on May 4, 2009 at 10:06 AM. Reason : arrows ... i need to look at what you posted]
5/4/2009 10:06:12 AM
5/4/2009 10:11:33 AM
^way to mix your data and presentation.
5/4/2009 3:47:01 PM
Hmm?
5/4/2009 4:05:23 PM
5/4/2009 4:17:28 PM
*cry*
5/4/2009 5:14:41 PM
I don't see what you did there.
5/4/2009 5:18:55 PM
5/4/2009 5:18:58 PM
Thanks, Ernie!
5/5/2009 7:40:21 AM