Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Trying to print 3 columns of data from mysql with php

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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Using cfstoredproc to return query data 2 30
Word, Excel, Access icons 4 17
PHP Mail error 3 26
HTML Anchor Link Problem 3 35
Find out what you should include to make the best professional email signature for your organization.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 how to look for a specific file type in a local or remote server directory using PHP.

809 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