Re: OK, have to have this done by 5... SQL help please
| From: | Andrian Pervazov | Date: | Fri, 01 Sep 2000 20:22:20 +0000 |
| Subject: | Re: OK, have to have this done by 5... SQL help please | ||
| References: | 1 | Groups: | php.windows |
| Request: | Send a blank email to php-windows+get-2374@lists.php.net to get a copy of this message | ||
SELECT DISTINCT might help you.
Andrian
"Asendorf, John" wrote:
>
> 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";
>
> }
>
> ?>
>
> --
> PHP Windows Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-windows-unsubscribe@lists.php.net
> For additional commands, e-mail: php-windows-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net