Click here to Skip to main content
16,019,619 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
HY!
I know how to use table in html very well, but the error iam facing know is un-understandable for me...I know how to use table in html very well, but the error iam facing know is un-understandable for me...
Here is my code...
HTML
<html>
<head>
<title>tets</title>
<style>
table
{
    border: 1px solid black;
    border-collapse: separate;
    border-spacing: 2px;
    border-color: gray;
    text-align: center;
    width: 500px;
    max-width: 500px;
}
th
{
    border-bottom:1px solid gray;
    border-spacing: 2px;
    padding-left: 15px;
    padding-right: 15px;
    text-align: center;
    background: silver;
}
td
{
    max-width:500px;
    background: silver;
}
.tbl
{
    margin-top:200px;
    margin-left: 230px;
}
</style>

</head>
<body>
    <div class="tbl">
<table>
    <tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>UserName</th>
    <th>Email</th>
    <th>Password</th>
</tr>
    <tr>
        <td>Zaffar</td>
        <td>Khan</td>
        <td>MSZ</td>
        <td>M@yahoo.com</td>
        <td>123</td>
    </tr>
    <tr>
        <td>Zaffar</td>
        <td>Khan</td>
        <td>MSZ</td>
        <td>M@yahoo.com</td>
        <td>123</td>
    </tr>
    <tr>
        <td>Zaffar</td>
        <td>Khan</td>
        <td>MSZ</td>
        <td>M@yahoo.comgggggggggggggggggggggggggg</td>
        <td>123ggggggggggggggggggggggggggggggggggggggggggghjjjjjjjjjjjjjjjjjjjjjjfjyhfffffffffffffffffffffffffuyyyyyxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</td>
    </tr>
</table>
</div>
</body>
</html>

the error is when i enter the long data like you seen above and controll the width of the table, then the data will conflict, mean the data is out of cell and cross the width.. please run the code and check what is the error....
i want the data within the table and with a width i specifies..
Posted
Updated 30-Nov-13 11:21am
v2

1 solution

Because you have no space characters in the long <TD> tags, the browser doesn't know where to wrap the contents.

Option 1
This is a sample of how a string value from the database can be processed to insert <BR> tags every so many characters and create a new string that can be used in the HTML table cell. I used 20 for the width value. This sample is in VB. You can convert to whatever language you are using. By doing this, you are not modifying the value in the database. You are processing the data for display so that it appears properly.
VB
Dim strFromdatabase As String = "123ggggggggggggggggggggggggggggggggggggggggggghjjjjjjjjjjjjjjjjjjjjjjfjyhfffffffffffffffffffffffffuyyyyyxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"

Dim strNewString As String ' New string to be output into the table cell
Dim x As Integer ' Number of characters left to process
Dim y As Integer ' Current index into source string
Dim z As Integer ' Number of characters to process this time through the loop
Const CELLWIDTH As Integer = 20
x = strFromdatabase.Length
y = 0
strNewString = ""
While x > 0
    z = Math.Min(CELLWIDTH, x)
    strNewString += strFromdatabase.Substring(y, z)
    x = x - z
    y = y + z
    If x > 0 Then
        strNewString += "<BR>"
    End If
End While
Debug.WriteLine(strNewString)



Option 2
Use the Width attribute in the <TH> and <TD> tags or define a new style in your stylesheet that contains the Width property and use that style for the Email and Password columns.


<tr>
    <th>First Name</th>
    <th>Last Name</th>
    <th>UserName</th>
    <th Width=100>Email</th>
    <th Width=100>Password</th>
</TR>
 
Share this answer
 
v11
Comments
msz900 30-Nov-13 11:26am    
not working!
Mike Meinz 30-Nov-13 11:36am    
Write some code that will insert <BR> tags every x characters in the long strings in the email and password columns where x is the width that you want for that column. This will force a wrap effect.
msz900 30-Nov-13 12:02pm    
any example please
Mike Meinz 30-Nov-13 12:10pm    
<td>123ggggggggggggggggggggggggggggggggg<BR>ggggggghjjjjjjjjjjjjjjjjjjjjjjfjy<BR> hfffffffffffffffffffffffffuyyyyyx<BR>xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx</td>
msz900 30-Nov-13 12:18pm    
iam getting password from database in table so for that <br> will not help, if he will then how?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900