adsense

2011-04-19

[php] 4/18上課內容


$host = "localhost";
$user = "root";
$password ="";
$link = mysql_pconnect($host,$user,$password)
or die ("mysql連線失敗:".mysql_error());
 mysql_select_DB("MY_database",$link) or die("資料庫選擇失敗:".mysql_error());

 $result = mysql_query("create table ed as select e.departmentid, d.name dname,e.employeeid,e.name ,e.salary
 from employees e, departments d
 where e.departmentid=d.departmentid
 order by departmentid",$link);

$result1 = mysql_query("select min(salary) as salary from ed group by departmentid" , $link) ;
if(mysql_num_rows($result1)== 0)
{
echo "無資料可顯示
";
exit(1);
}
$i=0;
while ($row = mysql_fetch_object($result1))
{
$temp[$i] = $row-> salary;  /*row 裡面的salary*/
//echo"br";
$i=$i + 1 ;
}
//echo $temp[0]."br";
$i = 0;
while (count($temp) > $i)
{
$result2 = mysql_query("select * from ed where salary in (".$temp[$i].")",$link);
if(mysql_num_rows($result2) == 0)
{
echo "無資料可顯示
";
exit(1);
}
while ($row1 = mysql_fetch_object($result2))
{
echo $row->departmentid;
echo ", ".$row1->dname;
echo ", ".$row1->employeeid;
echo ", ".$row1->name;
echo ", ".$row1->salary;
echo "
";
}
$i = $i +1;
}
?>

沒有留言:

張貼留言