How to loop through the directive?

hi,
i have to put the all data in the form of a HTML table by getting from the mysql table.

but based on the id of the row, i want to display the image stored in the directive and is fetched directly and display the image and populate the img src=‘-path to that image related to that row-’.
And if the image related to that id, id not available in the directive it will display ‘no image’ message in that appropriate column of that row…

How to do this?

Can you show us the php code you have that displays the table?


$sql = "SELECT * FROM $tbl_name";
$result = mysql_query($sql);
echo "<table width=500 align=center class=maintxt border=0 cellpadding=5 cellspacing=2>";
	print "<tr>";
	print "<td bgcolor=#FFF8DC align=center>&nbsp;&nbsp;<B>SELECT</B>&nbsp;&nbsp;</td>";
	print "<td bgcolor=#FFF8DC align=center><B>ID</B></td>";
	print "<td bgcolor=#FFF8DC align=center><B>NAME</B></td>";
	print "<td bgcolor=#FFF8DC align=center><B>TYPE</B></td>";
	print "<td bgcolor=#FFF8DC align=center><B>OHMS</B></td>";
	print "<td bgcolor=#FFF8DC align=center><B>CONNECTOR TYPE</B></td>";
	print "<td bgcolor=#FFF8DC align=center><B>LABEL</B></td>";
	print "<td bgcolor=#FFF8DC align=center><B>IMAGE</B></td>";	
	print "</tr>";


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

		// Your while loop here
			if($i == 0)
			{
			$bgcolor = '#DCDCDC';
			$i = 1;
			}
			else
			{
			$bgcolor = '#f5f5f5';
			$i = 0;
			}
			print "<tr>";
			print "<td bgcolor='$bgcolor' align=center>";
			print "<input name='select[]' value='{$row['id']}' type='checkbox'>";
			print "</td>";
			print "<td bgcolor='$bgcolor' align=left>";
			echo $row['id'];
			print "</td>";
			print "<td bgcolor='$bgcolor' align=left>";
			echo $row['catid1'];print "<input name='catid' value='{$row['catid1']}' type='hidden'>";
			print "</td>";
			print "<td bgcolor='$bgcolor' align=left>";
			echo  $row['catid2'];
			print "</td>";
			print "<td bgcolor='$bgcolor' align=left>";
			echo $row['catid3'];
			print "</td>";
			print "<td bgcolor='$bgcolor' align=left>";
			echo $row['catid4'];
			print "</td>";
			print "<td bgcolor='$bgcolor' align=left>";
			echo $row['label'];
			print "</td>";
			// here i want to write the code to fetch the image related to the row_id.(means image_name in the directory as 1.gif, 2.gif, ----)
			print "</tr>";

		}
	?>
</table>