Jump to content

Images displaying in columns


budimir

Recommended Posts

Hey guys,

 

I wrote a code for displaying images in columns, but for some reason it's not working. Can you take a look and tell me what I'm doing wrong?

 

$i = 0;
if($i % 4 == 0){
                        echo '
                        <td width="25%" align="center" valign="top">
                        <a href= "'.$slika_velika.''.$slika_v.'" rel="lytebox" title="'.$naziv.' - '.$mjesto.' - '.$medalja.'" target="_blank"><img src="'.$slika_mala.''.$slika_m.'"width="200" height="150" border="0"></a><br>
                        </td>
                        <td width="25%" align="center" valign="top">
                        '.$naziv.' - '.$mjesto.'
                        </td>
                        <td width="25%" align="center" valign="top">
                        '.$medalja.'
                        </td><br />
                        ';
                        echo '</tr><tr>';
                            }
                        $i++;
                    }

 

The output I'm getting now is one image below another. I would like to display them one next to another.

 

Please help!!!

 

Link to comment
https://forums.phpfreaks.com/topic/222648-images-displaying-in-columns/
Share on other sites

This is the complete code I'm using

 

        <?php
        $slika_velika = "slike_medalja/";
        $slika_mala = "slike_medalja/thumbs/";
        $upit = "SELECT * FROM medalje_slike ORDER BY datum_dodavanja ASC";
        $rezultat = mysql_query($upit,$veza) or die ("Nije uspilo");
                while($row = mysql_fetch_array($rezultat)){
                        $slika_v = $row["slika_velika"];
                        $slika_m = $row["slika_mala"];
                        $mjesto = $row["mjesto_osvajanja"];
                        $naziv = $row["naziv_natjecanja"];
                        $vrsta = $row["vrsta_medalje"];
                        
                        if ($vrsta == 1) { $medalja = "Zlato"; } elseif ($vrsta == 2) { $medalja = "Srebro";} elseif ($vrsta == 3) { $medalja = "Bronca"; }

$i = 0;
if($i % 4 == 0){
                        echo '
                        <td width="25%" align="center" valign="top">
                        <a href= "'.$slika_velika.''.$slika_v.'" rel="lytebox" title="'.$naziv.' - '.$mjesto.' - '.$medalja.'" target="_blank"><img src="'.$slika_mala.''.$slika_m.'" border="0"></a><br>
                        </td>
                        <td width="25%" align="center" valign="top">
                        '.$naziv.' - '.$mjesto.'
                        </td>
                        <td width="25%" align="center" valign="top">
                        '.$medalja.'
                        </td><br />
                        ';
                        echo '</tr><tr>';
                            }
                        $i++;
                    }
        ?>

Hey revraz,

 

I did it like this, now, but still not working

 

        <?php
        $slika_velika = "slike_medalja/";
        $slika_mala = "slike_medalja/thumbs/";
        $upit = "SELECT * FROM medalje_slike ORDER BY datum_dodavanja ASC";
        $rezultat = mysql_query($upit,$veza) or die ("Nije uspilo");
                while($row = mysql_fetch_array($rezultat)){
                        $slika_v = $row["slika_velika"];
                        $slika_m = $row["slika_mala"];
                        $mjesto = $row["mjesto_osvajanja"];
                        $naziv = $row["naziv_natjecanja"];
                        $vrsta = $row["vrsta_medalje"];
                        
                        if ($vrsta == 1) { $medalja = "Zlato"; } elseif ($vrsta == 2) { $medalja = "Srebro";} elseif ($vrsta == 3) { $medalja = "Bronca"; }

$i = 0;
if($i % 4 == 0){
                        echo '<tr>
                        <td width="25%" align="center" valign="top">
                        <a href= "'.$slika_velika.''.$slika_v.'" rel="lytebox" title="'.$naziv.' - '.$mjesto.' - '.$medalja.'" target="_blank"><img src="'.$slika_mala.''.$slika_m.'" border="0"></a><br>
                        </td>
                        <td width="25%" align="center" valign="top">
                        '.$naziv.' - '.$mjesto.'
                        </td>
                        <td width="25%" align="center" valign="top">
                        '.$medalja.'
                        </td><br />
                        ';
                        echo '</tr>';
                            }
                        $i++;
                    }
        ?>

 

I would like to display the images horizontaly in columns, but I'm getting them verticly in rows??? What am I doing wrong?

Hey guys,

 

Thanks for you're effort, but I made it. I tried to play with code and this is what it acctualy made it work.

 

        <table width="100%" border="1" cellspacing="4" cellpadding="4" align="center">
            <tr>
        <?php
        $slika_velika = "slike_medalja/";
        $slika_mala = "slike_medalja/thumbs/";
        $upit = "SELECT * FROM medalje_slike ORDER BY datum_dodavanja ASC";
        $rezultat = mysql_query($upit,$veza) or die (mysql_error());
                while($row = mysql_fetch_array($rezultat)){
                        $slika_v = $row["slika_velika"];
                        $slika_m = $row["slika_mala"];
                        $mjesto = $row["mjesto_osvajanja"];
                        $naziv = $row["naziv_natjecanja"];
                        $vrsta = $row["vrsta_medalje"];
                        
                        if ($vrsta == 1) { $medalja = "Zlato"; } elseif ($vrsta == 2) { $medalja = "Srebro";} elseif ($vrsta == 3) { $medalja = "Bronca"; }

        $i = 0;
        if($i % 4 == 0){
                        
                        echo '
                        <td width="25%" align="center" valign="top">
                        <a href= "'.$slika_velika.''.$slika_v.'" rel="lytebox" title="'.$naziv.' - '.$mjesto.' - '.$medalja.'" target="_blank"><img src="'.$slika_mala.''.$slika_m.'" border="0"></a><br />
                        '.$naziv.' - '.$mjesto.' <strong>'.$medalja.'</strong>
                        </td>';
                        }
                        $i++;

                        #echo '</tr><tr></tr><tr>';
                            

                    }
          ?>
              </table>

 

I hope someone will make a use of this.

 

Again, thanks!!!

:( Not working correctly.

 

Now I have a situation that images are display horizontally, but for indefinite. What ever I do, it will not go to new row after 4 images.

 

Please help. This is the code.

 

        <table width="100%" border="1" cellspacing="4" cellpadding="4" align="center">
            <tr>
        <?php
        $slika_velika = "slike_medalja/";
        $slika_mala = "slike_medalja/thumbs/";
        $upit = "SELECT * FROM medalje_slike ORDER BY datum_dodavanja ASC";
        $rezultat = mysql_query($upit,$veza) or die (mysql_error());
                while($row = mysql_fetch_array($rezultat)){
                        $slika_v = $row["slika_velika"];
                        $slika_m = $row["slika_mala"];
                        $mjesto = $row["mjesto_osvajanja"];
                        $naziv = $row["naziv_natjecanja"];
                        $vrsta = $row["vrsta_medalje"];
                        
                        if ($vrsta == 1) { $medalja = "Zlato"; } elseif ($vrsta == 2) { $medalja = "Srebro";} elseif ($vrsta == 3) { $medalja = "Bronca"; }

        $i = 0;
        if($i % 4 == 0){
                        
                        echo '
                        <td width="25%" align="center" valign="top">
                        <a href= "'.$slika_velika.''.$slika_v.'" rel="lytebox" title="'.$naziv.' - '.$mjesto.' - '.$medalja.'" target="_blank"><img src="'.$slika_mala.''.$slika_m.'" border="0"></a><br />
                        '.$naziv.' - '.$mjesto.' <strong>'.$medalja.'</strong>
                        </td>';
                        }
                        
                        #echo '</tr><tr>';
                        $i++;    

                    }
          ?>
                  </tr>
              </table>

here is an example ...

(NOTE: I have not included any pagination to this)

<?php
$max_columns = 5; /* set max columns for table */
$i = 0; /* initially set counter to use in starting and ending rows */
?>
<table border ="2">
<?PHP
include('db.php'); /* make connection to database here */
$query = "Select * FROM album"; /* define query */
$result = mysql_query($query);   /* execute query */
$total_cells = mysql_num_rows($result);  /* count total cells to be displayed */
$total_rows = ceil($total_cells / $max_columns);  /* calculate total rows needed */
$junk1 = $total_rows * $max_columns;  /* calculate number of empty cells in last row */
$junk2 = $junk1 - $total_cells;
if($junk2==0) { 
    $last_row = "</tr>"; 
}else{ 
    $j = 0; 
    while($j<$junk2){ 
        $last_row = $last_row . "<td></td>"; 
        $j ++; 
    } 
    $last_row = $last_row . "</tr>"; 
}
while($row = mysql_fetch_array($result)) {  /* begin looping thru the results */
    $image = "thumbs/" .  $row['image']; 
    if($i == 0){ 
        echo "<tr>";     
        $i ++; 
    } 
    ?>
    <td align="center" valign="center"><IMG src = "<?PHP echo $image; ?>"></td>
    <?PHP 
    $i ++;
    if($i > $max_columns) {   /* check if need to close row */
        echo "</tr>"; 
        $i=0; 
    }        
}
echo $last_row . "</table>"; /* clean up last row */
?> 

Thanks litebearer,

 

You're code worked like a charm, atlhough I would like to know what I messed up with my code. I'm realy curious!!!!

 

I had to correct one mistake in you're code, but it worked perfectly.

 

Thanks for you're effort. Thanks. Thanks. Thanks. You made my day. I spent whole day trying to figure out what's wrong with my code, because the same one is working on antoher page I have, so that's why I don't understand!!! If you could clarify that for me I would appreciate I lot. I need to understand.

 

:D

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.