Community discussion forum

Iterating through DB rows by column name

  • 8 months ago
    Disclaimer: I'm new to ASP, having a strong background in PHP & Java... I'd like to know how to do the equivalent of iterating through a result of database rows, setting values according to column names. I've found examples of extracting column names from a DB result, but not accessing array indexes by column names... A (very primative) equivalent in PHP would be : while ($row = mysql_fetch_assoc($result)) { echo "Column1 : " . $row['column1']; echo "Column2 : " . $row['column2']; echo "Column3 : " . $row['column3']; } Although what I really want to be doing is setting an object's properties given a DB row: function init_from_db($row) { $this->set_id($row['id']); $this->set_name($row['name']); // ... etc } Thanks in advance.
    Post was edited on 04/03/2009 09:40:58 Report abuse

Post a reply

No one has replied yet! Why not be the first?

Sign in or Join us (it's free).

Want to stay in touch with what's going on? Follow us on twitter!