Hey guys,

I have this code which gets some reults from a table and displays them:

echo "<table><tr>";

while($col = mysql_fetch_array($columns)){
echo "<th>".$col['COLUMN_NAME']."</th>";
echo "</tr>";
while($row = mysql_fetch_array($data)){
echo "<tr>";
foreach($row as $r){
echo "<td>".$r."</td>";
echo "</tr>";

echo "</table>";

Getting the column names is fine, but with the actual results it displays it twice for example:

Column1 Column2 Column3
result1 result1 result2 result2 result3 result3
result1 result1 result2 result2 result3 result3

Why is this happening?

Thanks in advance for any help. :)

Can you please provide your mysql query?
It looks fine I think.
And if not, i've little bit strange solution.
But just for last chance.

my $data query is:

$data = mysql_query("SELECT * FROM ".$table) or die(mysql_error());

mysql_fetch_array() pulls the resource as an associative array and as a numbered array, try changing it to mysql_fetch_assoc()

commented: good spot +14

ahhh yes. Thank you very much, works perfectly :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.