Hello
I have an SQL query that i want to concatenate the fields and display it in a way that those concatenated fields will be displayed first row will have 4 columns,second row will also have 4 columns....etc. for instance

the query

`SELECT imageurl,
        caption, 
        template
        FROM template;

The Result
imageurl caption template
image001 cap001 temp001
image002 cap002 temp002
image003 cap003 temp003
image004 cap004 temp004
image005 cap005 temp005
image006 cap006 temp006
image007 cap007 temp007
image008 cap008 temp008

I want it to be displayed this way

                cap001      cap002     cap003      cap004
                image001    image002   image003    image004
                temp001     temp002    temp003     temp004

                cap005      cap006     cap007      cap008
                image005    image006   image007    image008
                temp005     temp006    temp007     temp008

I need help i have tried everything i think can me this right but it did not work .

In just plain SQL this may be very difficult. Are you using some (scripting) language too?

yes i am using php

add connection and query here as usual



    if (mysql_num_rows($result) > 0) { 
    echo "<table>"; 
         echo "<thead>";


     echo "<th>ImageURL</th>";
         echo "<th>caption</th>";
         echo "<th>template</th>";
         }
      while ($row = mysql_fetch_assoc($query)) { 
        echo "<tr>";
          echo"<td>$row['col1']</td> <td>{$row['col2']}</td><td>{$row['col3']}</td>";


        echo"</tr>";
      } 
    echo "</table>";  
}
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.