I have a searchable database.. I would like to change the style of how the table is displayed...
I have a css file of how I would like the table displayed.. Can that be done? If so..How?

Recommended Answers

All 4 Replies

Member Avatar for diafol

Yes. Provide your code and tell us how you'd like it changed.

<?php
mysql_connect ("localhost", "","")  or die (mysql_error());
mysql_select_db ("");
if(isset($_POST['submit']) && !empty($_POST['submit'])){
    $result = ""; //USED LATER
    /*$term = $_POST['term']; THIS WORKS BUT FOR SECURITY ISSUES USE:*/
    $term = mysql_real_escape_string($_POST['term']);//AVOID MYSQL INJECTION
    $sql = mysql_query("SELECT * FROM `INFO` where INFO like '%$term%' OR Data like '%{$term}%'");
     if (mysql_num_rows($sql) <= 0) {
        // no results
        //echo 'No results found.'; BETTER ECHO LATER
        $error = "No result found";
    } else if ($term ="") {
        $error = "No name entered!";
    } else {
        $result .= "<table border='1'>";
        $result .="<tr><td>INFO</td><td>INFO</td><td>INFO</td></tr>";
        while ($row = mysql_fetch_array($sql)){
            $result .= '<tr>';
            $result .= '<td>'.$row['Data'].'</td>';
            $result .= '<td>'.$row['Data'].'</td>';
            $result .= '<td>'.$row['Data'].'</td>';
            $result .= '</tr>';
        }
        $result .= "</table>"; 
    }
     mysql_close();
}
?>

and this is the css that i want:

table.hovertable {
    font-family: verdana,arial,sans-serif;
    font-size:11px;
    color:#333333;
    border-width: 1px;
    border-color: #999999;
    border-collapse: collapse;
}
table.hovertable th {
    background-color:#c3dde0;
    border-width: 1px;
    padding: 8px;
    border-style: solid;
    border-color: #a9c6c9;
}
table.hovertable tr {
    background-color:#d4e3e5;
}
table.hovertable td {
    border-width: 1px;
    padding: 8px;
    border-style: solid;
    border-color: #a9c6c9;
}

and this is the tr

<tr onmouseout="this.style.backgroundColor='#d4e3e5';" onmouseover="this.style.backgroundColor='#ffff66';">

I've tried quite a few things but keep on coming up with errors...

<center><table class="hovertable">
    <tbody>
        <tr>
            <th>INFO</th>
            <th>INFO</th>
                        <th>INFO</th>
        </tr>
        <tr onmouseout="this.style.backgroundColor='#d4e3e5';" onmouseover="this.style.backgroundColor='#ffff66';">
            <td>Data</td>
            <td>Data</td>
                        <td>Data</td>
        </tr>
</tr>
    </tbody>
</table></center>

I changed: $result .= "<table border='1'>"; to $result .= "<table border='1' class='hovertable'>";

So now it does display the table as I want but i don't see it highlighting the rows

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.