I have written a db function in my lib as
function RunSQL($sql)
{
define('BASEPATH','TEMP');
include "../../../config/database.php";
/* Connect to the database */
$link = mysql_connect($db['dbname']['hostname'], $db['dbuser']['username'], $db['pwd']['password']);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
mysql_select_db($db['db']['database']) or die(mysql_error());
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)){
$dataset[] = $row;
}
return $dataset;
}
Then in my class, I call this function and try to go through records as:
$rs_transactions = RunSQL($sql);
print_r($rs_transactions);
foreach($rs_transactions as $row)
{
echo "<br><br>...in loop....";
}
Problem is that print_r shows there r three records returned, but in foreach loop, it goes through only for first record. It doesn’t loop for all three records.
What could be wrong?