PDA

View Full Version : db => multidimensional Array



Jubba
January 24th, 2003, 08:54 PM
I would like to take my information from my db query and convert it into a mulitdimensional array. Not sure if its even possible...

Code:


<?
$userID = mysql_connect("localhost", "userName", "userPass");
mysql_select_db("dbName", $linkID);

$resultID = mysql_query("SELECT nID, nText, nLink, nTarget FROM links", $userID);

for($x= 0; $x < mysql_num_rows($resultID); $x++)
{
$row = mysql_fetch_assoc($resultID);
$nOuter = array(
$nInner[$x] = array("nText" => $row[nText], "nLink" => $row[nLink], "nTarget" => $row[nTarget]);
)
}

print $nOuter[0][nText];
?>


Parse error: parse error, expecting `')'' on line 11

Cheers,

Jubba
January 25th, 2003, 03:32 PM
I fixed my problem. Its not really the way I wanted to go, but it will probably turn out to be more useful.


<?
$linkID = mysql_connect("localhost", "userName", "userPass");
mysql_select_db("dbName", $linkID);

$resultID = mysql_query("SELECT nID, nText, nLink, nTarget FROM links", $linkID);

$nTextA = array();
$nLinkA = array();
$nTargetA = array();

for($x= 0; $x < mysql_num_rows($resultID); $x++)
{
$row = mysql_fetch_assoc($resultID);
array_push($nTextA, "\"nText\" => $row[nText]");
array_push($nLinkA, "\"nLink\" => $row[nLink]");
array_push($nTargetA, "\"nTarget\" => $row[nTarget]");
}

print $nTextA[2]."<br>";
print $nLinkA[1]."<br>";
print $nTargetA[0]."<br>";

?>