Jump to content


Photo

New here - Got a question


  • Please log in to reply
15 replies to this topic

#1 rodneykm

rodneykm
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 11 October 2006 - 07:48 PM

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.


// 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");
}
}



#2 Jocka

Jocka
  • Members
  • PipPipPip
  • Advanced Member
  • 344 posts
  • LocationDallas, Texas

Posted 11 October 2006 - 08:06 PM

How I did it.. something like this:
<?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;
}

?>


#3 rodneykm

rodneykm
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 11 October 2006 - 08:47 PM

My best shot so far...I'm really stumped on this. Seems like it should be SO easy.

// 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++;
}


#4 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 11 October 2006 - 11:37 PM

In which order do you want the data displayed, horizontally or vertically?  If you're not sure what I mean, check out this post

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#5 rodneykm

rodneykm
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 12 October 2006 - 03:38 AM

Horizontally for sure.

In which order do you want the data displayed, horizontally or vertically?  If you're not sure what I mean, check out this post

Regards
Huggie



#6 rodneykm

rodneykm
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 12 October 2006 - 01:13 PM

bump

#7 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 12 October 2006 - 01:22 PM

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#8 rodneykm

rodneykm
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 12 October 2006 - 08:49 PM

Yeah definitely will need that. Any help is greatly appriciated.

#9 rodneykm

rodneykm
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 13 October 2006 - 12:08 PM

bump

#10 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 13 October 2006 - 12:13 PM

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
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#11 heckenschutze

heckenschutze
  • Members
  • PipPipPip
  • Advanced Member
  • 257 posts
  • LocationAustralia

Posted 13 October 2006 - 12:19 PM

Nested loops FTW.

<?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>";
?>

HTH, now just incorperate it :)

#12 rodneykm

rodneykm
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 13 October 2006 - 02:46 PM

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

// 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>";}




#13 rodneykm

rodneykm
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 14 October 2006 - 06:17 PM

bump

#14 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 14 October 2006 - 06:23 PM

Sorry dude, been busy, I'll get on the case now.

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools

#15 rodneykm

rodneykm
  • Members
  • PipPip
  • Member
  • 10 posts

Posted 16 October 2006 - 01:29 AM

bumpity

#16 HuggieBear

HuggieBear
  • Members
  • PipPipPip
  • Advanced Member
  • 1,899 posts
  • LocationEngland, UK

Posted 17 October 2006 - 08:38 AM

Apologies for the delay...

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

<?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> ";
}
?>

Note: 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

Regards
Huggie
Advice to MySQL users: Get phpMyAdmin and test your queries work there first, take half the hassle out of diagnosis, also check the reserved words list.

Links: PHP Docs :: RegEx's :: MySQL :: DevGuru :: w3schools




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users