Php mysql query need help pls

hello all,

I am struggling to display mysql table data as i want to be. I have a table as below:

Table: product

ID…Album Name…Album Image
1 …Name1…name1.jgp
2 …Name2…name2.jgp
3 …Name3…name3.jgp
4 …Name4…name4.jgp
5 …Name5…name5.jgp

I want to display data on my page as below:

name1.jpg----------name1.jpg---------name3.jpg
Name1 ------------Name2 ---------- Name3

I want to display the image first and the album name under the image and three product in a row. I am trying with the following code:


<?php
include "dbconnect.php";
$link=dbconnect();

$query=("select *from playlist");
$result=mysql_query($query);
while ($row = mysql_fetch_array($result))
      {
            if ($count > 0 && $count % 3 == 0)
                  {
                      echo "<br>";
                      echo "<br>";
                  }
 
 echo "<img src=../admin/uploads/".$row['image'] ." width='120' height='130' >";
 echo '<a href="dandl.php?artist=' . urlencode($row['artist']) .'& album='.urlencode($row['album']). '">'. $row['album']. '</a> ';

$count++;
  
}
?>

this code giving me output as:

name1.jpg Name1---------name2.jpg Name2--------------name3.jpg Name3

Can anyone help me please?

hi thanks for your reply. i did use <br> but it doesnt work. and your code give me an output like 1 product in a row as:

name1.jpg
Name1

name2.jpg
Name2

name3.jpg
Name3

But I want to output as:

name1.jpg name2.jpg name3.jpg
Name1 Name2 Name3

i want 3 product in a single row with image of the product and name of the product under image. plss need help.

I think the op wants 3 albums per row and you can use less code if you don’t use tables.

echo “<img src=…/admin/uploads/”.$row[‘image’] ." width=‘120’ height=‘130’ >“; echo ‘<a href="dandl.php?artist=’ . urlencode($row[‘artist’]) .‘& album=’.urlencode($row[‘album’]). '”>'. $row[‘album’]. ‘</a> </br>’;

add a </br> at the end

or you can always use a table for layout

while ($row = mysql_fetch_array($result))
{

if ($count &gt; 0)                   
{                       
echo "&lt;table&gt;";                   
}    

echo “<tr>”;

echo “<td>”;
echo “<img src=…/admin/uploads/”.$row[‘image’] ." width=‘120’ height=‘130’ >";
echo “</td>”;

echo “<td style=‘width:30px;’>”;//spacer
echo “</td>”;

echo “<td>”;
echo ‘<a href="dandl.php?artist=’ . urlencode($row[‘artist’]) .‘& album=’.urlencode($row[‘album’]). ‘">’. $row[‘album’]. '</a> ';
echo “</td>”;

echo “</tr>”;

$count++;
}
echo “</table>”;

not sure if the code above is correct, but you get the idea

You haven’t initialised $count before this line:

if ($count > 0 && $count % 3 == 0)

And to display the links below the image you could either wrap the links in a block level element like a div or better still just “display: block” those links in the css.

You can use an unordered list with fixed li width.

<html>
<head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <style type="text/css">
                .list { width: 330px; }
                .list li { float: left; width: 100px; text-align: center; margin: 0 4px; }
                .list img { width: 100%; }
        </style>
</head>
<body>
<ul class="list">
        <li><img src="test.jpg" />description</li>
        <li><img src="test.jpg" />description</li>
        <li><img src="test.jpg" />description</li>
        <li><img src="test.jpg" />description</li>
        <li><img src="test.jpg" />description</li>
        <li><img src="test.jpg" />description</li>
</ul>
</body>
</html>

hello all,

I am using the following code to retrieve mysql data and show on my page…


<?php
include "dbconnect.php";
$link=dbconnect();
$result = mysql_query("SELECT * FROM playlist where date= '2011-09-06'") 
or die(mysql_error());   

echo "<table width = 100% border = '0' cellspacing = '2' cellpadding = '0'>";

while ($friendList = mysql_fetch_array($result)) {

echo "<tr>"

. "<td><a href='memberindex.php?id = ".$friendList['id']."'><img src='".$friendList['image']."' title='".$friendList['artist']."' alt='".$friendList['album']."'/><br />".$friendList['album']."</a><br /></td> " 

. "</tr> ";

}
echo "</table> "; ?>

this code retrieve image and album name from the table and display as below:

id 1
image1
album1

id 2
image2
album2

id 3
image3
album3

but i want to display the info as below:

id1-----------------id2---------------id3
image1------------image2-----------image3
album1------------album2-----------album3

i want image and album name of a product as column but other product as rows. I hope you understand. anyone can help me with this please?

Are you sure you have the right php code? because the code you posted only outputs an image link and the album name and not the id as you say it does.

Have a look at the suggestions in your other thread where you ask the same question