Sunday, June 24, 2012

Select Query Fetch multiple result function


<?php
mysql_connect("localhost","root","");
mysql_select_db("fetch");

function fnFetchMultipleResults($resResource, $strFetchType = 'ARR')
{
$resResource = mysql_query($resResource);
$intRows = mysql_num_rows($resResource);
if($intRows > 0)
{
if($strFetchType == 'OBJ')
{
while($arrRecord = mysql_fetch_object($resResource))
{
$arrResults[] = $arrRecord;
}
}
else if($strFetchType == 'ARR')
{
while($arrRecord = mysql_fetch_assoc($resResource))
{
$arrResults[] = $arrRecord;
}
}
}
else
{
$arrResults = array();
}

return $arrResults;
}
function fnFetchSingleResult($resResource, $strFetchType = 'ARR')
{
$resResource = mysql_query($resResource);
$intRows = mysql_num_rows($resResource);
if($intRows > 0)
{
if($strFetchType == 'OBJ')
{
$arrRecord = mysql_fetch_object($resResource);
}
else if($strFetchType == 'ARR')
{
$arrRecord = mysql_fetch_assoc($resResource);
}
}
else
{
return array();
}
return $arrRecord;
}

$sqlQuery = "SELECT * FROM `fetch`";
$arrRes = fnFetchMultipleResults($sqlQuery, $strFetchType = 'ARR');
print_r($arrRes);
?>

No comments:

Post a Comment

Please mention your comments.......