Solved

Trying to print 3 columns of data from mysql with php

Posted on 2011-02-20
5
783 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
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 500 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

What is SQL Server and how does it work?

The purpose of this paper is to provide you background on SQL Server. It’s your self-study guide for learning fundamentals. It includes both the history of SQL and its technical basics. Concepts and definitions will form the solid foundation of your future DBA expertise.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to create a scatter graph with straight lines 6 26
Centering Vertically 3 27
How to loop through records  using SELET COUNT 2 13
Bootstrap on PLNKR 3 13
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this tutorial viewers will learn how to embed videos in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <video> tag to insert a video. Define the src as the URL of your video; this is similar to …
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)

919 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

22 Experts available now in Live!

Get 1:1 Help Now