Tables from MySQL query results

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Cowbie
    New Member
    • Nov 2007
    • 5

    Tables from MySQL query results

    Hello again,

    I'm using a MySQL database and I want to pull results from the database and put them onto a php page. I've currently got it working using the following code, but it's not exactly what I want:

    $query = 'SELECT * FROM loan';
    $result = mysql_query($qu ery) or die('No Loans Found: ' . mysql_error());

    // Printing results in HTML
    echo "<table>";
    while ($line = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
    echo "<br>\t<tr> \n";
    foreach ($line as $col_value) {
    echo "\t\t<td>$col_v alue</td>\n";
    }
    echo "\t</tr>\n";
    }
    echo "</table>\n";

    Basically, I want the table to have a border and a background, but no matter what I try it just messes the code up so it no longer works.

    Can anyone throw me a few pointers?
    Thanks.
  • brettl
    New Member
    • Sep 2007
    • 41

    #2
    You can always use CSS and add a class to your query result table to set a background color and a border around the table.

    Comment

    Working...