Solved

Trying to print 3 columns of data from mysql with php

Posted on 2011-02-20
5
782 Views
Last Modified: 2012-05-11
I am trying to print rows from a database into three columns and then be able to print them in three columns as well. the below code is what I am using to display the three columns but when I try to print them. it doesn't want to print them correctly. it only displays some of the rows in the print preview. any suggestions? I have tried creating a print CSS and force it to break on an tag but I haven't had any luck with it.
$data = mysql_query("SELECT * FROM test") ;
$data_count = mysql_num_rows($data);
$div_open = '<div style="float:left;margin-left:30px;">';
$div_close = '</div>';

print $div_open;
print "<ul>";

for ( $i = 0; i < 150 && $i < $data_count; $i ++)
{
	if ($i % 50 == 0 && $i > 1)
	{
		print $div_close;
		print $div_open;
		print "<ul>";
	}
	$info = mysql_fetch_array( $data );
	print "<tr><td>" . $info['1'] . "&nbsp;&nbsp;&nbsp;" . $info['2'] . "&nbsp;&nbsp;&nbsp;" . "</td><td>" .  $info['3'] . "</td></tr><br>";

}
print "</ul>";
print $div_close;

Open in new window

0
Comment
Question by:jaxbrian
  • 3
  • 2
5 Comments
 
LVL 6

Accepted Solution

by:
MatthewP earned 500 total points
Comment Utility
At a guess the browser isn't sure how to render the page for print as you're not generating valid html with this code, so if its fine on screen I'd look at generating some valid html first of all. UL needs LI elements, TR needs TABLE elements. BR after TR isn't valid either you should use margins/padding for your spacing. Validate your code with http://validator.w3.org/ - validate any style sheets here too - then see if that clears it up.

0
 
LVL 2

Author Comment

by:jaxbrian
Comment Utility
will do
0
 
LVL 6

Assisted Solution

by:MatthewP
MatthewP earned 500 total points
Comment Utility
If that doesn't work on it's own, one possibile source of problems I can see is where table cells are going to be too wide to fit on the page. If this is the case applying some styles to the table cells can help. Example:

<td style="width:400px; word-wrap: break-word;">

Look at setting a width on your table too and container div too.



0
 
LVL 2

Author Comment

by:jaxbrian
Comment Utility
ok, I have it doing what I wanted it to do. it was  combination of both your answers plus some more tweaking.

thank you guys very much for your time and input
0
 
LVL 2

Author Comment

by:jaxbrian
Comment Utility
it was just one guy but ... lol
0

Featured Post

Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

Join & Write a Comment

Suggested Solutions

Building a website can seem like a daunting task to the uninitiated but it really only requires knowledge of two basic languages: HTML and CSS.
This article discusses how to create an extensible mechanism for linked drop downs.
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

763 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now