phpmyadmin

資料庫:restaurant

資料表:taipei_eat

 

restaurant.php

<?php
$hostname_restaurant = "localhost";//
$database_restaurant = "restaurant";//
$username_restaurant = "凱";//
$password_restaurant = "admin";//
$link= mysql_pconnect($hostname_restaurant, $username_restaurant, $password_restaurant) or trigger_error(mysql_error(),E_USER_ERROR);
//使用 mysql_pconnect()而不使用mysql_connect( ) 可以省下每次重新開啟資料庫連接的時間
?>

 

index.php

<?php require_once('Connections/restaurant.php'); ?>

<?php
mysql_select_db($database_restaurant, $link);
$sql = "SELECT * FROM taipei_eat";  //在taipei_eat資料表中選擇所有欄位
$result = mysql_query($sql, $link) or die(mysql_error());  // 執行SQL查詢
$row_result = mysql_fetch_assoc($result); //將陣列以欄位名索引
mysql_query("set names utf8"); //將資料庫設定為utf8編碼,防止中文亂碼
?>

<form id="form1" name="form1">
<table border="1">

<tr>
<td>id</td>
<td>name</td>
<td>tel</td>
<td>address</td>
</tr>

<?php do { ?>

<tr>
<td><?php echo $row_result['id']; ?></td>
<td><?php echo $row_result['name']; ?></td>
<td><?php echo $row_result['tel']; ?></td>
<td><?php echo $row_result['address']; ?></td>

<?php } while ($row_result = mysql_fetch_assoc($result));?>
<tr>

</table>
</form> 

<?php
mysql_free_result($result); //釋放查詢結果所佔用的記憶體
?>


參考資料:http://muta1021.wordpress.com/category/php/

相關文章