-------------------------------------------------------------------
<html>
<head>
<META HTTP-EQUIV="content-type" CONTENT="text/html; charset=utf-8">
</head>
<?php
$server = '127.0.0.1';
$username = 'root';
$password = 'root';
$link = mysql_connect($server, $username, $password);
if (!$link) {
die('can not connect : ' . mysql_error());
}
echo 'successfully connected';
$db_selected = mysql_select_db('stock_db',$link);
if (!$db_selected){
die('fail to select database'.mysql_error());
}
$result = mysql_query('SELECT * FROM stock');
if (!$result) {
die('query fail'.mysql_error());
}
$numFields = mysql_num_fields($result);
print("<br>num of fields:");
print($numFields);
$nameFields = array();
for($i=0;$i<$numFields;$i++){
$nameFields[] = mysql_field_name($result, $i);
}
print("<br>");
print("<table border=1>");
print("<tr>");
for($j=0;$j<$numFields;$j++){
print("<td>");
print($nameFields[$j]);
print("</td>");
}
print("</tr>");
while ($row = mysql_fetch_assoc($result)) {
print("<tr>");
for($j=0;$j<$numFields;$j++){
print("<td>");
print($row[$nameFields[$j]]);
print("</td>");
}
print("</tr>");
}
print("</table>");
mysql_close($link);
?>
</html>
-------------------------------------------------------------------
0 件のコメント:
コメントを投稿