Page 1 of 1

how to add an image in a php table

Posted: Sat Jun 05, 2010 10:35 am
by jerry1984r
hi, in a script, I have a php file, that presents a table of items, for music artists, however, there's something missed in this table, I need to add in the table, an image for the artist... I'm so new weby, and don't know how to do that, however I tried to do something:

Code: Select all

if($this->params->get('showartistshome') || $this->letter != ""){
	?>

	<table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
            <td class="sectiontableheader" align="right" width="5%">#</td>
            <td class="sectiontableheader" width="60%"><? echo JText::_('المرنم'); ?></td>
            <td class="sectiontableheader"  align="right" width="10%"><? echo JText::_('الألبومات'); ?></td>
            <td class="sectiontableheader" align="right" width="10%"><? echo JText::_('المقاطع'); ?></td>
			<td class="sectiontableheader" align="right" width="20%"><? echo JText::_('صورة'); ?></td>
        </tr>      
	<?php
	$k = 1;
	for ($i=0, $n=count( $this->items ); $i < $n; $i++)	{
		$row = &$this->items[$i];
		$link= JRoute::_( 'index.php?option=com_muscol&view=artist&id='. $row->id . $itemid);
		$artist_image = JHTML::image('images/artists/' . $this->artist->image , $this->artist->name , $image_attr );
		?>
        <tr class="sectiontableentry<? echo $k; ?>" >
        	<td align="right"><? echo ($i + 1); ?></td>
        	<td><a href='<?php echo $link; ?>'><?php echo $row->artist_name; ?></a></td>
			<td align="right"><?php echo $row->num_albums; ?></td>
            <td align="right"><?php echo $row->num_songs; ?></td>
			<td align="right"><?php echo JHTML::image('images/artists/' . $this->artist->image , $this->artist->name , $image_attr ); ?> </td>
		</tr>
	<? $k = 3 - $k; } ?>
    </table>
	
when I go to the frontend page, where the script in, it doesn't display the image in the 4th cell, still blank.
so how to correct this.

the .php file is in the attachments.

Re: how to add an image in a php table

Posted: Sat Jun 05, 2010 12:06 pm
by Jonah Bron
If you view the source in your browser, is the <img> tag there at all?

Re: how to add an image in a php table

Posted: Sat Jun 05, 2010 12:12 pm
by jerry1984r
if u mean the sectiontableheader of the img, it tagged there, but it doesn't display the img in it's cell.

Re: how to add an image in a php table

Posted: Sat Jun 05, 2010 12:40 pm
by jerry1984r
here is a Screenshot of the table

Re: how to add an image in a php table

Posted: Mon Jun 07, 2010 4:02 am
by jerry1984r
nobody knows how to do such thing like this ?' :?

Re: how to add an image in a php table

Posted: Mon Jun 07, 2010 5:07 am
by cpetercarter
Since you are using a class JHTML in your code, I guess you are coding for a Joomla site, and you might get more information by posting your question in a Joomla forum.

One thought occures to me, however. You are using $image_attr as the third argument in your call to JHTML::image. But your code does not appear to define $image_attr. You could try omitting the third argument completely (the Joomla documentation says that it is optional); or you could define $image_attr as an empty array :

Code: Select all

$image_attr = array();
If that isn't the problem, please check that you have specified the path to your images correctly. A blank where an image should be often means "I cannot find an image at this address". Also, could you post the html output of your script (click view/page source in Firefox, something similar in IE) so that we can see whether your script is producing an unexpected output.