web2py vs PHP
In PHP
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. | <html><body><h1>Records</h1> mysql_connect(localhost,username,password); @mysql_select_db(database) or die( "Unable to select database"); $query="SELECT * FROM contacts"; $result=mysql_query($query); mysql_close(); $i=0; while ($i < mysql_numrows($result)) { $name=mysql_result($result,$i,"name"); $phone=mysql_result($result,$i,"phone"); echo "<b>$name</b><br>Phone:$phone<br><br><hr><br>"; $i++; } ?></body></html> |
In web2py
1. 2. | def contacts(): return HTML(BODY(H1('Records'),db().select(db.contacts.ALL))) |
HTML, BODY, H1, etc. are helpers that build HTML tags. SQLTABLE is a special helper that can render as HTML TABLE any set of records.