Border around specific table row - php

I am trying to create a border around the top row ONLY! Currently, a border will be displayed only around the outside of the table. But I also want a border around the first row. Can someone help me do this? I want the row with 'Team, Correct Picks, and Points' to have a border around it.
<body>
<?=$leaguename?>
<center><table cellspacing="0" style="width:400px; border:1px solid gray">
<?
echo "<tr border=\"1\"><td> Team </td><td>Correct Picks</td><td>Points</td></tr>";
while($row = mysql_fetch_array($memberslist)) {
if ($row['User_ID'] == $id) {
echo "<tr style=\"border:1px solid gray\" bgcolor=\"gray\"><td>" . $row['User_ID'] . "</td><td><b>" . $row['Correct_Picks'] . " </b> /" . $maxcorrectpicks . "</td><td>" . $row['Points'] . "</td></tr>";
} else {
echo "<tr><td>" . $row['User_ID'] . "</td><td><b>" . $row['Correct_Picks'] . " </b> /" . $maxcorrectpicks . "</td><td>" . $row['Points'] . "</td></tr>";
}
}
?>
</table></center>
</body>

This is presentational, so mixing it into the PHP is a bad idea. Instead, use CSS:
tr:first-child td { border-top: 1px solid black; border-bottom: 1px solid black; }
tr:first-child td:first-child { border-left:1px solid black; }
tr:first-child td:last-child { border-right:1px solid black; }
IE7+8 support for the *-child selectors can be a bit buggy. If it's not working in those browsers, consider using JavaScript polyfills.
You may also want to put the headers inside <thead> and <th> elements to make the <tr> with data the first row in a <tbody> element.
e.g.
<table>
<thead>
<tr>
<th>Team</th>
</tr>
</thead>
<tbody>
<tr>
<td>1</td>
</tr>
</tbody>
</table>

Related

Ranking by number of points with php

I have a question. I'm currently working on a ranking list webprogram for a shooting club made with php and html.
Now I'm at the point, where I want to print out the ranking table with the results from my sql database. The ranking table is showing a rank, personal informations and the results. The results where sort by the scored points.
My problem now is, that I dont know how to make an automatic rank per person. The only thing I managed to do is this:
Output
Here is my code:
<!DOCTYPE html>
<html>
<body>
<div>
<h3 style='color:green; font-weight: 700;'> <?php echo "Rangliste $infos" ?> </h3>
<a class='btn btn-default' href='?page=rangliste'>Zurück</a>
<a class='btn btn-default' href='?page=rangliste_veteranencup'> <span class=''></span> Veteranen Cup</a>
<a class='btn btn-default' href='?page=rangliste_dianacup'><span class=''></span>Diana Cup</a>
<a class='btn btn-default' href='?page=rangliste_gäste'><span class=''></span>Gäste Cup</a>
<style>
table {
border-collapse: collapse;
width: 90%;
color: black;
font-size: 12px;
text-align: left;
}
div {
margin-left: 50px;
}
th {
border: 1px solid black;
background-color: #D3DFDD;
}
td {
text-align: center;
border: 1px solid black;
background-color: white;
}
.outlined {
border: 2px solid black;
}
</style>
<p></p>
<table>
<colgroup>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col>
<col class='outlined'>
<col span='3'>
</colgroup>
<tr>
<th scope='col'>Rang</th>
<th scope='col'>Vorname</th>
<th scope='col'>Nachname</th>
<th scope='col'>Jahrgang</th>
<th scope='col'>Wohnort</th>
<th scope='col'>Total Reh</th>
<th scope='col'>Total Gams</th>
<th scope='col'>Total Klapphas</th>
<th scope='col'>Total Rollhas</th>
<th scope='col'>Gesamttotal</th>
<th scope='col'>Tiefschuss Reh</th>
<th scope='col'>Tiefschuss Gams</th>
</tr>
<?php
$conn = mysqli_connect("localhost", "root", "", "art");
if ($conn-> connect_error) {
die("Connection failed" . $conn-> connect_error);
}
$sql = "SELECT schuetze.vorname, schuetze.nachname, schuetze.jahrgang, schuetze.ort,
resultate.vmTotalReh, resultate.vmTotalGams, resultate.vmTotalKlapphas, resultate.vmTotalRollhas, resultate.vmTotal, resultate.vmTiefschussReh, resultate.vmTiefschussGams
FROM schuetze
JOIN resultate ON schuetze.id = resultate.schuetzeID
WHERE resultate.anlassID = ? ORDER BY resultate.vmTotal DESC, resultate.vmTotalKlapphas DESC, resultate.vmTotalRollhas DESC, resultate.vmTotalReh DESC, resultate.vmTotalGams DESC, resultate.vmTiefschussReh DESC, resultate.vmTiefschussGams DESC, schuetze.jahrgang DESC";
$stmt = $conn->prepare($sql);
$stmt->bind_param("i", $res_anlassID);
$stmt->execute();
$result = $stmt->get_result();
while ($row = $result-> fetch_assoc()) {
echo "</td><td>"/* . $rang . "</td><td>" */. $row['vorname'] . "</td><td>" . $row['nachname'] . "</td><td>" . $row['jahrgang'] . "</td><td>" . $row['ort'] . "</td><td>" . $row['vmTotalReh'] . "</td><td>" . $row['vmTotalGams'] . "</td><td>" . $row['vmTotalKlapphas'] . "</td><td>" . $row['vmTotalRollhas'] . "</td><td>" . $row['vmTotal'] . "</td><td>" . $row['vmTiefschussReh'] . "</td><td>" . $row['vmTiefschussGams'] . "</td></tr>";
}
echo "</table>";
$conn-> close();
?>
</div>
</body>
</html>

How do i put a <td> in my <table> with php?

I’m working on a php snippet and i made a table. I tried putting a td tag inside but when i do this, a lot disappears. This is a piece of my code:
//Use the functions of the client, the params of the function are in
//the associative array
$params = array('customerid' => '1532');
$response = $soapclient->ca_customer_products($params);
echo '<table><tbody><tr><th>Product</th><th>Naam</th> <th>Prijs</th><th>Qte</th></tr>';
echo '<table style="border-style: solid; border-width:1px;">';
foreach($response->list->element as $product) {
if($product->stock > 0) {
echo '<tr>';
echo '<td style="display: flex; border: 1px solid black;">';
//echo '<td>';
echo '<img src="' . $product->url . '" class="php_image" style="width: 15%; height: 15%;"/>';
//echo '<img style="width: 15%;">';
//echo '</td>';
print_r($product->description);
echo "<p style='color:green;'>".$product->price1."</p>";
echo "<p style='color:red; text-decoration: line-through'>".$product->price2."</p>";
print_r($product->price1);
print_r($product->price2);
print_r($product->stock);
echo '</tr>';
}
}
echo '</tbody></table>';
The code behind the // is where i tried to put the td tag but when i put it there, the images that normally appear go blank and when i inspect my code there is a lot of other code that also disappears. What am i doing wrong here?
Thank you for your help!
First I can see a problem with these lines :
echo '<table><tbody><tr><th>Product</th><th>Naam</th> <th>Prijs</th><th>Qte</th></tr>';
echo '<table style="border-style: solid; border-width:1px;">';
Because you just close your first TABLE at the end, but not the other inside :
echo '</tbody></table>';
There are some inconsistency of your <td> to <th>. You can have a look below
$params = array('customerid' => '1532');
$response = $soapclient->ca_customer_products($params);
echo '<table style="border-style: solid; border-width:1px;">
<thead>
<tr>
<th>Product</th>
<th>Naam</th>
<th>Prijs</th>
<th>Qte</th>
</tr>
</thead><tbody>';
foreach($response->list->element as $product) {
if($product->stock > 0) {
echo "<tr>
<td style='display: flex; border: 1px solid black;'>
<img src='$product->url' class='php_image' style='width: 15%; height: 15%;'/>
</td>
<td>Your product name</td>
<td>$product->description</td>
<td>
<p style='color: green;'>$product->price1</p>
<p style='color: red;'>$product->price</p>
</td>
<td>$product->stock</td>
</tr>";
}
}
echo '</tbody></table>';
?>
There's a lot problems with the code. From what i can see in your code, you have a table inside a tbody and at the end closed only one table.
Secondly you're also trying to put a td inside another td which is not the right thing to do. Check out mozilla developer website for more information on using HTML tables.
//Use the functions of the client, the params of the function are in
//the associative array
$params = array('customerid' => '1532');
$response = $soapclient->ca_customer_products($params);
echo '<table style="border-style: solid; border-width:1px;"><tbody><tr><th>Product</th><th>Naam</th> <th>Prijs</th><th>Qte</th></tr>';
foreach($response->list->element as $product) {
if($product->stock > 0) {
echo '<tr>';
echo '<td style="display: flex; border: 1px solid black;">';
//echo '<td>';
echo '<img src="' . $product->url . '" class="php_image" style="width: 15%; height: 15%;"/>';
//echo '<img style="width: 15%;">';
//echo '</td>';
print_r($product->description);
echo "<p style='color:green;'>".$product->price1."</p>";
echo "<p style='color:red; text-decoration: line-through'>".$product->price2."</p>";
print_r($product->price1);
print_r($product->price2);
print_r($product->stock);
echo '</td></tr>';
}
}
echo '</tbody></table>';
You are not closing your tags correctly. Also checkout the docs just as #christopher_bincom has mentioned.

Preg_match_all how to correctly get all info?

Can't understand how correctly get all info from web, not just one row but all.
This script produces the output : Array Array Array Array and only one row.
<table id="rounded-corner" width=100%>
<tr>
<td>Nuotrauka</td>
<td>Pavadinimas</td>
<td>miestas</td>
<td>metai</td>
<td>kaina</td>
</tr>
<?
$url = "My Link";
$contents = file_get_contents($url);
preg_match_all("|<span class=\"ttitle2\">(.*?) </span>|U",$contents,$pavadinimas);
preg_match_all("|<span class=\"ttitle3\">(.*?)</span>|U",$contents,$miestas);
preg_match_all("|<span class=\"ttitle1\">(.*?)</span>|U",$contents,$metai);
preg_match_all("|<span class=\"ttitle1\" style='float: left;'>(.*?)<br />|U",$contents,$kaina);
preg_match_all("/<img .*?(?=src)src=\"([^\"]+)\"/si", $contents, $img_link);
$output = "<tr><td><img src=$img_link></td><td>$pavadinimas</td><td>$miestas</td><td>$metai</td><td>$kaina</td></tr>";
print_r($output);
?>
</table>
Try this. It is extracting data as required.
<table style="border: 1px solid black;" id="rounded-corner" width=100%>
<tr>
<td style="border: 1px solid black;">Nuotrauka</td>
<td style="border: 1px solid black;">Pavadinimas</td>
<td style="border: 1px solid black;">miestas</td>
<td style="border: 1px solid black;">metai</td>
<td style="border: 1px solid black;">kaina</td>
</tr>
<?php
$url = "put_your_url";
$contents = file_get_contents($url);
preg_match_all('/<span class="ttitle2".*?>(.*?)<\/span>/',$contents,$pavadinimas);
preg_match_all('/<span class="ttitle3".*?>(.*?)<\/span>/',$contents,$miestas);
preg_match_all('/<span class="ttitle1".*?>(.*?)<\/span>/',$contents,$metai_kaina);
foreach($metai_kaina[0] as $key=>$metai_kaina_val){
if($key%2==0)
$metai[] = strip_tags($metai_kaina_val);
else
$kaina[] = strip_tags($metai_kaina_val);
}
preg_match_all('/<img .*?(?=src)src=\"([^\"]+)\"/si', $contents, $img_link);
for($i=0; $i<count($pavadinimas[0]); $i++){
echo '<tr>
<td style="border: 1px solid black;"><img src="'.$img_link[1][$i+2].'"></td>
<td style="border: 1px solid black;">'.$pavadinimas[0][$i].'</td>
<td style="border: 1px solid black;">'.$miestas[0][$i].'</td>
<td style="border: 1px solid black;">'.$metai[$i].'</td>
<td style="border: 1px solid black;">'.$kaina[$i].'</td>
</tr>';
}
?>
</table>
The $matches parameter of the function will always be an array - you need to process the variable before adding them to the output string.
http://php.net/manual/en/function.preg-match-all.php
As far as I'm aware you can't print_r a mixture of string and array.
If all matchings return the same number of results, which seems to be implied by your $output structure, iterate over one of them:
$output = '';
foreach ($pavadinimas[1] as $index => $match) {
$output .= '<tr><td><img src=' . $img_link[1][$index] . '></td><td>' . $match . '</td><td>' . $miestas[1][$index] . '</td><td>' . $metai[1][$index] . '</td><td>' . $kaina[1][$index] . '</td></tr>';
}
preg_match_all makes deep complex search. Maximum it'll be two dimentional array. Read docs
how to correctly get all info?
For this to find out you just dump out all the result info:
print_r($pavadinimas);
print_r($miestas);
...
but i need that all info put in table
Be little more inventive; if $pavadinimas is 2d array:
echo '<table>';
foreach($p in $pavadinimas){
echo '<tr>';
foreach($item in $p){
echo '<td>' , $item , '</td>' ;
}
echo '</tr>';
}
echo '</table>';
Note
To invert the 2d array order you just use flag (PREG_PATTERN_ORDER or PREG_SET_ORDER) in the preg_match_all (see flag section in docs). Thus you will have your table with other order.

Displaying result of same column but having different values in php

I have the following php code which queries a table of my database according to place.
The table structure is as follows :
s/n | inventory no | asset no | place
=====+==============+============+=============
1 | 125A | 5245 | London
2 | 1254B | 7545 | London
3 | 128A | 5645 | New York
4 | 254B | 1545 | Tokyo
5 | 6545 | 1456 | Tokyo
And the code:
$location=$_POST['loc'];
foreach ($location as $chk1)
{
echo "<br>";
$sql="SELECT * FROM desktop WHERE Place='$chk1';";
$result=mysql_query($sql);
if($result==null)
{
echo '<script> alert("No entry for location '.$chk1.' anditem '.'desktopreturned");</script>';
continue;
}
$row = mysql_fetch_array($result);
if($row==null)
{
echo '<script>alert("No entry for location '.$chk1.' and item '.'desktop returned");</script>';
continue;
}
mysql_data_seek($result, 0);
?><table border='1' id="desktop" caption=<?php $location ?> >
<tr>
<th>S/N</th>
<th>Inventory No</th>
<th>Asset No</th>
<th>Place</th>
</tr>
<?php
while($row = mysql_fetch_array($result)) {?>
<tr class="alt">
<?php
echo "<td>" . $row['S/N'] . "</td>";
echo "<td>" . $row['Inventory no'] . "</td>";
echo "<td>" . $row['Asset No'] . "</td>";
echo "<td>" . $row['Place'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
Edit :
CSS code :
#desktop {
font-family: "Trebuchet MS", Arial, Helvetica, sans-serif;
width: 100%;
border-collapse: collapse;
}
#desktop th {
font-size: 1.1em;
text-align: left;
padding-top: 5px;
padding-bottom: 4px;
background-color: #FFCC33;
color: #ffffff;
}
#desktop td, #desktop th {
font-size: 1em;
border: 1px solid #FFCC33;
padding: 3px 7px 2px 7px;
}
#desktop tr.alt td {
color: #000000;
background-color: #FFFFCC;
}
Here, $location is storing the locations selected in the html form.
I want the returned result of the query for different places to be displayed as a single table. Currently it is displaying different place's result as different tables having their own table headers. I want the returned query to be appended into one variable.
Just place your table before the foreach loop.As it is inside the loop it repeats each time the loop continues
<table border='1' id="desktop" caption=<?php $location ?> >
<tr>
<th>S/N</th>
<th>Inventory No</th>
<th>Asset No</th>
<th>Place</th>
</tr>
foreach ($location as $chk1)
{
echo "<br>";
$sql="SELECT * FROM desktop WHERE Place='$chk1';";
$result=mysql_query($sql);
...
...
}
}
echo "</table>";
try with this code, I have changed location array default to london,
you have changed case for field name first letter should not be capital. Hope this help :)
$location=array('London','Tokyo');
$str.='<table border="1" id="desktop">
<tr>
<th>S/N</th>
<th>Inventory No</th>
<th>Asset No</th>
<th>Place</th>
</tr>';
foreach ($location as $chk1)
{
echo "<br>";
$sql="SELECT * FROM desktop WHERE Place='$chk1';";
$result=mysql_query($sql);
if($result==null)
{
echo '<script> alert("No entry for location '.$chk1.' anditem '.'desktopreturned");</script>';
continue;
}
$row = mysql_fetch_array($result);
if($row==null)
{
echo '<script>alert("No entry for location '.$chk1.' and item '.'desktop returned");</script>';
continue;
}
mysql_data_seek($result, 0);
while($row = mysql_fetch_array($result)) {
$str.='<tr class="alt">
<td>' . $row['sr'] . '</td>
<td>' . $row['inventory_no'] . '</td>
<td>'. $row['asset_no'] . '</td>
<td>' . $row['place'] . '</td>
</tr>';
}
}
$str.='</table>';
echo $str;
?>

Failed to load pdf, dompdf error -> PDF.js v0.8.787 (build: 58407cf) Message: InvalidPDFException

Following is my code to display a pdf using dompdf but the error was failed to load pdf
PDF.js v0.8.787 (build: 58407cf)
Message: InvalidPDFException
table name is acad_act and database name is pbas_db. Details of database connection is stored in db_connect.php. Any help would be appreciable
<?php
include('db_connect.php');
require 'dompdf/dompdf_config.inc.php';
$sqlinv="SELECT * FROM acad_act";
$res_inv = mysql_query($sqlinv) or die(mysql_error());
while ($sql3=mysql_fetch_array($res_inv)) {
$inv_id = $sql3['User_id'];
$date = $sql3['Year'];
$cname = $sql3['Gen_Info_AQ'];
$subtotal = $sql3['Gen_Info_NOC'];
$disc = $sql3['Gen_Info_Place'];
$subtotal2 = $sql3['Gen_Info_Duration'];
$tax = $sql3['Gen_Info_SA'];
$gtotal = $sql3['Gen_Info_Aqyear'];
}
$dompdf= new DOMPDF();
$html .="<html>
<head>
<style>
body {
font-family: arial;
font-size: 13px;
}
table {
width: 100%;
border-collapse: collapse;
}
th {
font-weight: bold;
font-size: 14px;
border: 1px solid #333333;
}
tr {
width: 100%;
}
td {
border: 1px solid #333333;
text-align: center;
padding: 10px;
font-weight: normal!important;
}
</style>
</head><body>";
$html .="
<table>
<thead>
<tr>
<th class=''>Sr.</th>
<th class=''>Particulars</th>
<th class=''>Size</th>
<th class=''>Quantity / Insertion</th>
<th class=''>Rate</th>
<th class=''>Amount</th>
<th class=''>Amount 2</th>
<th class=''>Amount 3</th>
</tr>
</thead>
<tbody>
<tr>
<td>" . $inv_id . "</td>
<td>" . $date . "</td>
<td>" . $cname . "</td>
<td>" . $subtotal . "</td>
<td>" . $disc . "</td>
<td>" . $subtotal2 . "</td>
<td>" . $tax . "</td>
<td>" . $gtotal . "</td>
</tr>
</tbody>
</table>
</body>
</html>";
$dompdf->load_html($html);
$dompdf->render();
$dompdf->stream("sample.pdf");
exit(0);
?>
The exception is due to pdf.js plugin installed in the browser. Instead of rendering the error the pdfjs shows an exception which doesn't display the error. Just remove the pdfjs plugin than you will be able to see the required error.

Categories