I've been struggling these past days to export a table to PDF in PHP with mpdf, I finally solved most of the problems, however, I'm only able to create the pdf and store it in the server files automaticlly when opening the page, instead I would like to have the pdf only created after pressing a button. Here is my code:
<?php if ( have_posts() ) : while (have_posts() ) : the_post(); ?>
<h3><?php the_title() ?></h3>
<?php ob_start(); ?>
<div id="customers">
<table border='1'>
<thead>
<tr>
<td>
<h1 class="table2" >Periodo de Inversión</h1>
</td>
<td>
<h1 class="table2" >Saldo Inicial</h1>
</td>
<td>
<h1 class="table2" >Inversión en el Periodo</h1>
</td>
<td>
<h1 class="table2" >Interés Causado en el Periodo</h1>
</td>
<td>
<h1 class="table2" >Intereses Pagados</h1>
</td>
<td>
<h1 class="table2" >Intereses Reinvertidos</h1>
</td>
<td>
<h1 class="table2" >Saldo</h1>
</td>
</tr>
</thead>
<tbody>
<?php
if( have_rows('datos_especificos') ):
?>
<?php
while ( have_rows('datos_especificos') ) : the_row();
$icelpx = get_sub_field('interes_causado_en_el_periodo');
$cpx = get_sub_field('cantidad_pagada');
$crx = $icelpx-$cpx;
$sal1x = get_sub_field('saldo');
$ipx = get_sub_field('inversion_en_el_periodo');
$sal2x = $sal1x+$ipx+$crx;
$fech = get_sub_field('fecha');
$sal1 = get_sub_field('saldo');
$ielp = get_sub_field('inversion_en_el_periodo');
$icelp = get_sub_field('interes_causado_en_el_periodo');
$cp = get_sub_field('cantidad_pagada');
$cr = $icelp-$cp;
$crt = $crt+$cr;
$sal2 = $sal1+$ip+$cr;
$igalf = $igalf+$icelp;
$fech2 = $fech+100;
$ID= $the_query->ID;
?>
<tr>
<td>
<p class="table"> <?php the_sub_field('fecha') ?> </p>
</td>
<td>
<p class="table"> <?php the_sub_field('saldo') ?> </p>
</td>
<td>
<p class="table"> <?php the_sub_field('inversion_en_el_periodo') ?> </p>
</td>
<td>
<p class="table"> <?php the_sub_field('interes_causado_en_el_periodo'); ?> </p>
</td>
<td>
<p class="table"> <?php the_sub_field('cantidad_pagada'); ?> </p>
</td>
<td>
<p class="table"> <?php echo $crx; ?> </p>
</td>
<td>
<p class="table"> <?php echo $sal2x; ?> </p>
</td>
</tr>
<?php
endwhile;
else :
// no rows found
endif;
?>
</tbody>
</table>
</div>
<br>
<table>
<tr>
<td>
<p class="table"> Saldo Inicial <?php echo $fech; ?> </p>
</td>
<td>
<p class="table"> <?php echo $sal1; ?> </p>
</td>
</tr>
<td>
<p class="table"> Nuevas Inversiones </p>
</td>
<td>
<p class="table"> <?php echo $ielp; ?> </p>
</td>
<tr>
<td>
<p class="table"> Intereses Pagados </p>
</td>
<td>
<p class="table"> <?php echo $cp; ?> </p>
</td>
</tr>
<tr>
<td>
<p class="table"> Intereses Reinvertidos </p>
</td>
<td>
<p class="table"> <?php echo $crt; ?> </p>
</td>
</tr>
<tr>
<td>
<p class="table"> Total Intereses Generados a la fecha</p>
</td>
<td>
<p class="table"> <?php echo $igalf; ?> </p>
</td>
</tr>
<tr>
<td>
<p class="table"> Saldo Inicial <?php echo $fech2; ?> </p>
</td>
<td>
<p class="table"> <?php echo $sal2; ?> </p>
</td>
</tr>
</table>
<?php $tableVar = ob_get_contents();
$mpdf=new mPDF();
$stylesheet = file_get_contents(get_template_directory_uri() . 'style.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($tableVar,2);
$mpdf->Output('test8.pdf','F');
?>
Generate pdf //THIS BUTTON DOES NOTHING FOR NOW.
<hr>
<?php endwhile; else: ?>
<p>There are no posts or pages here</p>
<?php endif; ?>
To further explain my comment (and this isn't necessarily the best way to do this) you could change the link from this:
Generate pdf
To a form like this:
<form method="post"><input type="submit" value="Generate pdf"/></form>
And then wrap your PDF stuff in something like this:
if( 'POST' === $_SERVER['REQUEST_METHOD'] )
{
$mpdf=new mPDF();
$stylesheet = file_get_contents(get_template_directory_uri() . 'style.css');
$mpdf->WriteHTML($stylesheet,1);
$mpdf->WriteHTML($tableVar,2);
$mpdf->Output('test8.pdf','F');
}
There's some security things and edge cases you might want to consider but this is a good basic start
Related
I have popup it works normal i need to use method post to get my value from the input balise but the problem is when i do form the popup window displays in just a second then hide again and I need to click two time becausethe first time i got just the last result
<div class="List_modify">
<table class="list">
<thead class="topBar">
<tr>
<th>Prenom</th>
<th>Nom</th>
<th>CIN</th>
<th>Emails</th>
<th>Références</th>
<th>Photos</th>
<th>Niveau</th>
<th class="button_editer" style="vertical-align:middle"><span>Editer</span></th>
</tr>
</thead>
<?php $requet = "select * from Etudiants";
$resultat = mysqli_query($connecte, $requet);
while ($r = mysqli_fetch_array($resultat)) {
?>
<tbody class="container">
<tr>
<td>
<?php echo $r['Prenom']; ?>
</td>
<td>
<?php echo $r['Nom']; ?>
</td>
<td>
<?php echo $r['CIN']; ?>
</td>
<td>
<?php echo $r['Emails']; ?>
</td>
<td>
<?php echo $r['Matricule']; ?>
</td>
<td> <img src="image/<?php echo $r['Photo']; ?> " style="width: 150px; height:150px;"></td>
<td>
<?php echo $r['Niveau']; ?> </td>
<td>
<form method="POST" action="">
<input type="hidden" name="id" value="<?php echo $r['Id_Etudiant']; ?>">
<button class=" button" onclick="show()" style="vertical-align:middle" type="submit" name="submit"><span>Editer<i class=" fas fa-user-edit"></i></span>
</button>
</form>
</td>
</tr>
</tbody>
<?php } ?>
</table>
</div>
<div class="background_page_modify" id="page_modify" onclick="hide()">
<div class="page_etudiant" onclick="event.stopPropagation()">
<div class="closebtn" id="closebtn" onclick="hide()">
<div class="circle"> +</div>
</div>
<div class="etudiant_box">
<?php
if (isset($_REQUEST['submit'])) {
$checkid = $_REQUEST['id'];
echo $checkid;
}
?>
</div>
</div>
</div>
I am not sure what is going wrong. But the system is printing the same values again and again, where it should echo the value only once where it is matching student_id in the delivery table. The full code I have edited as requested. This is not executing the query but able display the Table headings.
The code is :
<?php $min = $this->db->get_where('academic_settings' , array('type' =>'minium_mark'))->row()->description;?>
<?php $running_year = $this->db->get_where('settings' , array('type' => 'running_year'))->row()->description; ?>
<div class="content-w">
<div class="conty">
<?php include 'fancy.php';?>
<div class="header-spacer"></div>
<div class="content-i">
<div class="content-box">
<div class="row">
<div class="table-responsive">
<table width="100%" class="table table-striped table-lightfont">
<tbody>
<tr>
<td style="color:black !important; text-transform:uppercase; text-align:center;">
<?php echo get_phrase('Subject_Name');?> :
<span><?php echo $row['name'];?></span>
</td>
</tr>
<tr>
<td>
<table class="table table-padded">
<thead style="background-color:#90be2e; color:white;">
<tr style="padding-bottom:4px; padding-top:4px;">
<th style="color:white;"><?php echo get_phrase('Publish Date');?></th>
<th style="color:white;"><?php echo get_phrase('Assignment');?></th>
<th style="color:white;"><?php echo get_phrase('Faculty');?></th>
<th style="color:white;"><?php echo get_phrase('Last Date');?></th>
<th style="color:white;"><?php echo get_phrase('Submitted On');?></th>
<th style="color:white;"><?php echo get_phrase('Marks');?></th>
<th style="color:white;"><?php echo get_phrase('Feedback');?></th>
</tr>
</thead>
<tbody>
<?php
$uploader_id_student = $this->db->get_where('student', array('student_id' => $this->session->userdata('login_user_id')))->row()->student_id;
$invoices = $this->db->get_where('deliveries', array('student_id' => $uploader_id_student))->result_array();
foreach($invoices as $row2):
?>
<tr>
<td>
<?php echo $this->db->get_where('homework' , array('homework_code'=>$row2['homework_code']))->row()->upload_date;?>
</td>
<td>
<?php
$get_homework_data = $this->db->get_where('homework' , array('homework_code'=>$row2['homework_code']))->row();
echo wordwrap($get_homework_data->title,15,"<br>\n");
?>
</td>
<td>
<?php
echo $this->db->get_where('teacher' , array('teacher_id'=>$get_homework_data->uploader_id))->row()->first_name;
?>
<?php
echo $this->db->get_where('teacher' , array('teacher_id'=>$get_homework_data->uploader_id))->row()->last_name;
?>
</td>
<td>
<?php
$sampleDate1 = $this->db->get_where('homework' , array('homework_code'=>$row2['homework_code']))->row()->date_end;
$convertDate1 = date("d-m-Y", strtotime($sampleDate1));
echo $convertDate1;
?>
</td>
<td>
<?php
$sampleDate = $row2['date'];
$convertDate = date("d-m-Y", strtotime($sampleDate));
echo $convertDate;
?>
</td>
<td style="text-align:center;">
<?php echo $row2['mark'];?>
</td>
<td>
<?php echo wordwrap($row2['teacher_comment'],25,"<br>\n");?>
</td>
</tr>
<?php endforeach;?>
<!--<?php endforeach;?> -->
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
attached is screenshot of table Deliveries is there Deliveries Picture Download
Here is your code updated to fix the performance issues mentioned by Arnold Daniels.
<?php
$uploader_id_student = $this->session->userdata('login_user_id');
$invoices = $this->db->get_where('deliveries', array('student_id' => $uploader_id_student))->result_array();
foreach($invoices as $row2) {
$get_homework_data = $this->db->get_where('homework' , array('homework_code'=>$row2['homework_code']))->row();
$teacher = $this->db->get_where('teacher' , array('teacher_id'=>$get_homework_data->uploader_id))->row();
?>
<tr>
<td>
<?= $get_homework_data->upload_date ?>
</td>
<td>
<?= wordwrap($get_homework_data->title,25,"<br>\n") ?>
</td>
<td>
<?= $teacher->first_name . ' ' . $teacher->last_name ?>
</td>
</tr>
<?php
}
?>
It appears to be working fine as far as I could test it. Is there anything missing from the snippet you posted that could help reproduce your issue?
Edit:
So the complete code would be:
<?php
$min = $this->db->get_where('academic_settings' , array('type' =>'minium_mark'))->row()->description;
$running_year = $this->db->get_where('settings', array('type' => 'running_year'))->row()->description;
?>
<div class="content-w">
<div class="conty">
<?php include 'fancy.php'; ?>
<div class="header-spacer"></div>
<div class="content-i">
<div class="content-box">
<div class="row">
<div class="table-responsive">
<table width="100%" class="table table-striped table-lightfont">
<tbody>
<tr>
<td style="color:black !important; text-transform:uppercase; text-align:center;">
<?php echo get_phrase('Subject_Name'); ?> :
<span><?php echo $row['name']; ?></span>
</td>
</tr>
<tr>
<td>
<table class="table table-padded">
<thead style="background-color:#90be2e; color:white;">
<tr style="padding-bottom:4px; padding-top:4px;">
<th style="color:white;"><?php echo get_phrase('Publish Date'); ?></th>
<th style="color:white;"><?php echo get_phrase('Assignment'); ?></th>
<th style="color:white;"><?php echo get_phrase('Faculty'); ?></th>
<th style="color:white;"><?php echo get_phrase('Last Date'); ?></th>
<th style="color:white;"><?php echo get_phrase('Submitted On'); ?></th>
<th style="color:white;"><?php echo get_phrase('Marks'); ?></th>
<th style="color:white;"><?php echo get_phrase('Feedback'); ?></th>
</tr>
</thead>
<tbody>
<?php
$uploader_id_student = $this->db->get_where('student', array('student_id' => $this->session->userdata('login_user_id')))->row()->student_id;
$invoices = $this->db->get_where('deliveries', array('student_id' => $uploader_id_student))->result_array();
foreach ($invoices as $row2) :
$homework_data = $this->db->get_where('homework', array('homework_code' => $row2['homework_code']))->row();
$teacher = $this->db->get_where('teacher', array('teacher_id' => $get_homework_data->uploader_id))->row();
?>
<tr>
<td>
<?php echo $homework_data->title->upload_date; ?>
</td>
<td>
<?php
echo wordwrap($homework_data->title, 15, "<br>\n");
?>
</td>
<td>
<?php
echo $teacher->first_name;
?>
<?php
echo $teacher->last_name;
?>
</td>
<td>
<?php
$sampleDate1 = $homework_data->date_end;
$convertDate1 = date("d-m-Y", strtotime($sampleDate1));
echo $convertDate1;
?>
</td>
<td>
<?php
$sampleDate = $row2['date'];
$convertDate = date("d-m-Y", strtotime($sampleDate));
echo $convertDate;
?>
</td>
<td style="text-align:center;">
<?php echo $row2['mark']; ?>
</td>
<td>
<?php echo wordwrap($row2['teacher_comment'], 25, "<br>\n"); ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
I would need to see the contents of the included file "fancy.php" to be sure. There was an extra endforeach statement, but I'm guessing that it came from somewhere beyond the scope of the snippet you updated. I would need to see the whole content of the file and the content of the included script in order to determine the true nature of the error.
<!--<?php endforeach;?> -->
Remove this Line
I generating a QR CODE with url as data content, but when i try to print a page where the qr is generated, the qr does not seem to appear yet other content displays. Here is my snippet
<?php
require_once("qrcode.php");
//---------------------------------------------------------
$qr = new QRCode();
// ƒGƒ‰[’ù³ƒŒƒxƒ‹‚ðÝ’è
// QR_ERROR_CORRECT_LEVEL_L : 7%
// QR_ERROR_CORRECT_LEVEL_M : 15%
// QR_ERROR_CORRECT_LEVEL_Q : 25%
// QR_ERROR_CORRECT_LEVEL_H : 30%
$qr->setErrorCorrectLevel(QR_ERROR_CORRECT_LEVEL_L);
$qr->setTypeNumber(4);
$qr->addData("http:/".$_SERVER['REQUEST_URI']."");
$qr->make();
//---------------------------------------------------------
?>
and below is the other content on the page
<div class="invoice-box" id="invoice-box">
<table cellpadding="0" cellspacing="0">
<tr class="top">
<td colspan="2">
<table>
<tr>
<td class="title">
<img src="images/logo.png" style="width:100%; max-width:200px; height:95px;">
</td>
<td>
Invoice #: <?php print $invoice_details->sub_code ?><br>
Created: <?php print date('Y/M/d', strtotime($invoice_details->paid_date)) ?><br>
Due: February 1, 2015
</td>
</tr>
</table>
</td>
</tr>
<tr class="information">
<td colspan="2">
<table>
<tr>
<td>
<br>
<br>
</td>
<td>
<?php print $invoice_details->org ?><br>
<?php print $invoice_details->lname ?> <?php print $invoice_details->fname ?><br>
<?php print $invoice_details->email ?>
</td>
<td>
<?php $qr->printHTML(); ?>
</td>
</tr>
</table>
</td>
</tr>
<tr class="heading">
<td>
Payment Method
</td>
<td>
</td>
</tr>
<tr class="details">
<td>
<?php print $invoice_details->method ?>
</td>
<td>
</td>
</tr>
<tr class="heading">
<td>
Item
</td>
<td>
Price(UGX)
</td>
</tr>
<tr class="item">
<td>
<?php print ucfirst($invoice_details->event) ?> - Summit
</td>
<td>
<?php print number_format($invoice_details->amount) ?>
</td>
</tr>
<tr class="total">
<td></td>
<td>
Total: UGX <?php print number_format($invoice_details->amount) ?>
</td>
</tr>
</table>
</div>
<input type="button" value="Print Div" onclick="PrintElem('#invoice-box')" />
and my printing script
<script type="text/javascript">
function PrintElem(elem)
{
Popup($(elem).html());
}
function Popup(data)
{
var mywindow = window.open('', 'invoice-box', 'height=400,width=600');
mywindow.document.write('<html><head><title>my div</title>');
/*optional stylesheet*/ //mywindow.document.write('<link rel="stylesheet" href="main.css" type="text/css" />');
mywindow.document.write('</head><body >');
mywindow.document.write(data);
mywindow.document.write('</body></html>');
mywindow.document.close(); // necessary for IE >= 10
mywindow.focus(); // necessary for IE >= 10
mywindow.print();
mywindow.close();
return true;
}
</script>
Assuming I found the correct library, it has an image creator. What you need to do is use an output buffer around the imagegif (or imagepng) call to capture the image's binary data into a string, then base64 encode the string, and echo that as part of a data URI directly in the src attribute of an img tag.
$img = $qr->createImage(4, 2);
ob_start();
imagegif($img);
imagedestroy($img);
$img = ob_get_clean();
In your HTML
<img src="data:image/gif;base64,<?php echo base64_encode($img);?>">
If you're concerned about support for data URLs, leave out the output buffering, add a unique, random filename as the second parameter to the imagegif call to save it, then echo that filename in the src.
It seems that you're trying to print a black background color which is removed by default from printing. Unfortunately there's no way to force it back programatically in browsers other than Safari and Chrome.
You can force this back for Safari and Chrome by doing:
<div class="invoice-box" id="invoice-box">
<style>
.invoice-box table td: {
-webkit-print-color-adjust: exact !important;
}
</style>
<table cellpadding="0" cellspacing="0">
<tr class="top">
<td colspan="2">
<table>
<tr>
<td class="title">
<img src="images/logo.png" style="width:100%; max-width:200px; height:95px;">
</td>
<td>
Invoice #: <?php print $invoice_details->sub_code ?><br>
Created: <?php print date('Y/M/d', strtotime($invoice_details->paid_date)) ?><br>
Due: February 1, 2015
</td>
</tr>
</table>
</td>
</tr>
<tr class="information">
<td colspan="2">
<table>
<tr>
<td>
<br>
<br>
</td>
<td>
<?php print $invoice_details->org ?><br>
<?php print $invoice_details->lname ?> <?php print $invoice_details->fname ?><br>
<?php print $invoice_details->email ?>
</td>
<td>
<?php $qr->printHTML(); ?>
</td>
</tr>
</table>
</td>
</tr>
<tr class="heading">
<td>
Payment Method
</td>
<td>
</td>
</tr>
<tr class="details">
<td>
<?php print $invoice_details->method ?>
</td>
<td>
</td>
</tr>
<tr class="heading">
<td>
Item
</td>
<td>
Price(UGX)
</td>
</tr>
<tr class="item">
<td>
<?php print ucfirst($invoice_details->event) ?> - Summit
</td>
<td>
<?php print number_format($invoice_details->amount) ?>
</td>
</tr>
<tr class="total">
<td></td>
<td>
Total: UGX <?php print number_format($invoice_details->amount) ?>
</td>
</tr>
</table>
</div>
<input type="button" value="Print Div" onclick="PrintElem('#invoice-box')" />
For browsers like IE and Firefox unfortunately this requires user interaction. See this question for more answers: Printing background-color in Firefox and IE
Finally, i got a way around this, here is my solution
<?php
require_once("qrcode.php");
$qr = QRCode::getMinimumQRCode("http:/".$_SERVER['REQUEST_URI']."", QR_ERROR_CORRECT_LEVEL_L);
$img = $qr->createImage(4, 2);
ob_start();
imagegif($img);
imagedestroy($img);
$img = ob_get_clean();
?>
Then output the qrcode as image with this;
<img src="data:image/gif;base64,<?php echo base64_encode($img);?>">
Thanks to #walf for his solution somehow, hope it helps someone else.
My question to you is as follows. I have created a form that is populated from a mysql database. Id like to be able to edit that form after it has been submitted. I have got it to the point where it will allow me to edit the fields in the form but when i do so the data is not updated on the database. Could you have a look at my code and see where i might be going wrong?
<?php
include_once 'includes/db_connect.php';
?>
</head>
<body>
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headingsa7">Acceptance Criteria</td>
<td class="headingsa8">Technician Responsible</td>
</tr>
<tr>
<td class="headings1">Job/Order Number:</td>
<td class="answers1"><div class= "typesection1">
<?php echo ($row['job_order_number'] ); ?></div></td>
<tr>
<td class="answersa7">
<div class= "typesectiona7">
<?php
echo ($row['acceptance_criteria1'] );
?>
</div>
</td>
<td class="answersa8">
<div class= "typesectiona8">
<?php
echo($row['technician_responsible1'] );
?>
</div></td>
</tr>
<tr>
<td class="answersa7">
<div class= "typesectiona7">
<?
php echo ($row['acceptance_criteria2'] );
?>
</div></td>
<td class="answersa8">
<div class= "typesectiona8">
<?php
echo ($row['technician_responsible2'] );
?>
</div>
</td>
</tr>
<tr>
<td class="answersa7">
<div class= "typesectiona7">
<?php
echo ($row['acceptance_criteria3'] );
?>
</div>
</td>
<td class="answersa8">
<div class= "typesectiona8">
<?php
echo ($row['technician_responsible3'] );
?>
</div>
</td>
</tr>
<tr>
<td class="answersa7">
<div class= "typesectiona7">
<?php
echo($row['acceptance_criteria4'] );
?>
</div>
</td>
<td class="answersa8">
<div class= "typesectiona8">
<?php
echo($row['technician_responsible4'] );
?>
</div>
</td>
</tr>
</table>
<br /><br />
<center>
<?php echo "Edit | Delete |
?>
</center>
</div>
</body>
</html>
edit page.php
</head>
<body>
<?php
mysql_connect("localhost","username","password");
mysql_select_db("joziweb1_form");
$order = "SELECT * FROM jobrequest";
$result = mysql_query($order);
$row = mysql_fetch_array($result);
?>
<form method="post" action="edit_data.php">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headingsa7">Acceptance Criteria</td>
<td class="headingsa8">Technician Responsible</td>
</tr>
<tr>
<td class="headings1">Job/Order Number:</td>
<td class="answers1">
<div class= "typesection1">
<?php
echo $_GET['job_order_number'];
?>
</div>
</td>
<tr>
<td class="answersa7">
<div class= "typesectiona7">
<?php
echo ($row['acceptance_criteria1'] );
?>
</div>
</td>
<td class="answersa8"><input class="typesectiona8" type="text" name="Technician_responsible1"value=<?php echo $technician_responsible1;?>>
</td>
</tr>
<tr>
<td class="answersa7">
<div class= "typesectiona7">
<?php echo ($row['acceptance_criteria2'] ); ?>
</div>
</td>
<td class="answersa8">
>
<td class="answersa8">
>
>
Edit_data.php
<?php
mysql_connect("localhost","username","password");
mysql_select_db("databasename");
$order = "UPDATE jobrequest,
SET technician_responsible1='$Technician_responsible1', technician_responsible2='$Technician_responsible2' technician_responsible3='$Technician_responsible3', technician_responsible4='$Technician_responsible4',
WHERE 'technician_responsible1' , 'technician_responsible2' , 'technician_responsible3' , 'technician_responsible4' , “;
mysql_query($order);
header("location:jobrequest_viewform.php");
?>
in a edit.php page add this code
session_start();
$_SESSION['no']=$_GET['job_order_number'];
in a edit_data.php
session_start();
$no=$_SESSION['no'];
then use
$order = "UPDATE jobrequest,
SET technician_responsible1='$Technician_responsible1',technician_responsible2='$Technician_responsible2',technician_responsible3='$Technician_responsible3',technician_responsible4='$Technician_responsible4',
WHERE job_order_number='$no'“;
mysql_query($order);
try this maybe it work..
This is the code, and as written in the title, I'm trying to have each column with the same width:
<div class="table-responsive">
<table class="table table-striped table-hover">
<thead>
<tr>
<th>N°</th>
<th>Data</th>
<th>Compratore</th>
<th>Venditore</th>
<th>Merce</th>
<th>Quantita'</th>
<th>Prezzo</th>
<th>Pagamento</th>
<th>Azioni</th>
</tr>
</thead>
<tbody>
<?php
$result = query("SELECT numero_contratto, anno_contratto, data, C.denominazione as compratore, V.denominazione as venditore, merce, quantita, info_quantita, prezzo, info_prezzo, pagamento FROM Contratti, Societa V, Societa C WHERE compratore = C.id_societa and venditore = V.id_societa ORDER BY data DESC", $conn);
foreach($result as $r)
{
?>
<tr>
<td>
<?php echo $r['numero_contratto']."/".$r['anno_contratto']; ?>
</td>
<td>
<?php
$data = explode("-", $r['data']);
echo $data[2]."-".$data[1]."-".$data[0];
?>
</td>
<td>
<?php echo $r['compratore']; ?>
</td>
<td>
<?php echo $r['venditore']; ?>
</td>
<td>
<?php echo $r['merce']; ?>
</td>
<td>
<?php echo $r['quantita']." ".$r['info_quantita']; ?>
</td>
<td>
<?php echo $r['prezzo']." ".$r['info_prezzo']; ?>
</td>
<td>
<?php echo $r['pagamento']; ?>
</td>
<td>
<span class="glyphicon glyphicon-remove"></span>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
And this is the output on my web page:
But if you see this Fiddle with static values putted into the table, the problem doesn't show!
http://jsfiddle.net/brVa9/1/
So the problem is inside the db schema or structure.
What I should do to have all the columns with the same width?