Jump to content

Archived

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

rodneykm

New here - Got a question

Recommended Posts

The code below displays the first picture from any directory inside the directory in which it sits. My problem is that it only displays them in one column. For the life of me I cant figure out how to get this into multiple columns and rows...say 3 x 5 or so. Any have any suggestions? Any help at all would be very appriciated.


[code]// display categories on main page - gallery.php
function display_categories($cats) {
    global $file;


// Print Table
print('<table id="display_categories" >'."\r\n");


while ($next = next($cats)){
    $key = key($cats);
$value = $next;
$title = '<b>'.$key.'</b>:<br />';
//Output Thumbnail Images
print('<td style="width: '. THMBWIDTH .'px; height: '. THMBHEIGHT .'px;">');
if(is_array($value)) {
            foreach($value as $k2=>$v2) {
                if(is_dir(PATH.$file.'/'.$key.'/'.$k2))
                    $subcats[$k2] = $v2;
                else
                    $subimgs[] = $v2;
            }
            $imgloc = !empty($subimgs) ? rawurlencode($file.'/'.$key.'/'.reset($subimgs)) : null;
            $alt = !empty($subimgs) ? reset($subimgs) : 'no image';


// Show Gallery Main Image
print('<a href="'.SELF.'?file='.rawurlencode($file.'/'.$key).'">');
            print('<img src="imgsrc.php?src='.$imgloc.'" alt="'.$alt.'" />');
            print('</a>'."\r\n");






// Gallery Information (Image size, gallery name, etc...)
echo "<br>".$title;
            echo @count($subcats).' sub-categories<br />';
            echo @count($subimgs).' images';
print('</td>    <td class="category">'."\r\n");
unset($subcats, $subimgs);
        } else {
            print('<img src="imgsrc.php?src=null" alt="no image" />');
            print('</td><td class="category">'."\r\n");
            echo $title;
            print('0 sub-categories<br />');
            print('0 images');
        }
        print("\r\n".'</td>'."\r\n");

  print('</table>'."\r\n");
}
}

[/code]

Share this post


Link to post
Share on other sites
How I did it.. something like this:
[code]
<?php

$t_count = 0; // TABLE COUNT

if($t_count == '0'){
      echo "<tr><td>Blah</td>";
      $t_count = 1;
} else if($t_count == '1'){
      echo "<td>Secnd Blah</td>";
      $t_count = 2;
} else if($t_count == '2'){
      echo "<td>third blah</td></tr>";
      $t_count = 0;
}

?>[/code]

Share this post


Link to post
Share on other sites
My best shot so far...I'm really stumped on this. Seems like it should be SO easy.

[code]// display categories on main page - gallery.php
function display_categories($cats) {
    global $file;

// Print Table
print('<table id="display_categories" columnspan="3" rowspan="3">'."\r\n");


foreach($cats as $key=>$value) {

// While $j equals 1, print data out
while ($j = 1){
echo "<tr>";
$title = '<b>'.$key.'</b>:<br />';

//Output Thumbnail Images
print('<td style="width: '. THMBWIDTH .'px; height: '. THMBHEIGHT .'px;">');
if(is_array($value)) {
            foreach($value as $k2=>$v2) {
                if(is_dir(PATH.$file.'/'.$key.'/'.$k2))
                    $subcats[$k2] = $v2;
                else
                    $subimgs[] = $v2;
            }
            $imgloc = !empty($subimgs) ? rawurlencode($file.'/'.$key.'/'.reset($subimgs)) : null;
            $alt = !empty($subimgs) ? reset($subimgs) : 'no image';


// Show Gallery Main Image
print('<a href="'.SELF.'?file='.rawurlencode($file.'/'.$key).'">');
            print('<img src="imgsrc.php?src='.$imgloc.'" alt="'.$alt.'" />');
            print('</a>'."\r\n");

// Gallery Information (Image size, gallery name, etc...)
echo "<br>".$title;
            echo @count($subcats).' sub-categories<br />';
            echo @count($subimgs).' images';
print('</td>    <td class="category">'."\r\n");
unset($subcats, $subimgs);
        } else {
            print('<img src="imgsrc.php?src=null" alt="no image" />');
            print('</td><td class="category">'."\r\n");
            echo $title;
            print('0 sub-categories<br />');
            print('0 images');
        }
        print("\r\n".'</td></tr>'."\r\n");

    }
    print('</table>'."\r\n");
}
echo "</tr>"
$j++;
}[/code]

Share this post


Link to post
Share on other sites
In which order do you want the data displayed, horizontally or vertically?  If you're not sure what I mean, check out [url=http://www.phpfreaks.com/forums/index.php/topic,109401.msg441016.html#msg441016]this post[/url]

Regards
Huggie

Share this post


Link to post
Share on other sites
Horizontally for sure.

[quote author=HuggieBear link=topic=111232.msg450723#msg450723 date=1160609832]
In which order do you want the data displayed, horizontally or vertically?  If you're not sure what I mean, check out [url=http://www.phpfreaks.com/forums/index.php/topic,109401.msg441016.html#msg441016]this post[/url]

Regards
Huggie
[/quote]

Share this post


Link to post
Share on other sites
Will you have a need to paginate your results? e.g. 15 thumbs per page with 'previous' and 'next' buttons at the bottom?

Regards
Huggie

Share this post


Link to post
Share on other sites
OK, I have a huge deal on at work at the moment, but luckily for you, it's almost the weekend :)

I'll post the code for you tomorrow, I might even try to integrate some of your code for you.

Regards
Huggie

Share this post


Link to post
Share on other sites
Nested loops FTW.

[code]
<?php
$rows = 5;
$columnsPerRow = 3;

echo "<table>";
for($r = 0; $r < $rows; $r++)
{
echo "<tr>";
for($c = 0; $c < $columnsPerRow; $c++)
{
echo "<td>My info</td>";
}
echo "</tr>";
}
echo "</table>";
?>[/code]

HTH, now just incorperate it :)

Share this post


Link to post
Share on other sites
That has me REALLY close. Heres the code. It displays 5 rows and 3 columns, but its all repeat data. (hope that makes sense).

[code]// display categories on main page - gallery.php
function display_categories($cats) {
    global $file;


// Print Table
print('<table id="display_categories" columnspan="3" rowspan="3">'."\r\n");
$rows = 5;
$columnsPerRow = 3;

for($r = 0; $r < $rows; $r++)
{
echo "<tr>";
for($c = 0; $c < $columnsPerRow; $c++)
{

/*print ('<pre>');
print_r ($cats);
print ('</pre>'); */
foreach($cats as $key=>$value) {

//while ($next = next($cats)){
    //$key = key($cats);
//$value = key($cats);
$title = '<b>'.$key.'</b>:<br />';
//Output Thumbnail Images
print('<td style="width: '. THMBWIDTH .'px; height: '. THMBHEIGHT .'px;">');
if(is_array($value)) {
            foreach($value as $k2=>$v2) {
                if(is_dir(PATH.$file.'/'.$key.'/'.$k2))
                    $subcats[$k2] = $v2;
                else
                    $subimgs[] = $v2;
            }
            $imgloc = !empty($subimgs) ? rawurlencode($file.'/'.$key.'/'.reset($subimgs)) : null;
            $alt = !empty($subimgs) ? reset($subimgs) : 'no image';


// Show Gallery Main Image
print('<a href="'.SELF.'?file='.rawurlencode($file.'/'.$key).'">');
            print('<img src="imgsrc.php?src='.$imgloc.'" alt="'.$alt.'" />');
            print('</a>'."\r\n");

// Gallery Information (Image size, gallery name, etc...)
echo "<br>".$title;
            echo @count($subcats).' sub-categories<br />';
            echo @count($subimgs).' images';
print('</td>    <td class="category">'."\r\n");
unset($subcats, $subimgs);
        } else {
            print('<img src="imgsrc.php?src=null" alt="no image" />');
            print('</td><td class="category">'."\r\n");
            echo $title;
            print('0 sub-categories<br />');
            print('0 images');
        }
        print("\r\n".'</td>'."\r\n");
}
} }
echo "</tr>";}


[/code]

Share this post


Link to post
Share on other sites
Apologies for the delay...

Here's the code, with comments, give it a try.

[code]<?php

// Connect to DB
include('connect.php');

// Select total results for pagination
$result = mysql_query('SELECT count(countryName) FROM tblCountry'); // This needs to be your query
$num_records = mysql_result($result,0,0);

// Set maximum number of rows and columns
$max_num_rows = 2;
$max_num_columns = 2;
$per_page = $max_num_columns * $max_num_rows;

// Work out how many pages there are going to be
$total_pages = ceil($num_records / $per_page);

// Get the current page number
if (isset($_GET['page'])) $page = $_GET['page']; else $page = 1;

// Work out the limit offset
$start = ($page - 1) * $per_page;

// Select the results we want including limit and offset
$result = mysql_query("SELECT countryName FROM tblCountry ORDER BY countryName LIMIT $start, $per_page"); // Your query
$num_columns = ceil(mysql_num_rows($result)/$max_num_rows);
$num_rows = ceil(mysql_num_rows($result)/$num_columns);

// Echo the results
echo "<table border=\"2\">\n";
for ($r = 0; $r < $max_num_rows; $r++){
echo "<tr>\n";
for ($c = 0; $c < $max_num_columns; $c++){
$x = $r * $max_num_columns + $c;
if ($x < mysql_num_rows($result)){
                  $y = mysql_result($result, $x, 0); // This line outputs the results from your query
                }
                else {
                  $y = "Coming Soon"; // This is what I put in the empty spaces
                }
echo "<td>$y</td>";
}
echo "</tr>\n";
}

// Echo page numbers
echo "</table>\n";
for ($i=1;$i <= $total_pages;$i++) {
if ($i == $page) echo " $i "; else echo " <a href=\"?page=$i\">$i</a> ";
}
?>[/code]

[size=8pt][color=red][b]Note:[/b][/color] If you have a 'where' clause in your main select statement, you should also include it in the pagination sql at the top of the page[/size]

Regards
Huggie

Share this post


Link to post
Share on other sites

×

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.