user9871124
user9871124

Reputation:

Reapeated result in Sql query

I have an sql query to retrieve data of a particular type ...it goes fine except it repeats the result twice..why??

Here's my code:

<?PHP  REQUIRE 'attemptsql.php'  ?>
<?php
$query="SELECT DISTINCT person   FROM kid WHERE Subs=0";
$results = mysql_query($query);
while ($row = mysql_fetch_array($results)) {

foreach($row as $field) {
    echo  htmlspecialchars($field) ;
}




}

Like I said its ok but instead od th result being:

Dan

I get:

DanDan

Note:I only have one record named"Dan"

Thanks.

Upvotes: 3

Views: 45

Answers (1)

D-Shih
D-Shih

Reputation: 46219

You don't need foreach just only use while

<?PHP  REQUIRE 'attemptsql.php'  ?>
<?php
$query="SELECT DISTINCT person   FROM kid WHERE Subs=0";
$results = mysql_query($query);
while ($row = mysql_fetch_array($results)) {
    echo  htmlspecialchars($row["person"]) ;
}

Upvotes: 2

Related Questions