Forum OpenACS Development: querying table "users"

Collapse
Posted by Divya R on
Hi pls note below for any mistakes in the code: -
# Displays all details about the user from the database on the screen that is
# stored in a variable content1.

set db [ns_db gethandle]

set selection [ns_db select $db "select user_id,first_names,last_name,screen_nam
e,priv_name,email,priv_email from users"]

set content1 "<table width=100%><tr bgcolor=#c3c3c3<td>User Id</td><td>First Nam
e</td><td>Last Name</td><td>Screen Name</td><td>Private Name</td><td>Email</td><
td>Private Email</td>"

while{[ns_db getrow $db $selection]} {
  set_variable_after_query
  append content1 "
    <tr><td>$user_id</td><td>$first_names</td><td>$last_name</td><td>$screen_na
me</td><td>$priv_name</td><td>$email</td><td>$priv_email</td>"
}

append content1 "</table>"

ns_db releasehandle $db

# Displays all the data.

set page_title "User-Details"

ReturnHeaders

ns_write "

[ad_header Users-Details]

$content1

[ad_footer]
"
Thanks in advance,
Divya

Collapse
Posted by Robert Locke on
Is this meant for OACS 3.x?  Or 4.x?  If the latter, then you should really read the developer's guide and other documentation (especially acs-templating) located in /doc/.  Otherwise, there are several problems with the code:

* the "users" table doesn't have all those fields.  try "cc_users" instead.

* your first <tr bgcolor=... is missing a closing ">" tag.

* all your <tr>'s are missing corresponding </tr>'s.

* it's set_variables_after_query not set_variable_after_query. (you're missing an "s")

I recommend you read the docs, study your error log, debug, etc when you encounter these types of problems.  Best of luck...

Collapse
Posted by Oscar Bonilla on
Also, did OpenACS 3.x include the db API? It would be much simpler to use the db API than using ns_db directly.
Collapse
Posted by Andrew Piskorski on
Divya, you've posted your question in the wrong forum, again. This really belongs in Q&A, not Development.