icantcode Posted November 24, 2009 Share Posted November 24, 2009 I am at my wit's end. I finally figured out how to format my database into 3 columns(nicely). Now I want to print 3 sets of the 3 columns per page. (Like a photo directory) Here is the active link and the code is below. http://www.centralmembers.org/pdftable.php <?php ################### S T A R T C O N F I G U R A T I O N ###################### # SET THE NUMBER OF COLUMS IN THE TABLE $number_of_colums=3; # SET YOUR MYSQL HOSTNAME, USERNAME, PASSWORD AND DATABASENAME $db = mysql_connect("", "", ""); mysql_select_db("",$db); # ENTER NAME OF TABLE TO BE displayed $table_name = "xxx"; // change to whatever table you want to get data from $field1_name = "filename"; // change to whatever field name from the $table_name $field2_name = "author"; // change to whatever field name from the $table_name $field3_name = "details"; // change to whatever field name from the $table_name $field4_name = "location"; // change to whatever field name from the $table_name $field5_name = "keywords"; // change to whatever field name from the $table_name ################### E N D C O N F I G U R A T I O N ###################### #################################################################################### #################### STOP HERE - NO NEED TO CHANGE FROM THIS POIN ################# #################################################################################### $sql = "SELECT * FROM xxx ORDER BY title ASC"; $result = mysql_query($sql ,$db); $total_records = mysql_num_rows($result); $num_rows = ceil($total_records / $number_of_colums); if ($result) { if ($myrow = mysql_fetch_array($result)) { do { ?><table width="100%" border="0" cellspacing="15" cellpadding="15" align="center"> <tr> <?php do { if ($newrowcount == $number_of_colums) { $newrowcount = 0; ?><tr> <?php } ?><td valign="top"> <?php ################### DISPLAY cell info ########## ?><center><?php if (!empty ($myrow[$field1_name]) && (file_exists ('directory/thumbs/' . $myrow[$field1_name]))) { echo '<img src="./directory/thumbs/' . $myrow[$field1_name] . '" />'; } else { echo '<img src="./directory/thumbs/nophoto.jpg" />'; } ?></center><br /><?php ?><center> <font face="Verdana, sans-serif" size="2"><b><?php echo nl2br(stripslashes($myrow[$field2_name])); ?></b></font> </center><?php ?><center> <font face="Verdana, sans-serif" size="1"><?php echo nl2br(stripslashes($myrow[$field3_name])); ?></font> </center><?php ?><center> <font face="Verdana, sans-serif" size="2"><?php echo $myrow[$field4_name]; ?></font> </center><?php ?><center> <font face="Verdana, sans-serif" size="1"><b>E:</b> <?php echo $myrow[$field5_name]; ?></font> </center><?php ################### DISPLAY cell info ########## ?></td> <?php $newrowcount++; if ($newrowcount == $number_of_colums) {echo"</tr>";} } while ($myrow = mysql_fetch_array($result)); ?></tr></table></div> <?php } while ($myrow = mysql_fetch_array($result)); } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/182831-multi-column-printing-andor-pagination/ Share on other sites More sharing options...
mikesta707 Posted November 24, 2009 Share Posted November 24, 2009 Please wrap your code in code tags. here is a basic pagination tutorial http://www.phpfreaks.com/tutorial/basic-pagination That should help get you started. Once you figure out the steps to use pagination, adapting your current script to that shouldn't be hard Quote Link to comment https://forums.phpfreaks.com/topic/182831-multi-column-printing-andor-pagination/#findComment-964998 Share on other sites More sharing options...
icantcode Posted November 24, 2009 Author Share Posted November 24, 2009 Hence my username... What do you mean by wrapping in code tags? and I have tried the pagination tutorial, but I can't figure it out because it uses basic recordsets without pictures and formatting. The first challenge was pulling 6 items from my table and formatting them nicely and arranging in 3 columns. Quote Link to comment https://forums.phpfreaks.com/topic/182831-multi-column-printing-andor-pagination/#findComment-965005 Share on other sites More sharing options...
mikesta707 Posted November 24, 2009 Share Posted November 24, 2009 i mean using code bb tags, ie [code=php:0] [/code] for PHP or [code] [/code] for general code. I understand it uses basic record sets, but once you get something with basic record sets working, all you would really need to do to adapt it to your current set up is change the limit/entries per page/what your selecting from the table. honestly, your display code won't really change at all Quote Link to comment https://forums.phpfreaks.com/topic/182831-multi-column-printing-andor-pagination/#findComment-965007 Share on other sites More sharing options...
icantcode Posted November 24, 2009 Author Share Posted November 24, 2009 Quit being a know-it-all-douche. I tried the pagination tutorial and I couldn't get it to work. This was another suggestion that didn't work. (I used code tags this time) <code> <?php include 'pdftable.php'; if(!isset($_GET['page'])){ $page = 1; } else { $page = $_GET['page']; } $max_results = 9; $from = (($page * $max_results) - $max_results); $sql = mysql_query("SELECT * FROM XXX LIMIT $from, $max_results"); while($row = mysql_fetch_array($sql)){ echo "$row[author] $row[filename] } $total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM XXX"),0); $total_pages = ceil($total_results / $max_results); echo "<p align=\"center\">Select a Page<br />"; if($page > 1){ $prev = ($page - 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\">« Previous </a>"; } for($i = 1; $i <= $total_pages; $i++){ if(($page) == $i){ echo "$i "; } else { echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> "; } } if($page < $total_pages){ $next = ($page + 1); echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next »</a>"; } echo "</p>"; ?> </code> Quote Link to comment https://forums.phpfreaks.com/topic/182831-multi-column-printing-andor-pagination/#findComment-965018 Share on other sites More sharing options...
mikesta707 Posted November 24, 2009 Share Posted November 24, 2009 but all I know how to be is a know it all douche! If you don't understand the tutorial, then you should learn more about PHP before you try to do this. It will be a headache trying to just take some code you don't understand and apply it to code that you (seemingly) barely understand. I could write a simple pagination script, but I'm not going to create a whole script and tailor it to your situation. People who post here volunteer their time, and a little respect goes a long way. by the way, i didn't mean to come off like a "know it all douche" as you so eloquently put it, but may i suggest that you not come off as a whiny brat when asking for help on a forum of volunteers Quote Link to comment https://forums.phpfreaks.com/topic/182831-multi-column-printing-andor-pagination/#findComment-965023 Share on other sites More sharing options...
icantcode Posted November 24, 2009 Author Share Posted November 24, 2009 I appreciate your large brain. I've been struggling with this for several MONTHS and can't work it out. That is exactly why I posted. You obviously know what I need, but are reluctant to help me. Quote Link to comment https://forums.phpfreaks.com/topic/182831-multi-column-printing-andor-pagination/#findComment-965029 Share on other sites More sharing options...
mikesta707 Posted November 24, 2009 Share Posted November 24, 2009 I know how to make a pagination script yes. I could theoretically adapt it to your current script, but you aren't asking for someone else to do it for you, you were asking for help. I figured a tutorial on pagination would help you, since that what you wanted. if you are saying you don't understand the tutorial, and refuse to try to understand it, than what incentive is there for me to just do it for you. Maybe you should explain what exactly you don't understand about the pagination tutorial? then maybe I, or someone else can try to explain to you what you don't understand. When you show an incentive to learn, people show an incentive to teach, but just demanding answers and refusing to read something and learn on your own is a sure fire way to get no answers. It's not that i'm reluctant to help, its that I am reluctant to make your script for you. Quote Link to comment https://forums.phpfreaks.com/topic/182831-multi-column-printing-andor-pagination/#findComment-965035 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.