rodneykm Posted October 11, 2006 Share Posted October 11, 2006 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.phpfunction 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] Link to comment https://forums.phpfreaks.com/topic/23696-new-here-got-a-question/ Share on other sites More sharing options...
Jocka Posted October 11, 2006 Share Posted October 11, 2006 How I did it.. something like this:[code]<?php$t_count = 0; // TABLE COUNTif($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] Link to comment https://forums.phpfreaks.com/topic/23696-new-here-got-a-question/#findComment-107575 Share on other sites More sharing options...
rodneykm Posted October 11, 2006 Author Share Posted October 11, 2006 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.phpfunction 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] Link to comment https://forums.phpfreaks.com/topic/23696-new-here-got-a-question/#findComment-107597 Share on other sites More sharing options...
HuggieBear Posted October 11, 2006 Share Posted October 11, 2006 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]RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/23696-new-here-got-a-question/#findComment-107683 Share on other sites More sharing options...
rodneykm Posted October 12, 2006 Author Share Posted October 12, 2006 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]RegardsHuggie[/quote] Link to comment https://forums.phpfreaks.com/topic/23696-new-here-got-a-question/#findComment-107749 Share on other sites More sharing options...
rodneykm Posted October 12, 2006 Author Share Posted October 12, 2006 bump Link to comment https://forums.phpfreaks.com/topic/23696-new-here-got-a-question/#findComment-107889 Share on other sites More sharing options...
HuggieBear Posted October 12, 2006 Share Posted October 12, 2006 Will you have a need to paginate your results? e.g. 15 thumbs per page with 'previous' and 'next' buttons at the bottom?RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/23696-new-here-got-a-question/#findComment-107893 Share on other sites More sharing options...
rodneykm Posted October 12, 2006 Author Share Posted October 12, 2006 Yeah definitely will need that. Any help is greatly appriciated. Link to comment https://forums.phpfreaks.com/topic/23696-new-here-got-a-question/#findComment-108076 Share on other sites More sharing options...
rodneykm Posted October 13, 2006 Author Share Posted October 13, 2006 bump Link to comment https://forums.phpfreaks.com/topic/23696-new-here-got-a-question/#findComment-108276 Share on other sites More sharing options...
HuggieBear Posted October 13, 2006 Share Posted October 13, 2006 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.RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/23696-new-here-got-a-question/#findComment-108283 Share on other sites More sharing options...
heckenschutze Posted October 13, 2006 Share Posted October 13, 2006 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 :) Link to comment https://forums.phpfreaks.com/topic/23696-new-here-got-a-question/#findComment-108287 Share on other sites More sharing options...
rodneykm Posted October 13, 2006 Author Share Posted October 13, 2006 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.phpfunction 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] Link to comment https://forums.phpfreaks.com/topic/23696-new-here-got-a-question/#findComment-108365 Share on other sites More sharing options...
rodneykm Posted October 14, 2006 Author Share Posted October 14, 2006 bump Link to comment https://forums.phpfreaks.com/topic/23696-new-here-got-a-question/#findComment-108847 Share on other sites More sharing options...
HuggieBear Posted October 14, 2006 Share Posted October 14, 2006 Sorry dude, been busy, I'll get on the case now.RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/23696-new-here-got-a-question/#findComment-108852 Share on other sites More sharing options...
rodneykm Posted October 16, 2006 Author Share Posted October 16, 2006 bumpity Link to comment https://forums.phpfreaks.com/topic/23696-new-here-got-a-question/#findComment-109248 Share on other sites More sharing options...
HuggieBear Posted October 17, 2006 Share Posted October 17, 2006 Apologies for the delay...Here's the code, with comments, give it a try.[code]<?php// Connect to DBinclude('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 numberif (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 resultsecho "<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 numbersecho "</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]RegardsHuggie Link to comment https://forums.phpfreaks.com/topic/23696-new-here-got-a-question/#findComment-109899 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.