Getting fieldname and value from assoc array?

From: Date: Sat, 07 Oct 2000 06:08:26 +0000
Subject: Getting fieldname and value from assoc array?
Groups: php.general 
Request: Send a blank email to php-general+get-19020@lists.php.net to get a copy of this message
Hi php, I put a result into an associative array ... now I need to get the value and the fieldname from a function without using implode or anything. As far as I understood assoc arrays, after retrieving it via mysql_fetch_array($result, MYSQL_ASSOC) it looks something like this: "Fieldname1", "Value1" "Fieldname2", "Value2" etc. Thus, I thought something like $assoc[x][y] would work ... suddenly recognizing that $assoc[x] delivers the values, but $assoc[x][0] delivers only the first character. Then I fiddled around with key() ... no success. Finally I tried something like for ($i=0; $i<count($detail); $i++) { $field = mysql_fetch_field($result, $i); $value = $detail[$i]; $form->displayText($field->name, $value); echo "<br>"; } That doesn't really work either ... list($key, $val) does the same as $assoc[x] ... it ought to it, I guess ;-) BTW: The purpose of the whole thingy is to get a single record from a database and to display it row by row with looking up some values in additional tables (therefore a function is needed). The function will look something like this: function displayRow($row, $table="") { echo "<tr>"; echo "<td valign=top>[$i] - ".$row[0]."</td>"; echo "<td>[".$row[1]."]</td>"; echo "</tr>\n"; MySql::lookup($field, $table); } So, to put a long story short: How do I get a result from mySql in a form, where I can easily pass key and value pairs to a function without using two methods (s. a.)? Any help is highly appreciated! Cheers, Vince ''' ô¿ô -

« previous php.general (#19020) next »