how to add an image in a php table

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jerry1984r
Forum Newbie
Posts: 4
Joined: Sat Jun 05, 2010 10:23 am

how to add an image in a php table

Post 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.
Attachments
default.zip
(1.52 KiB) Downloaded 30 times
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: how to add an image in a php table

Post by Jonah Bron »

If you view the source in your browser, is the <img> tag there at all?
jerry1984r
Forum Newbie
Posts: 4
Joined: Sat Jun 05, 2010 10:23 am

Re: how to add an image in a php table

Post by jerry1984r »

if u mean the sectiontableheader of the img, it tagged there, but it doesn't display the img in it's cell.
jerry1984r
Forum Newbie
Posts: 4
Joined: Sat Jun 05, 2010 10:23 am

Re: how to add an image in a php table

Post by jerry1984r »

here is a Screenshot of the table
Attachments
Screenshot - 05_06_2010 , 19_32_11.jpg
Screenshot - 05_06_2010 , 19_32_11.jpg (45.15 KiB) Viewed 478 times
jerry1984r
Forum Newbie
Posts: 4
Joined: Sat Jun 05, 2010 10:23 am

Re: how to add an image in a php table

Post by jerry1984r »

nobody knows how to do such thing like this ?' :?
cpetercarter
Forum Contributor
Posts: 474
Joined: Sat Jul 25, 2009 2:00 am

Re: how to add an image in a php table

Post 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.
Post Reply