Getting 3 duplicate records in a drop down

I'm getting 3 records in a drop down even tho there is only one record.

		echo '<select id="company" name = "Broker" width="200" style="width: 200px">';
		$SqlString = "select * from comp order by COMPANY";
		$companies = $conn->query($SqlString);
		while ($row_comp = $companies->fetch_array())
		{
			echo "<option value = \"";
			echo $row_comp['TID'];
			echo "\"";
			if ($row_comp['TID'] == $row_survey_data['TID'])
		 	{
				echo " selected";
			}
			echo ">";						
			echo $row_comp['COMPANY'];
			echo "</option>";
		}
		echo "</select>";
		echo "<br>";

Open in new window


What bothers me is that if it was a loop why only 3 times.  I have the same problem with the "persons" that work for the "company".
breeze351Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Ray PaseurCommented:
What is the data in the database?  Maybe use var_dump() to print out the data.
Kim WalkerWeb Programmer/TechnicianCommented:
Your entire table has only one record? select * from comp order by COMPANY selects the entire table named comp. And if there's only one records, what's the point of the order by clause?
HuaMin ChenProblem resolverCommented:
Try to put

"select distinct ..."

Open in new window

in the SQL statement
OWASP Proactive Controls

Learn the most important control and control categories that every architect and developer should include in their projects.

F PCommented:
$SqlString = "SELECT DISTINCT(`COMPANY`), `TID` FROM `comp` ORDER BY `COMPANY`";

Open in new window


or

$SqlString = "SELECT `COMPANY`, `TID` FROM `comp` ORDER BY `COMPANY` LIMIT 1";

Open in new window


or

$SqlString = "SELECT DISTINCT(`COMPANY`), `TID` FROM `comp` ORDER BY `COMPANY`;";
$companies = $conn->query($SqlString);

while ($row_comp = $companies->fetch_array())
{
	$options .= "<option value='{$row_comp['TID']}'";

	if ($row_comp['TID'] == $row_survey_data['TID'])
 	{
		$options .= " selected='selected'";
	}

	$options .= ">{$row_comp['COMPANY']}</option>";
}

echo <<<HTML
<select id="company" name="Broker" width="200" style="width: 200px">
	{$options}
</select>
<br>
HTML;

Open in new window

Ray PaseurCommented:
If the recommendations from HuaMinChen or Frank Pennock work, you've got duplication in your database table, and "there is only one record" is not a true statement.  SELECT * is a code smell.  You might want to look at this database with something like phpMyAdmin and consider ways of eliminating and preventing duplication.
Chris StanyonWebDevCommented:
I'm with Ray on this one - sounds like your data integrity is shot.

SELECT DISTINCT may work for you, but only if ALL the data you're selecting is distinct (hint: don't use SELECT *). If it is, then you have a problem with your Data. If it's not, then you'll still get duplicate entries in your dropdown.

Maybe post a sample of your data and we can advise accordingly.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
breeze351Author Commented:
Can I kill my partner?  Idiot kept updating the table without removing the previous records.  Day and a half trying to figure this out!!!!!!!!
Ray PaseurCommented:
No, I don't think you can kill your partner.  But going forward, when you have a data-dependent problem, please post your test data here along with your expected output and your question.  This is called the SSCCE and it's a good habit to cultivate because it will really save you a lot of time.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.