On Tuesday, 23 December 2014 17:24:12 UTC+11, Dave S wrote:
>
>
>
> On Wednesday, December 17, 2014 12:17:53 PM UTC-8, Oliver wrote:
>>
>> I'm getting "None" printed in the webpage. I'm trying to print all 
>> first_name in the users table database.  I'm trying to follow the select 
>> section in 
>> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer#Query--Set--Rows
>>
>> I'm using MySQL for database and have few test records inserted in the 
>> users table.  Please let me know what am I missing in the controller.  I 
>> appreciate your help.  Thanks
>>
>

Just to pick up on what Dave said ... where are you looking to see the 
output from 'print'?
in web2py controllers usually return variables which are packed into an 
HTML page via a view (in development mode, running on a local server such 
as the one built in to web2py, default views work fine). 
Because you are not returning any value, the view shows None. 

Carefully re-read the introductory parts of the book if this doesn't make 
sense. You may notice that you can do
return locals()
at the end of your controller, which with a default developer view will 
show all your local variables. 
you could then do

    rows = db.select(....)
return locals()

The rows will then show up in your view.




You can use print. It will write output to the python console. Where you 
see this depends on what your development environment is. 


 

>
>>
>> *My Model: *
>>
>> db.define_table('users',
>>                 Field('first_name', 'text'),
>>                 Field('last_name', 'text'))
>>
>> *My Controller:*
>>
>> def printall():
>>         for row in db(db.users.id > 0).select(db.users.ALL):
>> print row.first_name
>>
>> or
>>
>> def printall():
>>     for row in db().select(db.users.ALL):
>> print row.first_name
>>
>
>
> You are trying to print to the console for development purposes?
>
> If you are showing a "None" as your result, then it appears your query 
> isn't selecting any rows.  If you use the command line interface to your DB 
> (sqlite3?) can you form a SQL SELECT command that retrieves the records you 
> want?  If so, can you paste that command here?
>
> /dps
>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to