/    Sign up×
Community /Pin to ProfileBookmark

Page Break with Tables and MySQL

Hello I Found This

[QUOTE=sharapov]

I am retreaving my data from the MySQL database and display it inside HTML table. What I need to do is display every sixth row of the table on the new page (when user prints it). I know that it is possible with CSS if I do something like this: <tr style=”page-break-after: always;”> My problem is how can I make my code to insert this line (<tr style=”page-break-after: always;”>) every sixth row? I tried to do the following but it doesn’t really work correctly. Can anybody help?

[code]
. . .

$num_results = mysql_num_rows($result);

for ($i=0; $i <$num_results; $i++) {

if($i%6==5){

echo”<tr style=”page-break-after: always;”>”; }

else {

echo” <tr>”; }

. . .
[/code]
[/QUOTE]

The [B]above[/B] is exactly what i need, and i can get the above code working but, my problem is it when it gets data from the data base it just keeps pulling the same row of data, I dont know how to make it move to the next row of data until all rows are displayed. I was playing around with while($row = mysql_fetch_row($result)) statement but no luck. any help please.. this is what i have…

[code=php]
<?php
include(“conf.php”);
$connection = mysql_connect($server, $user, $pass);
mysql_select_db($db) or die (“Unable to select database!”);
$query = “SELECT * FROM users WHERE (status=’Active’)”;
$result = mysql_query($query) or die (“Error in query: $query. “.mysql_error());
$row = mysql_fetch_row($result);

$num_results = 19;
for ($i=0; $i <$num_results; $i++) {
if($i%5==4){
echo “next<br>”;
}
else {
echo “User:$row[3]>”;
}
}

mysql_free_result($result);
mysql_close($connection);

?>
[/code]

im sure its easy for someone that knows what their doing, im just now trying to learn php…

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@Declan1991Sep 07.2007 — [code=php]
while ($row = mysql_fetch_row($result)) {
if($i%5==4){
echo "next<br>";
}
else {
echo "User:$row[3]>";
}
}
++$i;
}
[/code]
Copy linkTweet thisAlerts:
@crtechauthorSep 07.2007 — That was it.. thanks a lot..
×

Success!

Help @crtech spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.20,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...