Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Trying to print 3 columns of data from mysql with php

Posted on 2011-02-20
5
Medium Priority
?
793 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 2000 total points
ID: 34938303
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
ID: 34938459
will do
0
 
LVL 6

Assisted Solution

by:MatthewP
MatthewP earned 2000 total points
ID: 34938590
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
ID: 34938969
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
ID: 34938973
it was just one guy but ... lol
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
Backups and Disaster RecoveryIn this post, we’ll look at strategies for backups and disaster recovery.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

971 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