Iterating through DB rows by column name

vbscript , asp , php Paris, France
  • 9 years 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 a reply

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

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


Why not write for us? Or you could submit an event or a user group in your area. Alternatively just tell us what you think!

Our tools

We've got automatic conversion tools to convert C# to VB.NET, VB.NET to C#. Also you can compress javascript and compress css and generate sql connection strings.

“In theory, theory and practice are the same. In practice, they're not.”