My First Test of Php Linking to MySql



the program:

<html>
<head>
<title>MyFirstTestInPhpLinkMySql</title>
</head>
<body>
<H1>o(-)_(-)o,我的php代码第一次连接MySql</H1>
<?php

$connect =@mysql_connect('localhost','root',"") or die('Unable to connect database server');
mysql_select_db('test') or die('Unable to connect database server');
$query ='SELECT * FROM friends';
$result = mysql_query($query);
if(mysql_error())
{
  echo "ERROR:".mysql_error()."     ".mysql_error();
  
}
else
{
  $rowno =mysql_num_rows($result);
  if(!$rowno)
  {
      echo "<front color =red>对不起,没有找到记录!</front>";
	  
  }
  else
  {
    $fieldno=mysql_num_fields($result);
	$tbname=mysql_field_table($result,0);
	mysql_data_seek($result,0);
	echo "我现在有".$rowno."个朋友记录在库";
	echo "<table border=1 bgcolor=grey>";
	echo "<caption>$tbname</caption>";
	//echo "<th>";
	echo "<tr>";
	for($i=0;$i<$fieldno;$i++)
	{
	   echo  "<th>".mysql_field_name($result,$i)."</th>";
	   
	}
	echo "</tr>\n";//一行一行的来
	echo "</th>";
	echo "<tbody>";
	while($row=mysql_fetch_row($result))
	{
	   echo "<tr>";
	   for($i=0;$i<$fieldno;$i++)
	   {
	     echo  "<td>$row[$i]</td>";//td是表格标准单元格
		 
	   }
	   echo "</tr>";
	}
	echo "</tbody>";
	
	
  }
}
?>
<H1>测试</H1>
</body>
</html>


some picture of the table :



the display of the result  on the web



good good study DDup~~~

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值