PHP MySQL Used Function Database Query ถ้าผมอยากทำ list ผมต้องใส่ loop ตรงไหนครับ
ลองแบบนี้ดูครับ
Code (PHP)
<?
/**** function connection to database ****/
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
/**** function select record ****/
function fncSelectRecord($strTable,$strCondition)
{
$strSQL = "SELECT * FROM $strTable WHERE $strCondition ";
$objQuery = @mysql_query($strSQL);
if(!$objQuery)
{
echo "Record not found<br>";
}
else
{
while($result = mysql_fetch_array($objQuery)){
echo "Customer Detail.<br>";
echo "CustomerID = $result[CustomerID]<br>";
echo "Name = $result[Name]<br>";
echo "Email = $result[Email]<br>";
echo "CountryCode = $result[CountryCode]<br>";
echo "Budget = $result[Budget]<br>";
echo "Used = $result[Used]<br>";
echo "<br>===========================<br>";
}
}
}
?>
Code (PHP)
<html>
<head>
<title>ThaiCreate.Com PHP & MySQL Tutorial</title>
</head>
<body>
<?
include("phpMySQLFunctionDatabase.php");
//**** Call to function select record ****//
$strTable = "customer";
$strCondition = " CustomerID = 'C005' ";
fncSelectRecord($strTable,$strCondition);//เรียกใช้ฟังก์ชัน
echo "<br>===========================<br>";
@mysql_close($objConnect);
?>
</body>
</html>
ประวัติการแก้ไข 2012-08-15 15:39:23
Date :
2012-08-15 13:41:12
By :
arm8957
แบบนี้นิ(ใช่ไหมพี่ mr.win)
Code (PHP)
<?
/**** function connection to database ****/
$objConnect = mysql_connect("localhost","root","root") or die("Error Connect to Database");
$objDB = mysql_select_db("mydatabase");
/**** function select record ****/
function fncSelectRecord($strTable,$strCondition)
{
$strSQL = "SELECT * FROM $strTable WHERE $strCondition ";
$objQuery = @mysql_query($strSQL);
$resultArray=array();
while($obResult = mysql_fetch_array($objQuery))
{
array_push($resultArray,$obResult);
}
return $resultArray;
}
?>
Date :
2012-10-23 11:44:38
By :
dekkuza
Load balance : Server 03