|
 |
|
โชว์ทุก Reccord ยังไง โดย Loop While กับ function fncSelectRecordAll() |
|
 |
|
|
 |
 |
|
Code (phpMySQLFunctionClassDatabase.php)
<?
/**** Class Database ****/
Class MyDatabase
{
/**** function connect to database ****/
function MyDatabase($strHost,$strDB,$strUser,$strPassword)
{
$this->objConnect = mysql_connect($strHost,$strUser,$strPassword);
mysql_query("SET NAMES TIS620");
$this->DB = mysql_select_db($strDB);
}
/**** function select record ****/
function fncSelectRecordAll()
{
$strSql = "SELECT * FROM $this->strTable ";
$query = @mysql_query($strSql);
$num = @mysql_num_rows($query);
$resultArray = array();
for ($i = 0;$i<$num;$i++) {
$result = mysql_fetch_array($query);
array_push($resultArray,$result);
}
mysql_free_result($query);
return $resultArray;
}
/*** end class auto disconnect ***/
function __destruct() {
return @mysql_close($this->objConnect);
}
}
?>
Code (phpMySQLUsedFunctionClassDatabase.php)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
include("phpMySQLFunctionClassDatabase.php");
//**** New class database ****//
$strHost = "localhost";
$strDB = "mydatabase";
$strUser = "root";
$strPassword = "root";
$clsMyDB = new MyDatabase($strHost,$strDB,$strUser,$strPassword);
//**** Call to function select record ****//
$clsMyDB->strTable = "customer";
$resultList = $clsMyDB->fncSelectRecordAll();
foreach ($resultList as $eachResult)
{
echo $eachResult["Field1"];
echo $eachResult["Field2"];
echo $eachResult["Field3"];
}
echo "<br>===========================<br>";
?>
</body>
</html>
|
 |
 |
 |
 |
Date :
2009-03-25 09:38:52 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ได้แล้วครับ ขอคุณมากๆครับคุณ WIN ขอให้เว็บมาสเตอร์ จงเจริญๆ ร่ำรวยๆครับ 
|
 |
 |
 |
 |
Date :
2009-03-25 10:03:16 |
By :
paejung |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|