ctsql_fetch_assoc
Fetches a result row as an associative array.
Declaration
array ctsql_fetch_assoc (resource queryID)
Description
ctsql_fetch_assoc() stores the data in associative indexes, using the field names as keys.
If two or more columns of the result have the same field names, the last column will take precedence. To access the other column(s) of the same name, you either need to access the result with numeric indexes by using ctsql_fetch_row() or add alias names. For aliased columns, you cannot access the contents with the original column name (by using ‘field’ in this example).
This SELECT statement demonstrates a query with aliased duplicate field names
SELECT table1.field AS foo, table2.field AS bar FROM table1, table2
Note: Field names returned by this function are case-sensitive.
Returns
Returns an array that corresponds to the fetched row, or FALSE if there are no more rows.
Example
<?php
ctsql_connect("localhost:ctreeSQL") or
die("Failed to connect to FairCom DB SQL: " . ctsql_error());
$result = ctsql_query("SELECT id, name FROM mytable");
while ($row = ctsql_fetch_assoc($result)) {
printf ("ID: %s Name: %s", $row["id"],$row["name"]);
}
ctsql_free_result($result);
?>
See also
ctsql_fetch_row(), ctsql_fetch_array().