[Resolved] Using foreach &arrays w/ query on multiple ta
Posted: Tue Feb 13, 2007 12:32 pm
I am having a hard time getting php to give me what I want from the database.
It appears that my mssql query is working fine, but that I may be having problems with the array in relation to calling a specific column from a specific table.
Here's the code followed by more explanation:
This returns the following list a bulleted list with 10 titles from the table, "DA_Document". My problem is, when I start trying to use an alias within the foreach, I get errors. eg:
Does this make sense? Would somebody be able to help me?
Thanks.
It appears that my mssql query is working fine, but that I may be having problems with the array in relation to calling a specific column from a specific table.
Here's the code followed by more explanation:
Code: Select all
<?php (Database connections ommited)
mssql_select_db($database, $dbconnect);
$query = "SELECT TOP 10 Res.ResourceID, Res.Title, Res.ShortBlurb, Res.Created, Cat.Title, Doc.Title, Doc.Location ";
$query .= "FROM DA_Resource Res, DA_Category Cat, DA_Document Doc ";
$query .= "WHERE Res.ResourceID = Doc.ResourceID ";
$query .= "AND Cat.CategoryID = Res.CategoryID ";
$result = mssql_query( $query, $dbconnect );
while ($line = mssql_fetch_assoc($result))
{
$return[] = $line;
}
$output = "<html><body><ul>";
foreach ($return as $line)
{ $output .= "<li>$line[Title]</li>
<li>$line[Location]</li>";}
$output .="</ul></body></ul>";
echo $output;
?>Code: Select all
<li>$line[Res.Title]</li>Thanks.