Jump to content

pagination & sort by stationary column header & alternate row colors


NoDoze

Recommended Posts

Is it possible to have all these features in one mysql data output?

 

I have the sort by column header and alternate row colors....but NO sationary column headers and no pagination.

 

I've tried to combine each of these features, but I can't get it to work together!

 

Can someone provide an exmple of how this code will look?

 

Thanks!

Link to comment
Share on other sites

This is what I have so far:

 

<html>
<head>
<link href="../css/index.css" rel="stylesheet" type="text/css">
</head>
<body bgcolor="#0554A3" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div class="text-header">Project Initiation Database</div>
<div class="prodatabase">
<br>
<a href="print.php" target="_blank">print page</a><br>
<br>
<table class="table">
<tr class="table-header">
<td><a href="viewall.php?sortby=date">Initiation Date</a></td>
<td><a href="viewall.php?sortby=project_number">Project Number</a></td>
<td><a href="viewall.php?sortby=resposible_individual">Responsible Individual</a></td>
<td><a href="viewall.php?sortby=off_project_name">Official Project Name</a></td>
<td><a href="viewall.php?sortby=inv_project_des">Invoice Job Description</a></td>
<td><a href="viewall.php?sortby=serv_project_name">Project Folder Name</a></td>
<td><a href="viewall.php?sortby=region">Region</a></td>
<td><a href="viewall.php?sortby=client">End Client</a></td>
<td><a href="viewall.php?sortby=solesource">Sole Source</a></td>
</tr>
</div>
</div>
</body>
</html>
<?
include 'config.php';
include 'opendb.php';
?>
<?

$query="SELECT * FROM pil";

if(isset($_GET['sortby'])){

$query .= " ORDER BY '" . $_GET['sortby'] . "'";
}

$result=mysql_query($query);

mysql_close();

$num=mysql_numrows($result);
$i=0;
while ($i < $num) {
$date=mysql_result($result,$i,"date");
$project_number=mysql_result($result,$i,"project_number");
$resposible_individual=mysql_result($result,$i,"resposible_individual");
$off_project_name=mysql_result($result,$i,"off_project_name");
$inv_project_des=mysql_result($result,$i,"inv_project_des");
$serv_project_name=mysql_result($result,$i,"serv_project_name");
$region=mysql_result($result,$i,"region");
$clientend=mysql_result($result,$i,"clientend");
$solesource=mysql_result($result,$i,"solesource");

print ($i % 2) ? "<tr bgcolor=\"6699CC\">" : "<tr bgcolor=\"3399CC\">";

print "<td>$date</td>";
print "<td nowrap>$project_number</td>";
print "<td align='left' nowrap>$resposible_individual</td>";
print "<td align='left' nowrap>$off_project_name</td>";
print "<td align='left' nowrap>$inv_project_des</td>";
print "<td align='left' nowrap>$serv_project_name</td>";
print "<td align='left' nowrap>$region</td>";
print "<td align='left' nowrap>$clientend</td>";
print "<td align='left' nowrap>$solesource</td>";

++$i;
}

?>

 

As you could see this is only sort by column header...

 

I need to make the headers stationary, and add pagination...

Link to comment
Share on other sites

Here is an example of my pagination...

 


<?php


include 'config.php';
include 'opendb.php';


if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}


$max_results = 10;


$from = (($page * $max_results) - $max_results); 



$sql = mysql_query("SELECT * FROM pil LIMIT $from, $max_results");



while($row = mysql_fetch_array($sql)){
    // Build your formatted results here.



echo ("<table>");
echo ("<tr>");
echo ("<td>");
echo ($row['date']);
echo ("</td>");
echo ("<td>");
echo ($row['project_number']);
echo ("</td>");
echo ("<td>");
echo ($row['resposible_individual']);
echo ("</td>");
echo ("<td>");
echo ($row['off_project_name']);
echo ("</td>");
echo ("<td>");
echo ($row['inv_project_des']);
echo ("</td>");
echo ("<td>");
echo ($row['serv_project_name']);
echo ("</td>");
echo ("<td>");
echo ($row['region']);
echo ("</td>");
echo ("<td>");
echo ($row['clientend']);
echo ("</td>");
echo ("<td>");
echo ($row['solesource']);
echo ("</td>");
echo ("</tr>");
echo ("</table>");

}


$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM pil"),0);

$total_pages = ceil($total_results / $max_results);

echo "<tr>";
echo stripslashes("<td colspan=\"1\"> ");
echo "</td>";
echo stripslashes("<td colspan=\"4\"> ");


if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i ";
        } else {
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
    }
}


if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
echo "</center>";
echo "</td>";
echo "</tr>";
?>

 

Now I just have to combine these two sets of code, to get it to work....

But everything I try doesn't work...

 

Please help!

 

Thanks.

Link to comment
Share on other sites

You know you do not have to echo every single line of code right?

 

IE:

echo '</center></td></tr>';

//works just as well as
echo '</center>';
echo '</td>';
echo '</tr>';

 

That may make it easier for modifications and that you don't have 15,000 lines of code when you only need 500.

 

and why do this:

echo stripslashes("<td colspan=\"4\"> ");

 

when this would work without the use of an extra function...

echo '<td colspan="4">';

//even this would work.
echo "<td colspan=\"4\">"; //as long as the slashes are stripped.

 

As for the original question

 

try

 

echo (($i % 2) == 0) ? "<tr bgcolor=\"6699CC\">" : "<tr bgcolor=\"3399CC\">";

 

 

 

Link to comment
Share on other sites

Yeah, I can't get it to work....I need to combine the two pages of code above...

 

So pagination, column header sort, sationary column headers, and alternate row colors all work together on the same page output.

 

Thanks for the example!

Link to comment
Share on other sites

OK, I've managed to get almost everything combined...Here is the code I have so far...

 

<html>
<head>
<link href="../css/index.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
a:link , a:visited {
color: #FFFFFF;
text-decoration: none;
}
a:hover {
color: #000000;
text-decoration: none;
}
.table {
font-family: Arial;
font-size: 12px;
color: #000000;
text-decoration: none;
text-align: center;
border: 1px solid #000000;
width: 100%;
}
.table-header {
font-family: Arial;
font-size: 12px;
font-weight: bold;
color: #FFFFFF;
text-decoration: none;
text-align: center;
background-color: #0554A3;
}
.prodatabase {
text-decoration: none;
font-family: Arial;
font-size: 10pt;
color: #FFFFFF;
position: absolute;
left: 25px;
top: 70px;
width: 970px;
}
.page {
text-decoration: none;
font-family: Arial;
font-size: 10pt;
color: #FFFFFF;
position: relative;
bottom: 0px;
height: 25px;
width: 500px;
text-align: center;
}
-->
</style>
</head>
<body bgcolor="#0554A3" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div class="text-header">Project Initiation Database</div>
<div class="prodatabase">
<br>
<a href="print.php" target="_blank">print page</a><br>
<br>
<table class="table">
<tr class="table-header">
<td>Initiation Date</td>
<td>Project Number</td>
<td>Responsible Individual</td>
<td>Official Project Name</td>
<td>Invoice Job Description</td>
<td>Project Folder Name</td>
<td>Region</td>
<td>End Client</td>
<td>Sole Source</td>
</tr>
</div>
</div>
</body>
</html>
<?php


include 'config.php';
include 'opendb.php';


if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}


$max_results = 25;


$from = (($page * $max_results) - $max_results); 



$sql = mysql_query("SELECT * FROM pil LIMIT $from, $max_results");



while($row = mysql_fetch_array($sql)){
    // Build your formatted results here.

echo (($i % 2) == 0) ? "<tr bgcolor=\"6699CC\">" : "<tr bgcolor=\"3399CC\">";
echo ("<td nowrap>");
echo ($row['date']);
echo ("</td>");
echo ("<td nowrap>");
echo ($row['project_number']);
echo ("</td>");
echo ("<td align='left' nowrap>");
echo ($row['resposible_individual']);
echo ("</td>");
echo ("<td align='left' nowrap>");
echo ($row['off_project_name']);
echo ("</td>");
echo ("<td align='left' nowrap>");
echo ($row['inv_project_des']);
echo ("</td>");
echo ("<td align='left' nowrap>");
echo ($row['serv_project_name']);
echo ("</td>");
echo ("<td align='left' nowrap>");
echo ($row['region']);
echo ("</td>");
echo ("<td align='left' nowrap>");
echo ($row['clientend']);
echo ("</td>");
echo ("<td align='left' nowrap>");
echo ($row['solesource']);
echo ("</td>");

}


$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM pil"),0);

$total_pages = ceil($total_results / $max_results);

echo "<tr>";
echo '<td colspan="1">';
echo "</td>";
echo '<td colspan="9">';


if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i ";
        } else {
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
    }
}


if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
echo "</center>";
echo "</td>";
echo "</tr>";
?>

 

I just need to make the header row stationary, and to make it sort by column header...

Link to comment
Share on other sites

<html>
<head>
<link href="../css/index.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
a:link , a:visited {
color: #FFFFFF;
text-decoration: none;
}
a:hover {
color: #000000;
text-decoration: none;
}
.table {
font-family: Arial;
font-size: 12px;
color: #000000;
text-decoration: none;
text-align: center;
border: 1px solid #000000;
width: 100%;
}
.table-header {
font-family: Arial;
font-size: 12px;
font-weight: bold;
color: #FFFFFF;
text-decoration: none;
text-align: center;
background-color: #0554A3;
}
.prodatabase {
text-decoration: none;
font-family: Arial;
font-size: 10pt;
color: #FFFFFF;
position: absolute;
left: 25px;
top: 70px;
width: 970px;
}
.page {
text-decoration: none;
font-family: Arial;
font-size: 10pt;
color: #FFFFFF;
position: relative;
bottom: 0px;
height: 25px;
width: 500px;
text-align: center;
}
-->
</style>
</head>
<body bgcolor="#0554A3" leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<div class="text-header">Project Initiation Database</div>
<div class="prodatabase">
<br>
<a href="print.php" target="_blank">print page</a><br>
<br>
<table class="table">
<tr class="table-header">
<td>Initiation Date</td>
<td>Project Number</td>
<td>Responsible Individual</td>
<td>Official Project Name</td>
<td>Invoice Job Description</td>
<td>Project Folder Name</td>
<td>Region</td>
<td>End Client</td>
<td>Sole Source</td>
</tr>
<?php


include 'config.php';
include 'opendb.php';


if(!isset($_GET['page'])){
    $page = 1;
} else {
    $page = $_GET['page'];
}


$max_results = 25;


$from = (($page * $max_results) - $max_results); 



$sql = mysql_query("SELECT * FROM pil LIMIT $from, $max_results");



while($row = mysql_fetch_array($sql)){
    // Build your formatted results here.

echo (($i % 2) == 0) ? "<tr bgcolor=\"6699CC\">" : "<tr bgcolor=\"3399CC\">";
echo ("<td nowrap>");
echo ($row['date']);
echo ("</td>");
echo ("<td nowrap>");
echo ($row['project_number']);
echo ("</td>");
echo ("<td align='left' nowrap>");
echo ($row['resposible_individual']);
echo ("</td>");
echo ("<td align='left' nowrap>");
echo ($row['off_project_name']);
echo ("</td>");
echo ("<td align='left' nowrap>");
echo ($row['inv_project_des']);
echo ("</td>");
echo ("<td align='left' nowrap>");
echo ($row['serv_project_name']);
echo ("</td>");
echo ("<td align='left' nowrap>");
echo ($row['region']);
echo ("</td>");
echo ("<td align='left' nowrap>");
echo ($row['clientend']);
echo ("</td>");
echo ("<td align='left' nowrap>");
echo ($row['solesource']);
echo ("</td>");

}


$total_results = mysql_result(mysql_query("SELECT COUNT(*) as Num FROM pil"),0);

$total_pages = ceil($total_results / $max_results);

echo "<tr>";
echo '<td colspan="1">';
echo "</td>";
echo '<td colspan="9">';


if($page > 1){
    $prev = ($page - 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$prev\"><<Previous</a> ";
}

for($i = 1; $i <= $total_pages; $i++){
    if(($page) == $i){
        echo "$i ";
        } else {
            echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$i\">$i</a> ";
    }
}


if($page < $total_pages){
    $next = ($page + 1);
    echo "<a href=\"".$_SERVER['PHP_SELF']."?page=$next\">Next>></a>";
}
echo "</center>";
echo "</td>";
echo "</tr>";
?>
</table>
</div>
</div>
</body>
</html>

 

Try that, you do not want to end the file until the page is done printing completely (IE </html> ) =)

Link to comment
Share on other sites

OK, another thing I've noticed....The Date format....

 

How do I convert 0000-00-00 to MO/DY/YR..?

I've search the forums, but the catch is that...the date is being called via a variable...see above:

print "<td>$date</td>";

 

Thanks.

 

Link to comment
Share on other sites

OK, so...I don't think it's possible to get pagination to work on a column header sort page, correct? Based on the amount of responses...

 

So... is it possible to get the header to be stationary? So that when people scroll down the table, the headers are stationary?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.