Jump to content

Display multiple images (1 per row) in table


robbo-bbr

Recommended Posts

Firstly Hi, I am (normally) the type of person than bangs my head until I work something out. Sadly on this occasion I have to admit defeat and ask for help (or guidance).

 

The Problem: I am trying to just learn how things work at the moment.

I created the usual 'Hello World' php and have started moving on from there and now have 2 php files (for this project). These files are part of a Joomla site, but they work fine (except images)

 

I have a Table in My SQL with the following headings:

id(int), image(longblob), message(text), unit(text) , date(date)

 

I have several rows of information stored, and have been able to call this information to the web browser in a table format.

 

The problem I'm encountering is getting the 'image' to display. I did place code in but only got loads of strange text (binary i think) instead of an image.

I have played around and got single images to display, but cant work out how to display each image in each row.

 

Please HELP (my wall is getting hurt from banging my head)

 

The 2 files are:

 

hello.html.php

<?php
class HTML_hello
{
  function showHello($rows, $option)
  { ?>
    <table>
    <?php
    foreach($rows as $row)
    {
      $link = 'index.php?option='.$option.
      '&id='. $row->id .
      '&task=view';
      echo '
      <tr>
        <td width="60">
            
            <a href="'. $link .'">'. $row->image .'</a>
        </td>
        <td width="200">
            <a href="'. $link .'">'. $row->message .'</a>
        </td>
        <td width="300">
            <a href="'. $link .'">'. $row->unit .'</a>
        </td>
        <td>
            <a href="'. $link .'">'. $row->date .'</a>
        </td>
      </tr>
      ';
    }
    ?>
  </table>
  <?php
  }
  
  	function viewHello($row, $option)
{ ?>
  <p class="contentheading">
  <?php echo "ID: <b>". $row->id ."</b>";?></p>
  <p>
    <?php echo "Image: <br><b>". $row->image . " </b>";?>
    <?php echo "Message: <br><b>". $row->message . " </b>";?> 
    <?php echo "Unit: <br><b>". $row->unit . " </b>";?>
    <?php echo "Date: <br><b>". $row->date . " </b>";?>
  <?php $link = 'index.php?option='. $option; ?>
  <p><a href="<?php echo $link;?>">< return to the hello frontpage</a></p>  
  <?php
}
    
}
?>

 

the 2nd file:

 

hello.php

<?php
defined( '_JEXEC' ) or die( 'Restricted access' );
echo '<div class="componentheading">Image Table Test</div>';

jimport('joomla.application.helper');
require_once(JApplicationHelper::getPath( 'html' ));
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.$option.DS.'tables');

switch( $task ){
  case 'view':
    viewHello($option);
    break;

    default:
    showPublishedHello($option);
    break;
}

function showPublishedHello($option)
{
  $db =& JFactory::getDBO();
  $query = "SELECT * FROM #__hello 
  WHERE published= '1' ORDER BY id DESC";
  $db->setQuery( $query );
  $rows = $db->loadObjectList();

  if ($db->getErrorNum())
  {
    echo $db->stderr();
    return false;
  }
  HTML_hello::showHello($rows, $option);
}

function viewHello($option)
{
  $id = JRequest::getVar('id', 0);
  $row =& JTable::getInstance( 'hello', 'Table');
  $row->load($id);

  if(!$row->published)
  {
    JError::raiseError( 404, JText::_('Invalid ID Provided'));		
  }
  HTML_hello::viewHello($row, $option);
}

?>

 

From what I have researched so far I believe I need to add the 'img tags' (plus more) in this area of hello.html.php

 

<img> <?php echo "Image: <br><b>". $row->image . " </b>";?></img>

 

Am i in the right direction?

 

I also believe I need to add something along the lines of:

 

$image_id=$row['image_id'];

 

Not sure if thats correct, or where to really put it.

 

Please help guys.

Thanks.

 

 

I always get lost in your codes haha and your questions..

 

FROM my understanding of things you want multiple image links which are stored in your database in multiple new rows..

 


// Okay lets get our images from the database
$SQL = mysql_query("SELECT * FROM Table1");

print '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
// Between these two <table> codes is where a new row will be created for every new image you display
// creating a while loop will put each image in its proper row
while($row = mysql_fetch_array($SQL)){

print '<tr>
          <td><img src="'.$row['image_link'].'"/></td>
          </tr>';


}
print '</table>';

I always get lost in your codes haha and your questions..

 

FROM my understanding of things you want multiple image links which are stored in your database in multiple new rows..

 


// Okay lets get our images from the database
$SQL = mysql_query("SELECT * FROM Table1");

print '<table width="100%" border="0" cellspacing="0" cellpadding="0">';
// Between these two <table> codes is where a new row will be created for every new image you display
// creating a while loop will put each image in its proper row
while($row = mysql_fetch_array($SQL)){

print '<tr>
          <td><img src="'.$row['image_link'].'"/></td>
          </tr>';


}
print '</table>';

 

Thank you for your help. I know my initial explanation is a little long :-)

 

Your code get to what I am after, however I need to merge it with my code.

I understand your code calls all from a table

$SQL = mysql_query("SELECT * FROM Table1");

I have done the same in my hello.php

So I 'think' I can remove that line

 

Then I can see how you keep calling 'while'

while($row = mysql_fetch_array($SQL))

I also have a working loop in hello.html.php

So again I have removed this.

 

What I'm left with is exactly what I think I need:

print '<tr>
          <td><img src="'.$row['image_link'].'"/></td>
          </tr>';

I have worked it like this (and many other ways) lol:

<tr>
        <td width="60">
            <a href="'. $link .'"><img src="'.$row['image_link'].'"/>'. $row->image .'</a>
        </td>
        <td width="200">
            <a href="'. $link .'">'. $row->message .'</a>
        </td>

All of my other stored info in a row is displayed, just no image (or again Binary output)

 

Any ideas?

Anyone?

 

Thank you

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.