"distinct" sql using php and postgres

admin

Administrator
Staff member
I would LOVE if someone could tell me why the "distinct" sql command is not retreaving data only once like it should in this script. this script selects the "level" entered for each entry out of the "scholarship" table located in the "funds" database. i thought that perhaps i needed to specify the field "level" rather than use the * but that created an error and didnt allow the select box to be populated by the db. then i tried to use the $option instead of the * but that basically came out with the same error. then i tried changing the spacing and THAT didnt work at all. if someone can help or even has a self populating script i could use - that would be so excellent, thanks for any help.
--------------------------------------------
<?php
$table="scholarship"; // name of the table
$limit="20"; // limit # of records in select box
$orderBy="schol_id"; // Usually a column name
$conn = pg_connect("","","","","funds");
if
(!$conn)
{echo "Could not make a connection";exit;}
$sql = "SELECT DISTINCT * FROM $table order by $orderBy;";
$select_box = pg_Exec($conn, $sql);
$numrecords = pg_NumRows($select_box);
echo "<select name=select>";
//pre selected option
echo"<option value=http://www.phpbuilder.com/board/archive/index.php/none>select type</option>";
//loop through database to populate select box
for ($j=0; $j < $numrecords; $j++) {
$value = pg_result($select_box, $j, "level"); //column name for the value of the checkbox
$option = pg_result($select_box, $j, "level"); // select option column name
echo"<option value=$value>$option</option>";
}
echo"</select>";
?>
--------------------------------------------
 
Top