Daniel Murran
Daniel Murran

Reputation: 105

Inline Styling in PHP

I am styling a page that has PHP in the middle that echos out a table. I have the html centered through an external style sheet but the PHP section(where the table is wont center) so I am thinking the best way to style this is for inline css in the php section. any help is appreciated.

// display data in table




echo "<table border='1'  cellpadding='2' class='footable mdl-data-table mdl-js-data-table mdl-data-table--selectable mdl-shadow--4dp full-width'>";

echo "<tr> <th>ID</th> <th>Administration Console</th> <th>Product Version</th> <th>Platform</th> <th>Database</th> <th>Owner</th> <th>Status</th> <th></th> <th></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 '<th>' . $row['id'] . '</th>';

echo '<td><a href="'.$row['curl'].'">'.$row['curl'].'</a></td>';

echo '<td>' . $row['pversion'] . '</td>';

echo '<td>' . $row['platform'] . '</td>';

echo '<td>' . $row['dversion'] . '</td>';

echo '<td><a href="mailto:'.$row['email'].'">' . $row['email'].'</a></td>';

echo '<td>' . $row['status'] . '</td>';

echo '<td><a href="php/edit.php?id=' . $row['id'] . '">Edit</a></td>';

echo '<td><a onclick="javascript:confirmationDelete($(this));return false;" href="php/delete.php?id=' . $row['id'] . '"onclick="return confirm("Do you want to delete this?")">Delete</a></td>';

echo "</tr>";

}





// close table>

echo "</table>";

?> 

Upvotes: 1

Views: 33223

Answers (2)

lifanko lee
lifanko lee

Reputation: 46

The same style mark in the front will be covered. example:

<style>
    th, td{
        text-align: center;
    }
    th, td{
        text-align: left;
    }
</style>

Then the text would be display from left.

To solve the problem simply, you can try to add these code below all of the css links:

<style>
    th, td{
        text-align: center;
    }
</style>

If it doesn't work, I suggest that you try this :-)

echo '<th style="text-align: center">' . $row['id'] . '</th>';

Upvotes: 1

Eugene van der Merwe
Eugene van der Merwe

Reputation: 91

You can use this but all tables will be centered

table {
    margin: 0 auto;
}

or define a class to identify the specific table

table .customClass {
    margin: 0 auto;
}

<table border='1' cellpadding='2' class='customClass footable mdl-data-table mdl-js-data-table mdl-data-table--selectable mdl-shadow--4dp full-width'>

or you can try using align="center"

<table align="center" border='1' cellpadding='2' class='footable mdl-data-table mdl-js-data-table mdl-data-table--selectable mdl-shadow--4dp full-width'>

Hope this might help you.

Upvotes: 3

Related Questions