⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 用perl生成wml(转自httplyy00.yeah.net)3.txt

📁 C&C++论坛精华
💻 TXT
字号:
作者:asp2001
email: asp2001@163.net
日期:2000-08-03 21:00:09
wap_showpoll.pl
从数据库中取得当前的Poll。它显示问题并产生一个select标签来显示可能的回答。 
#! /usr/bin/perl

use DBI;
# some vars like database password and such
do "somevars.pl";


$head = PrintHeader();
print $head;

print "<wml>";
print "<card id=\"poll\" title=\"Poll\">";
print "<do type=\"prev\">";
print "<prev/>";
print "</do>";
print "<do type=\"options\" label=\"PT Home\">";
print "<go href=\"/wml/index.wml\"/>";
print "</do>";



if ($dbh = DBI->connect( $dbName, $dbUser, $dbPw))
{
  # retrieving current active poll out of the database

  $sth = $dbh->prepare("select text, c from poll_descr where active = '1' order by c");
  $results = $sth->execute() or die "SQL-Error: $DBI::errstr\n";
  if (@result = $sth->fetchrow_array)
  {

    # displaying the question

    $pollNum = $result[1];
    print "<p>$result[0]</p>";
  }
  $sth->finish();

  # retrieving all possible answers and display as a select-field

  $sth = $dbh->prepare("select text, c  from poll_votes where poll_id = $pollNum order by c");
  $results = $sth->execute() or die "SQL-Error: $DBI::errstr\n";
  print "<p><br/><select name = \"num\">\n";
  while (@result = $sth->fetchrow_array)
  {
    print "<option value = \"$result[1]\">$result[0]</option>\n";
  }

  # generating the links for "Vote" and "View Results"

  print "</select></p><p><anchor>Send Vote<go href = \"wap_pollvote.pl\">\n";
  print "<postfield name = \"v\" value = \"\$(num)\"/>\n";
  print "<postfield name = \"num\" value = \"$pollNum\"/>\n";
  print "<postfield name = \"dv\" value = \"dv\"/>\n";
  print "</go></anchor></p>\n";
  print "<p><anchor>View Results<go href = \"wap_pollvote.pl\">\n";
  print "<postfield name = \"v\" value = \"\$(num)\"/>\n";
  print "<postfield name = \"num\" value = \"$pollNum\"/>\n";
  print "</go></anchor></p>\n";
  $sth->finish();
  $dbh->disconnect();
}
else
{
  print "<p>SQL-Error: $DBI::errstr</p>\n";
}

print "</card></wml>";



sub PrintHeader{
  my($header);

  $header = "Content-type: text/vnd.wap.wml\n\n";
  $header .= "<?xml version=\"1.0\"?>";
  $header .= "<!DOCTYPE wml PUBLIC \"-//WAPFORUM//DTD WML 1.1//EN\"";
  $header .= " \"http://www.wapforum.org/DTD/wml_1.1.xml\">\n";
  return $header;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -