OK, have to have this done by 5... SQL help please
| From: | Asendorf, John | Date: | Fri, 01 Sep 2000 20:07:59 +0000 |
| Subject: | OK, have to have this done by 5... SQL help please | ||
| Groups: | php.windows | ||
| Request: | Send a blank email to php-windows+get-2372@lists.php.net to get a copy of this message | ||
I've spent the last 10 minutes hunting for an SQL command which will return
all of the unique entries in a column.
I have a table with a list of names and the district in which they are
running... I want to make a group of tables which are separate by
district... I've got all the code I need, BUT, I can't figure out how to
get all the unique districts out of the table - fourth line down -
thanks in advance
John
<?PHP
// create SQL statement for district
$districtSQL = "SELECT firstname,district,office,term,party
FROM 2000_11_candidates
WHERE district"; // WHAT GOES HERE?!?!?!
// prepare SQL statement
$district_result = odbc_prepare($connection,$districtSQL);
// execute SQL statement and get results
odbc_execute($district_result);
//write the table
while (odbc_fetch_row($district_result)) {
$district = odbc_result($district_result,"district");
echo "<table border=\"1\"
cellpadding=\"5\"><caption>${district}</caption><thead>";
echo
"<tr><th>Office</th><th>Name</th><th>Address</th><th>City</th><th>Zip</th>";
echo
"<th>Term</th><th>Party*</th></tr></thead><tbody>";
// create SQL statement for candidates in that district
$candidatesSQL = "SELECT
firstname,office,address,city,zip,term,party
FROM 2000_11_candidates
WHERE district = $district
GROUP BY office";
// prepare SQL statement
$cand_result = odbc_prepare($connection,$candidatesSQL);
// execute SQL statement and get results
odbc_execute($cand_result);
while (odbc_fetch_row($cand_result)) {
$name = odbc_result($cand_result,"firstname");
$office = odbc_result($cand_result,"office");
$address = odbc_result($cand_result,"address");
$city = odbc_result($cand_result,"city");
$zip = odbc_result($cand_result,"zip");
$term = odbc_result($cand_result,"term");
$party = odbc_result($cand_result,"party");
echo "<tr><td>${name}</td>\n";
echo "<td>${office}</td>\n";
echo "<td>${address}</td>\n";
echo "<td>${city}</td>\n";
echo "<td>${zip}</td>\n";
echo "<td>${term}</td>\n";
echo "<td>${party}</td></tr>\n";
}
echo "</tbody></table>\n<P> </P>\n\n";
}
?>