ログインしてさらにmixiを楽しもう

コメントを投稿して情報交換!
更新通知を受け取って、最新情報をゲット!

パソコンで分からない事がある人コミュのよろしくお願いします

  • mixiチェック
  • このエントリーをはてなブックマークに追加
はじめまして。今Perlの授業をとっているのですがMySQLが出てきたからわけが分からなくなりました。今やってるのはMySQLにはいっている表をブラウザーに出力するというものですが表の列の名前(<th>で出す)の部分がどうやっても出ません。以下のプログラムでは表の中身しか出てきません。どうすればいいのでしょうか。よろしくお願いします。

#!/usr/bin/perl -Tw
use DBI;

chomp ( $in = <STDIN> );
$in = "&$in&";

$st = DBI->connect ( "DBI:mysql:201fHitoM:gradebot.byuh.edu", "201fHitoM", "wat\
er" ); #this line should be fixed

print "content-type: text/html\n
<html><head><title>Table Viewer</title>
</head><body>
<h1>Table Viewer</h1>
Please select a table for viewing.
<form method=post>\n";
tableButtons();

if ( $in =~ /$table=([^&]+)&/ ){
tableRows($1);}

print"</body></html>\n";
$st->disconnect();

sub tableButtons {
$q1 = $st->prepare ( "show tables" );
$q1 ->execute();
while ( @z = $q1->fetchrow_array() ){
print "<input type=submit";
print " name=table value='$z[0]'>\n"; }
$q1->finish();
}
sub tableRows {
my ( $table ) = @_;
print "<h1>Content of Table $table</h1>
<table border=1>\n";
$heading = "desc $table";
$query = "select * from $table";
$q2 = $st->prepare ( $query );
$q3 = $st->prepare ( $heading );
$q2->execute();
$q3->execute();
while (@z = $q2->fetchrow_array() ) {
print "<tr>";
print "<th>$z[0]";
foreach $cell ( @z ) {
print "<td>$cell"}
print "\n";}
$q2->finish();
print "</table>\n";
}

コメント(0)

mixiユーザー
ログインしてコメントしよう!

パソコンで分からない事がある人 更新情報

パソコンで分からない事がある人のメンバーはこんなコミュニティにも参加しています

星印の数は、共通して参加しているメンバーが多いほど増えます。

人気コミュニティランキング