Hi
Hier soll eine Funktion für einen User mehrere Konten aus einer Tabelle lesen und in ein Array packen. Der erste (numerische Index) ist für ein Konto eindeutig, der zweite ("Text"-Index) entspricht den Tabellenfeldern für dieses Konto. Aber das ansprechen danach klappt einfach nicht. Bei mir sieht das ganze etwas kompliziert aus, da ich jeweils die Spaltennamen der einzelnen Tabellen in einer Setup Datei definiere. Wieso kann ich auf die Daten nicht zugreifen obwohl Daten vorhanden wären?!
PHP-Code:
function getAccounts($intUserID, $intAccountCategory){
global $tblAccounts;
$sql = "SELECT * FROM " . $tblAccounts['TableName'] . " WHERE " . $tblAccounts['TypeID'] . " = $intAccountCategory AND " . $tblAccounts['UserID'] . " = $intUserID";
if(strlen($intAccountCategory) == 0){
return false;
} else {
if(!$res = mysql_query($sql)){
die("SQL Error in Function getNumAccounts: $sql");
} else {
if(mysql_affected_rows() > 0){
$arrAccounts = array();
$intCounter = 0;
while($row = mysql_fetch_array($res)){
$arrAccounts[$intCounter] = array();
$arrAccounts[$intCounter][$tblAccounts['Institution']] = $row[$tblAccounts['Institution']];
$arrAccounts[$intCounter][$tblAccounts['Name']] = $row[$tblAccounts['Name']];
$arrAccounts[$intCounter][$tblAccounts['Nr']] = $row[$tblAccounts['Nr']];
$arrAccounts[$intCounter][$tblAccounts['IBAN']] = $row[$tblAccounts['IBAN']];
$arrAccounts[$intCounter][$tblAccounts['BIC']] = $row[$tblAccounts['BIC']];
$arrAccounts[$intCounter][$tblAccounts['Added']] = $row[$tblAccounts['Added']];
$arrAccounts[$intCounter][$tblAccounts['StartingBalance']] = $row[$tblAccounts['StartingBalance']];
$arrAccounts[$intCounter][$tblAccounts['CurrentBalance']] = $row[$tblAccounts['CurrentBalance']];
$intCounter++;
}
return $arrAccounts;
} else {
return false;
}
}
}
}
Der Zugriff über zbsp:
PHP-Code:
$arrAccounts = getAccounts(1,1);
echo $arrAccounts[0][$tblAccounts['CurrentBalance']];
Da gibt es aber keinen Output
