简体   繁体   中英

Basic css styles(like border-bottom) are not affecting on dynamic created table

I'm reading a table data from MYSQL and writing it in html format to generate PDF (using TCPDF LIbrary) . but in resulting PDF only some of inline html CSS are affecting including(color,width.height) but other css like border-botttom(which I need the most) or all others ar being ignored by library.

$bookings_table_Result = mysql_query($bookings_table_query);
$tbl_header = '<table style=\"width:900px; border: 1px solid black; padding:0px;\">';
$tbl_footer = '</table>';
$tbl = '';

    while($row = mysql_fetch_array($bookings_table_Result)){
    $checkin = $row["checkin"];
    $checkout = $row["checkout"];
    $nights = $row["nights"];
    $guest = $row["guest"];
    $country = $row["country"];
    $guestcount = $row["guestcount"];
    $amount = $row["amount"];

    $tbl .= '<tr >

            <td style="border-bottom: solid 1px Black; width: 80px;">'.$checkin.'</td>
            <td style="border: 1px solid #000000; width: 80px;">'.$checkout.'</td>
            <td style="border: 1px solid #000000; width: 20px;">'.$nights.'</td>
            <td style="border: 1px solid #000000; width: 200px;">'.$guest.'</td>
            <td style="border: 1px solid #000000; width: 150px;">'.$country.'</td>
            <td style="border: 1px solid #000000; width: 40px;">'.$guestcount.'</td>
            <td style="border: 1px solid red; width: 80px; color: blue;">'.$amount.'</td>
            </tr>';
     };
$tbl .= '</table>';

$pdf->writeHTML($tbl, true, false, true, false, '');

I Uploaded the picture of Result PDF

在此处输入图片说明

You have a typo error in the line you use border-bottom , see:

... '<table style="width: 900px; border-bottom:1pt solid black;" border: 1px; cellspacing="0">';
                        This is out of the style attribute!! ------^

From the look of it, you are not generating a valid html table: You don't seem to add the table header to your $tbl variable.

If that is not the problem (you don't show where you output the table...), you'd better post the generated html instead of the php as this seems more related to html and css than php .

when you echo a style in html using php try changing your code to something like this:

 $tbl .= '<tr >
        <td style=\"border: 1px solid #000000; width: 80px;\">'.$checkin.'</td>
        <td style=\"border: 1px solid #000000; width: 80px;\">'.$checkout.'</td>
        <td style=\"border: 1px solid #000000;  width: 20px;\">'.$nights.'</td>
        <td style=\"border: 1px solid #000000; width: 200px;\">'.$guest.'</td>
        <td style=\"border: 1px solid #000000; width: 150px;\">'.$country.'</td>
        <td style=\"border: 1px solid #000000; width: 40px;\">'.$guestcount.'</td>
        <td style=\"border: 1px solid #000000; width: 80px;\">'.$amount.'</td>
        </tr>';

when using single quote '' you need need to include backslashes to tell the server to keep the "" when echoing your table.

I had a similar problem when i was using php to echo my tables from mysql db.

jeroen makes a good point. You need to add the beginning table declaration if you want to create a valid html table.

You also seem to be styling the table outside of your style definition as well.

change

$tbl_header = '<table style="width: 900px; border-bottom:1pt solid black;" border: 1px; cellspacing="0">';

to

$tbl_header = '<table style=\\"width:900px; border-bottom:1px solid black; border: 1px solid black; padding:0px;\\">

However probably no point in the border on the bottom then one on the entire table because your last border declaration is going to override the previous one. . .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM