First, you are missing double quotes for html attributes. I put them in the code below and they are escaped when also using double quotes as a string delimiter. Since you provided only two fields as a result from your query I prepared a code for a table with two columns. If you want a table with five columns the logic is the same.
<?php
// ...
// beginning of the table
echo '<table>';
while ($row = mysql_fetch_array($retd))
{
$code = $row["code"];
$name = $row["name"];
// beginning of one row
echo '<tr>';
// first cell showing a field from the $row
echo '<td width="150" align="center">';
echo "<a href=\"../item?scode=$code\"><img src=\"pictures/$code.gif\" border=\"0\" alt=\"Item $name\"></a>";
echo "</td>";
// second cell showing a field from the $row
echo "<td width=\"150\" align=\"center\">";
echo "<a href=\"../item?scode=$code\"><span class=\"fs13\">$name</span></a>";
echo "</td>";
// end of one row
echo '</tr>';
}
// end of the table
echo '</table>';
?>
I have tried the method of pritaeas and while I have managed to make 2 coloums (even if I wanted to make 5) but all the data was put in the 1st coloum while the 2nd column was empty.
I have also tried the method of broj1 and it put the picture in 1st coloum and the text in 2nd column.
Now, in one cell i'd like to make the picture and the text. and it is placed in a table which will have 5 columns ( in each column there will be pic & text) then after 5 columns it will begin another row.
if you can help me solve the problem i will really appreciated, since I have been trying to solve this for a long time.
I have prepared a modified code based on the link sent by pritaeas. Note I used a test array since I did not bother to set up a database.
<?php
// test array
$test_array = array();
for($j = 1; $j <= 103; $j++) {
$test_array[$j]["code"] = "CODE-$j";
$test_array[$j]["name"] = "NAME-$j";
}
// counter for cells
$i = 1;
// begin a table
echo '<table border="1">' . "\n";
foreach($test_array as $row)
// while($row = mysql_fetch_array($retd))
{
$code = $row["code"];
$name = $row["name"];
// for 1st, 6th, 11th etc record insert a tag for a new row
if (($i == 1) or (($i - 1) % 5) == 0) {
echo '<tr>' . "\n";
}
// insert a cell
echo("<td width=150 align=center>");
echo ("<a href=../item?scode=$code><img src=pictures/$code.gif border=0 alt=Item $name</a>");
echo ("<a href=../item?scode=$code><span class=fs13>$name</span></a>");
echo("</td>");
// for 5th, 10th, 15th etc record insert a tag for end of the row
if ((($i) % 5) == 0) {
echo '</tr>';
}
// increment $i
$i++;
}
// if there are no records left and the row has not yet been filled, fill it
// with empty cells
while(($i - 1) % 5 != 0) {
// insert a blank cell
echo '<td> </td>';
// increment $i
$i++;
// for 5th, 10th, 15th etc record insert a tag for end of the row
if (($i - 1) % 5 == 0) {
echo '</tr>';
}
}
// end the table
echo '</table>';
?>
Your while loop from the first post should do if it is constructed OK while ($row = mysql_fetch_array($retd)) . Post the table structure and the query you use to get the data.