Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Newspaper Column Style

Status
Not open for further replies.

nikko1

Programmer
Jan 28, 2005
8
US
I have the results of a query, and I want them to appear in a newspaper column style report. Any advise?

/* Code Starts Here
$sql= "SELECT realname, userlogin , depotid FROM usertable WHERE depotid < 100";

$result=mysql_query($sql, $link);
$rowno=mysql_num_rows($result);
PRINT <<<END
<table border = 0 cellpadding = 0 cellspacing = 0 width="33%">
<tr>
<th width="7%"><font size=1>Depot</font></th>
<th width="19%"><font size=1>Name</font></th>
<th width="7%"><font size=1>Tech</font></th>
</tr>
</table>
END;
while($line=mysql_fetch_array($result, MYSQL_ASSOC))
{
PRINT <<<END
<table border = 0 cellpadding = 0 cellspacing = 0 width="33%">
<tr>
<th width="7%"><u><font size=1>$line[depotid]</font></th>
<th width="19%"><u><font size=1>$line[realname]</font></th>
<th width="7%"><u><font size=1>$line[userlogin]</font></th>
</tr>
</table>
END;
}
print "__________________________________";
print "<br>$rowno";

*/ Code ends here

Thanks,
Sharon
 
so there is someone that uses the HEREDOC syntax...

Sharon - your code currently prints as columns in a table (why are you repeating the table syntax in each line?). can you define what you mean by newspaper column style report?

 
I want to print a certain amount of rows and then when I get to the end of the "page", I want to start printing more rows in a new column. Example...

Tech Name Depot Tech Name Depot
1 Pete 1 11 Albert 2
2 Tom 1 12 Bob 2
3 John 1 13 Carl 2
4 Sam 1 14 Dave 2
5 Scott 1 15 Edward 2
6 Kevin 1 16 Frank 2
7 Nick 1 17 George 2
8 Victor 1 18 Harold 2
9 Billy 1 19 Ignacio 2
10 Dino 1 20 Jim 2
 
aha. assuming you want to split the columns evenly and you want two columns then you could use the css float property. i haven't tested the output below but it *should* work... (or be readily adaptable...)

Code:
echo "
<style type=\"text/css\">
body {margin: auto 0px;}
.content {text-align: center; width:70%; }
.leftfloat { float:left; text-align:left; width:100%; position:relative; background-color:red; }
.rightfloat { float:right; text-align:right; width:100%; position:relative; background-color:green;}
</style>
";
$sql=   "SELECT  realname, userlogin , depotid FROM usertable WHERE depotid < 100";

$result=mysql_query($sql, $link);
$rowno=mysql_num_rows($result);
$rows = ceil($rowno/2);
echo "<div id=\"content\">";
$cnt = 0;
$done = false;
echo "<div id=\"leftfloat\">";
while($line=mysql_fetch_array($result, MYSQL_ASSOC))
{
  if (!$done)
  {
    

PRINT <<<END
<table border = 0 cellpadding = 0 cellspacing = 0 width="33%">
        <tr>
                <th width="7%"><font size=1>Depot</font></th>
                <th width="19%"><font size=1>Name</font></th>
                <th width="7%"><font size=1>Tech</font></th>
        </tr>

END;
  $done=true;
  } //end of the if done statement
 // now fill just the one col then the other
 if ($cnt <= $rows) 
 { 
        PRINT <<<END
        <tr>
                <th width="7%"><u><font size=1>$line[depotid]</font></th>
                <th width="19%"><u><font size=1>$line[realname]</font></th>
                <th width="7%"><u><font size=1>$line[userlogin]</font></th>
        </tr>
END;
  $cnt ++;
  }
else
  {
    //finish left hand column
    echo "</table></div>";    
    //move on to right hand column
    $done = false;
    echo "<div id=\"rightfloat\">";
    $cnt=0;
  }
}  end the while statement
//might get left with some uneven tag endings here due to row imbalance.  could correct this in the code but haven't... ;->
echo "</table></div>";  //for sure that closes the table and the right hand div
echo "</div>";//for sure closes the content div
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top