Need Help displaying mysql query

Hello,

I have a table which holds all the album name of diffferent artist. I have the following code:



          <?php
                include "dbconnect.php";
                $link=dbconnect();
                $query=("select *from  album group by artist;");
                $result=mysql_query($query);
                if(!mysql_num_rows($result))
                        {
                                echo"<script>alert (\\"No Record Found!!!\\");history.go(-1)</script>";

                        }
                else
                        {
						
					while ($row=mysql_fetch_array($result))
                      {
                    
                    echo $row["artist"];                       
                     }
					 }

                     ?>

                     

the above code works but it displays :

Metallica
Ironmaiden
Dream theatre
Bonjovi
GNR
Doors

but I want it to be display as:

Metallica Ironmainden Dream theatre

Bonjovi GNR Doors

Also i want to have a link with every name which will represent itself.

anyone can help me please??

So, 3 per row?

$count = 0;
while ($row = mysql_fetch_array($result)) {

  //every 3rd iteration of this loop, print a line break
  if ($count > 0 && $count % 3 == 0) {
    echo "<br />";
  }

  echo '<a href="something.php?artist=' . urlencode($row['artist']) . '">' . $row['artist'] . '</a> ';

  $count++;
}

$st = $db->query("SELECT DISTINCT artist FROM album");
$artists = $st->fetchAll(PDO::FETCH_ARRAY);

$split = array_chunk($artists, 3);
foreach($split as $v) {
    echo implode(' ', $v);
    echo '<br>';
}

Hi Dan,

Thank a lot its working perfectly. would you please mind to help me a bit more.

How can get the variable artist in something.php?


echo $_GET['artist'];

Thanx rajug.