CGI中的Ruby中断线路



这是我的脚本

#!/usr/bin/env ruby
require 'sqlite3'
print "Content-type: text/htmlrnrn"
print "<html><body>Hello Stack Overflow<p></body></html>rn"
database = SQLite3::Database.new( "new.database" )
database.execute( "create table new_table (id INTEGER PRIMARY KEY, content TEXT);" )
database.execute( "insert into new_table (content) values ('this is a stack')")
database.execute( "insert into new_table (content) values ('this is overflow')")
rows = database.execute( "select * from new_table" )
p rows

这有效,但在一行中打印行。我想增加一个线路,但我不知道如何。html tag

不起作用, n都没有。

您可以帮忙吗?

从您的问题中,我知道您要按行打印rows变量的内容,如果是,则可以将rows视为数组变量,并将eachrow一起使用。

例如,

rows.each do |x|
   print "#{x}n"
end

如果对您有帮助。

<br>将完成工作,因为您正在打印html。

rows.each do |row|
   print row + '<br>'
end

最新更新