Jump to content

Recommended Posts

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));

 

}

 

}

 

?>

Link to comment
https://forums.phpfreaks.com/topic/182831-multi-column-printing-andor-pagination/
Share on other sites

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

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.

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

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>

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

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.