Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Horizontal line after each row

Posted on 2011-09-06
11
Medium Priority
?
351 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
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

885 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