Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Horizontal line after each row

Posted on 2011-09-06
11
Medium Priority
?
349 Views
Last Modified: 2012-05-12
Hi:

I have this code to display data from the database.  I want to display each table row seperated from the other by a horizontal line.  In other words, I need a horizontal line between each row.

Please help.

Thanks.
<?PHP
require_once("./include/membersite_config.php");

if(!$fgmembersite->CheckLogin())
{
    $fgmembersite->RedirectToURL("login.php");
    exit;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
<head>
      <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
      <title>Home page</title>
      <link rel="STYLESHEET" type="text/css" href="style/fg_membersite.css">
</head>
<body>
<div id='fg_membersite_content'>
<h2>Home Page</h2>
Welcome back <?= $fgmembersite->UserFullName(); ?>!
<?php 
$orderCol=$_POST['orderCol'];
$orderWay=$_POST['orderWay'];
$filterCat=$_POST['filterCat'];
$filterCo=$_POST['filterCo']; 

if (!$orderCol) $orderCol="resid";
if (!$orderWay) $orderWay="DESC";

$sql="SELECT * FROM responses WHERE 1=1";
if ($filterCat) $sql.=" AND categories='{$filterCat}'";
if ($filterCo) $sql.=" AND Country='{$filterCo}'";
$sql.=" ORDER BY {$orderCol} {$orderWay}";


        // connect to the database 
        include('connect-db.php'); 
 
        // get results from database 
        $result = mysql_query($sql)  
                or die(mysql_error());   

$sqlCat="SELECT DISTINCT categories FROM responses ORDER BY 1";
        $rsCat = mysql_query($sqlCat)  
                or die(mysql_error());   

$sqlCo="SELECT DISTINCT Country FROM responses ORDER BY 1";
        $rsCo = mysql_query($sqlCo)  
                or die(mysql_error());   
                 
        // display data in table 
        // display data in table 
        echo "<p><b>View All</b> | <a href='view-paginated.php?page=1'>View Paginated</a></p>"; 
        echo "<form method=POST>";
        echo "<table border='0' cellpadding='20';>";
	echo "<tr><td>&nbsp;</td><td>&nbsp;</td>";
                echo "<th><select name=filterCat size=1 onChange='this.form.submit();'>";
	echo "<option value='' SELECTED>-choose a filter-</option>";
	while($row = mysql_fetch_array( $rsCat )) { 
		$isSel="";
		if ($row[0]==$filterCat) $isSel=" SELECTED";
		echo "<option value='{$row[0]}' {$isSel}>{$row[0]}</option>";
	}
	echo "</select></th><td>&nbsp;</td><td>&nbsp;</td>";
	echo "<th><select name=filterCo size=1 onChange='this.form.submit();'>";
	echo "<option value='' SELECTED>-choose a filter-</option>";
	while($row = mysql_fetch_array( $rsCo )) { 
		$isSel="";
		if ($row[0]==$filterCo) $isSel=" SELECTED";
		echo "<option value='{$row[0]}' {$isSel}>{$row[0]}</option>";
	}
	echo "</select></th><td>&nbsp;</td>";
        echo "<tr> <th>ID</th> <th>Title</th> <th>Category</th> <th>Description</th> <th>City</th><th>Country</th><th>Zip Code</th></tr>";	
 
        // loop through results of database query, displaying them in the table 
        while($row = mysql_fetch_array( $result )) { 
                 
                // echo out the contents of each row into a table 
                echo "<tr>"; 
                echo '<td>' . $row['resid'] . '</td>'; 
                echo '<td>' . $row['title'] . '</td>';
                echo '<td>' . $row['categories'] . '</td>';
	echo '<td style="WORD-BREAK:BREAK-ALL">' . $row['description'] . '</td>'; 
                echo '<td>' . $row['city'] . '</td>'; 
                echo '<td>' . $row['country'] . '</td>';
                echo '<td>' . $row['zipcode'] . '</td>'; 
                //echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>'; 
                //echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>'; 
                echo "</tr>"; 
                        }  
 
        // close table> 
       echo "</table>"; 

?> 
<p><a href="new.php">Add a new record</a></p><p><a href='logout.php'>Logout</a></p>
</div>

</body>
</html>

Open in new window

0
Comment
Question by:adamssap
[X]
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
  • 4
  • 3
  • 3
  • +1
11 Comments
 
LVL 7

Expert Comment

by:rgranlund
ID: 36490523
echo '<td>' . $row['resid'] . '</td>';
echo "<td style="border-right:solid 1px #000">' . $row['resid'] . '</td>';

Try that.
0
 
LVL 16

Expert Comment

by:brad2575
ID: 36490532
place

echo "<tr> <td colspan=9><hr></td></tr>"
just before this:
// close table>

or if you dont want it in the table put it after like this

echo "</table>";
echo "<hr>"
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 36490553
Add it to the beginning of the loop like below.  "WORD-BREAK" is not supported in firefox and Opera.
// loop through results of database query, displaying them in the table 
        while($row = mysql_fetch_array( $result )) { 
                 
                // echo out the contents of each row into a table 
                echo "<tr><td colspan='9'><hr></td></tr>"; // <-----------------
                echo "<tr>"; 
                echo '<td>' . $row['resid'] . '</td>'; 
                echo '<td>' . $row['title'] . '</td>';
                echo '<td>' . $row['categories'] . '</td>';
	echo '<td style="WORD-BREAK:BREAK-ALL">' . $row['description'] . '</td>'; 
                echo '<td>' . $row['city'] . '</td>'; 
                echo '<td>' . $row['country'] . '</td>';
                echo '<td>' . $row['zipcode'] . '</td>'; 
                //echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>'; 
                //echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>'; 
                echo "</tr>"; 
                        }

Open in new window

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 1

Author Comment

by:adamssap
ID: 36490657
Hi DaveBaldwin:

Thanks, that worked.  But this inserts a line after the column headers, can that be avoided?  Since "WORD-BREAK" is not supported by Firefox and Opera, what is the other option?

Thanks,
0
 
LVL 7

Expert Comment

by:rgranlund
ID: 36490698
Create a class for the border.  Apply that class only to the <td> that you want to display it.  That should do it.  However, which of the <td>'s in the code above do you want it on?
0
 
LVL 84

Accepted Solution

by:
Dave Baldwin earned 2000 total points
ID: 36490717
Jut add a counter to the code and skip the first time when it is 0.  I dont' know what you're trying to do with "WORD-BREAK".  I've never used it.
$counter = 0;
// loop through results of database query, displaying them in the table 
        while($row = mysql_fetch_array( $result )) { 
                 
                // echo out the contents of each row into a table 
                if($counter > 0) echo "<tr><td colspan='9'><hr></td></tr>"; // <-----------------
                echo "<tr>"; 
                echo '<td>' . $row['resid'] . '</td>'; 
                echo '<td>' . $row['title'] . '</td>';
                echo '<td>' . $row['categories'] . '</td>';
        echo '<td style="WORD-BREAK:BREAK-ALL">' . $row['description'] . '</td>'; 
                echo '<td>' . $row['city'] . '</td>'; 
                echo '<td>' . $row['country'] . '</td>';
                echo '<td>' . $row['zipcode'] . '</td>'; 
                //echo '<td><a href="edit.php?id=' . $row['id'] . '">Edit</a></td>'; 
                //echo '<td><a href="delete.php?id=' . $row['id'] . '">Delete</a></td>'; 
                echo "</tr>"; 
                $counter++;
                        }

Open in new window

0
 
LVL 1

Author Comment

by:adamssap
ID: 36490752
Thanks,

'Description' column has data which will make the table wider and the web page wider too, thats why I am using 'WORD-BREAK:BREAK-ALL' to wrap the text in the column and the web page remains without horizontal scroller.  Is there a better way to do it?
0
 
LVL 7

Expert Comment

by:rgranlund
ID: 36490779
Try This:
<td style="WORD-BREAK:BREAK-ALL;border-right:1px solid #000;">
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 36491078
I normally use fixed column widths which forces the text to wrap.
0
 
LVL 1

Author Closing Comment

by:adamssap
ID: 36491264
Thanks
0
 
LVL 84

Expert Comment

by:Dave Baldwin
ID: 36491411
You're welcome.
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.

705 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