Solved

Horizontal line after each row

Posted on 2011-09-06
11
338 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
Comment Utility
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
Comment Utility
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 82

Expert Comment

by:Dave Baldwin
Comment Utility
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
 
LVL 1

Author Comment

by:adamssap
Comment Utility
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
Comment Utility
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
Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

 
LVL 82

Accepted Solution

by:
Dave Baldwin earned 500 total points
Comment Utility
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
Comment Utility
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
Comment Utility
Try This:
<td style="WORD-BREAK:BREAK-ALL;border-right:1px solid #000;">
0
 
LVL 82

Expert Comment

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

Author Closing Comment

by:adamssap
Comment Utility
Thanks
0
 
LVL 82

Expert Comment

by:Dave Baldwin
Comment Utility
You're welcome.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Part of the Global Positioning System A geocode (https://developers.google.com/maps/documentation/geocoding/) is the major subset of a GPS coordinate (http://en.wikipedia.org/wiki/Global_Positioning_System), the other parts being the altitude and t…
Not sure what the best email signature size is? Are you worried about email signature image size? Follow this best practice guide.
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
In this tutorial viewers will learn how to code links for mobile sites that, once clicked, send a call or text to a specified number. For a telephone link (once clicked, calls a number), begin with a normal "<a href=" link tag. For the href, specify…

728 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now