I'm using this code for creating a table based on a CSV file and it works fine;
<?php
$lines = file('graphdata/GapsVsOthersForDimsOthersJson.csv');
foreach ($lines as $lineNum => $line) {
$cellType = ($lineNum == 0 ? "th" : "td");
$tokens = str_getcsv($line);
if ($lineNum == 0) echo "<thead>";
if ($lineNum == 1) echo "<tbody>";
echo "<tr id=\"tr" . $lineNum . "\">";
echo "<" . $cellType . " style=\"width: 300px;\">" . trim($tokens[0]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[1]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[2]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[3]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[4]) . "</" . $cellType . ">";
echo "</tr>";
if ($lineNum == 0) echo "</thead>";
}
if (count($lines) > 1) echo "</tbody>";
?>
I'm interested in inserting a button icon next the the last column header using:
<button id="popupWindowDimensions" type="button" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-info-sign"></span>
</button>
Any idea?
You can use the below format but this will create a empty last column
So Please can you clearly give how you need
<?php
$lines = file('graphdata/GapsVsOthersForDimsOthersJson.csv');
foreach ($lines as $lineNum => $line) {
$cellType = ($lineNum == 0 ? "th" : "td");
$tokens = str_getcsv($line);
if ($lineNum == 0) echo "<thead>";
if ($lineNum == 1) echo "<tbody>";
echo "<tr id=\"tr" . $lineNum . "\">";
echo "<" . $cellType . " style=\"width: 300px;\">" . trim($tokens[0]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[1]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[2]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[3]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[4]) . "</" . $cellType . ">";
if ($lineNum == 0)
{
echo "<" . $cellType . ' style=\"width: 100px;\">';
echo '<button id="popupWindowDimensions" type="button" class="btn btn-default btn-sm">
<span class="glyphicon glyphicon-info-sign"></span>
</button>';
echo '</' . $cellType . '>';
}
echo "</tr>";
if ($lineNum == 0) echo "</thead>";
}
if (count($lines) > 1) echo "</tbody>";
?>
Related
I select a excel file. then press read button.
It need to show all string type data is strong and color red. but is is not working. it's only check first error and execute. Doesn't check another error or not.
code:
<?php
echo '<h2>Parsing Excel Data</h2>';
echo '<table class="table table-hover">';
$i = 0;
foreach ($xlsx->rows() as $elt) {
if ($i == 0) {
echo "<tr><th scope='col'>" . $elt[0] . "</th><th scope='col'>" . $elt[1] . "</th><th scope='col'>" . $elt[2] . "</th><th scope='col'>" . $elt[3] . "</th><th scope='col'>" . $elt[4] . "</th><th scope='col'>" . 'Remark' . "</th></tr>";
}
else
{
echo "<tbody>";
if(gettype($elt[0]) == 'integer' && gettype($elt[1]) == 'integer' && gettype($elt[2]) == 'integer' && gettype($elt[3]) == 'integer' && gettype($elt[4]) == 'integer'){
echo "<tr><td>" . $elt[0] . "</td><td>" . $elt[1] . "</td><td>" . $elt[2] . "</td><td>" . $elt[3] . "</td><td>" . $elt[4] . "</td><td>" . '<button type="button" class="btn btn-primary">Candidate List</button><button type="button" class="btn btn-light">Candidate List(Examiner)</button>' . "</td></tr>";
}
else{
if(gettype($elt[0]) == 'string'){
echo "<tr class='danger'><td style='color: red;'>" . '<h4><del>'.$elt[0].'</del></h4>' . "</td><td>" . $elt[1] . "</td><td>" . $elt[2] . "</td><td>" . $elt[3] . "</td><td>" . $elt[4] . "</td><td>" . '<h6 class="text-center">Please Input the Correct Data.</h5>' . "</td></tr>";
}
else if(gettype($elt[1]) == 'string'){
echo "<tr class='danger'><td>" . $elt[0] . "</td><td style='color: red;'>" . '<h4><del>'.$elt[1].'</del></h4>' . "</td><td>" . $elt[2] . "</td><td>" . $elt[3] . "</td><td>" . $elt[4] . "</td><td>" . '<h6 class="text-center">Please Input the Correct Data.</h5>' . "</td></tr>";
}
else if(gettype($elt[2]) == 'string'){
echo "<tr class='danger'><td>" . $elt[0] . "</td><td>" . $elt[1] . "</td><td style='color: red;'>" . '<h4><del>'.$elt[2].'</del></h4>' . "</td><td>" . $elt[3] . "</td><td>" . $elt[4] . "</td><td>" . '<h6 class="text-center">Please Input the Correct Data.</h5>' . "</td></tr>";
}
else if(gettype($elt[3]) == 'string'){
echo "<tr class='danger'><td>" . $elt[0] . "</td><td>" . $elt[1] . "</td><td>" . $elt[2] . "</td><td style='color: red;'>" . '<h4><del>'.$elt[3].'</del></h4>' . "</td><td>" . $elt[4] . "</td><td>" . '<h6 class="text-center">Please Input the Correct Data.</h5>' . "</td></tr>";
}
else if(gettype($elt[4]) == 'string'){
echo "<tr class='danger'><td>" . $elt[0] . "</td><td>" . $elt[1] . "</td><td>" . $elt[2] . "</td><td>".$elt[3]."</td><td style='color: red;'>" . '<h4><del>'.$elt[4].'</del></h4>' . "</td><td>" . '<h6 class="text-center">Please Input the Correct Data.</h5>' . "</td></tr>";
}
}
}
$i++;
}
echo "</tbody></table>";
?>
Thank you.
I Solved it......
'''echo 'Parsing Excel Data';
echo '';
$i = 0;
foreach ($xlsx->rows() as $elt) {
if ($i == 0) {
echo "<tr><th scope='col'>" . $elt[0] . "</th><th scope='col'>" . $elt[1] . "</th><th scope='col'>" . $elt[2] . "</th><th scope='col'>" . $elt[3] . "</th><th scope='col'>" . $elt[4] . "</th><th scope='col'>" . 'Remark' . "</th></tr>";
}
else
{
echo "<tbody>";
if(gettype($elt[0]) == 'integer' && gettype($elt[1]) == 'integer' && gettype($elt[2]) == 'integer' && gettype($elt[3]) == 'integer' && gettype($elt[4]) == 'integer'){
echo "<tr><td>" . $elt[0] . "</td><td>" . $elt[1] . "</td><td>" . $elt[2] . "</td><td>" . $elt[3] . "</td><td>" . $elt[4] . "</td><td>" . '<button type="button" class="btn btn-primary">Candidate List</button><button type="button" class="btn btn-light">Candidate List(Examiner)</button>' . "</td></tr>";
}
else{
if(gettype($elt[0]) == 'string'){
$a= "<tr class='danger'><td style='color: red;'>" . '<h4><del>'.$elt[0].'</del></h4>' . "</td>";
}
else{
$a= "<tr class='danger'><td>" . $elt[0] . "</td>";
}
if(gettype($elt[1]) == 'string'){
$b= "<td style='color: red;'>" . '<h4><del>'.$elt[1].'</del></h4>' . "</td>";
}
else{
$b= "<td>" . $elt[1] . "</td>";
}
if(gettype($elt[2]) == 'string'){
$c= "<td style='color: red;'>" . '<h4><del>'.$elt[2].'</del></h4>' . "</td>";
}
else{
$c= "<td>" . $elt[2] . "</td>";
}
if(gettype($elt[3]) == 'string'){
$d= "<td style='color: red;'>" . '<h4><del>'.$elt[3].'</del></h4>' . "</td>";
}
else{
$d= "<td>" . $elt[3] . "</td>";
}
if(gettype($elt[4]) == 'string'){
$e= "<td style='color: red;'>" . '<h4><del>'.$elt[4].'</del></h4>' . "</td><td>" . '<h6 class="text-center">Please Input the Correct Data.</h5>' . "</td></tr>";
}
else{
$e= "<td>" . $elt[4] . "</td><td>" . '<h6 class="text-center">Please Input the Correct Data.</h5>' . "</td></tr>";
}
echo $a.$b.$c.$d.$e;
}
}
$i++;
}
echo "";'''
The following code works fine and it gives the required output:
<a target="_blank" href="' . $property_post_link . '" style="color:#f8953a;font-size:18px;margin-left:0px;text-decoration:none"><b>' . $property_name . '</b></a>
<div style="color:#f8953a;font-style:italic">
<!--- <span style="font-weight:bold;">Transaction Type: </span>' . $transaction_type . ' --->
<!--- <span style="font-weight:bold;padding-left:5px;">Category: </span>' . $newprop_category . ' --->
</div>
<div style="color:#f8953a;font-style:italic">
<span style="font-weight:bold">Property Type: </span>' . $proper_type . '
<span style="font-weight:bold;padding-right:5px;">BHK: </span>' . $bhk . '
<span style="font-weight:bold;padding-left:5px;">Status: </span>' . $status . '
</div>
<div style="color:#f8953a;font-style:italic">
<span style="font-weight:bold">Location: </span>' . $loc . '
<span style="font-weight:bold;padding-right:5px;">Building Name: </span>' . $buildingname . '
<span style="font-weight:bold;padding-left:5px;">No. of Floor: </span>' . $no_floor . '
</div>
<div style="color:#f8953a;font-style:italic">
<span style="font-weight:bold">Carpet Area: </span>' . $carpet_area . '
<span style="font-weight:bold;padding-right:5px;">Built up Area: </span>' . $buildup_area . '
<span style="font-weight:bold;padding-left:5px;">Price: </span>' . $price_options_select . '
</div>
<div style="color:#f8953a;font-style:italic">
<span style="font-weight:bold">Contact Person: </span>' . $contactperson . '
</div>
But I need to get this in a table. I am using the following code:
echo "<table border='1'>
<tr><th>Building</th><th>Location</th><th>BHKs</th><th>Built up Area</th><th>Furnishing</th><th>Quote</th><th>Advance Rent</th><th>Deposit</th><th>Parking</th></tr>";
foreach ($the_rows as $the_row) {
echo "<tr><td>" . $the_row->buildingname . "</td>";
echo "<td>" . $the_row->loc . "</td>";
echo "<td>" . $the_row->bhk . "</td>";
echo "<td>" . $the_row->buildup_area . "</td>";
echo "<td>" . $the_row->interior_options_select . "</td>";
echo "<td>" . $the_row->price . "</td>";
echo "<td>" . $the_row->advrent . "</td>";
echo "<td>" . $the_row->deposit . "</td>";
echo "<td>" . $the_row->car_parking . "</td></tr>";
}
echo "</table>";
But this is not fetching the results from the database. Any help is appreciated.
If you are using simple mysql_query() and mysql_fetch_array() then use code below.
echo "<table border='1'>
<tr><th>Building</th><th>Location</th><th>BHKs</th><th>Built up Area</th><th>Furnishing</th><th>Quote</th><th>Advance Rent</th><th>Deposit</th> <th>Parking</th></tr>";
foreach ($the_rows as $the_row) {
echo "<tr><td>" . $the_row['buildingname'] . "</td>";
echo "<td>" . $the_row['loc'] . "</td>";
echo "<td>" . $the_row['bhk'] . "</td>";
echo "<td>" . $the_row['buildup_area'] . "</td>";
echo "<td>" . $the_row['interior_options_select'] . "</td>";
echo "<td>" . $the_row['price']. "</td>";
echo "<td>" . $the_row['advrent'] . "</td>";
echo "<td>" . $the_row['deposit'] . "</td>";
echo "<td>" . $the_row['car_parking'] . "</td></tr>";
}
echo "</table>";
if not than please deiscribe you database code too,
This code reads a CSV file for creating a table. It works fine.
How do I make the 1st row to be formatted in header style (from the table CSS)?
<table id="myTable" class="tablesorter animated fadeInDown"> <!-- cellspacing='0' is important, must stay -->
<tbody>
<?php
$lines = file('graphdata/IndicForTableVsOthers.csv');
foreach ($lines as $lineNum => $line) {
if($lineNum == 0) {
print " <tr id=\"tr" . $lineNum . "\">";
}
print " <tr id=\"tr" . $lineNum . "\">";
$tokens = str_getcsv($line);
print "<td style=\"width: 300px;\">" . trim($tokens[0]) . "</td>";
print "<td style=\"width: 100px;\">" . trim($tokens[1]) . "</td>";
print "<td style=\"width: 100px;\">" . trim($tokens[2]) . "</td>";
print "<td style=\"width: 100px;\">" . trim($tokens[3]) . "</td>";
print "<td style=\"width: 100px;\">" . trim($tokens[4]) . "</td>";
print "</script>\n";
}
?>
</tbody>
This should work, I also changed some other parts who I think would have generated wrong marup.
<table id="myTable" class="tablesorter animated fadeInDown">
<?php
$lines = file('graphdata/IndicForTableVsOthers.csv');
foreach ($lines as $lineNum => $line) {
$cellType = ($lineNum == 0 ? "th" : "td");
$tokens = str_getcsv($line);
if ($lineNum == 0) echo "<thead>";
if ($lineNum == 1) echo "<tbody>";
echo "<tr id=\"tr" . $lineNum . "\">";
echo "<" . $cellType . " style=\"width: 300px;\">" . trim($tokens[0]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[1]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[2]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[3]) . "</" . $cellType . ">";
echo "<" . $cellType . " style=\"width: 100px;\">" . trim($tokens[4]) . "</" . $cellType . ">";
echo "</tr>";
if ($lineNum == 0) echo "</thead>";
}
if (count($lines) > 1) echo "</tbody>";
?>
</table>
If the first row is printed but it looks light and you want it Bold and Pretty so the user knows it's the header, add a class for convenience.
table.cs-contents tr:first-child td {
font-weight: bold;
text-align: center;
border-bottom: 2px solid #eaeaea;
}
I'm trying to do a condition within an if statement.
I have a current if statement which determines odd and even for css styling.
Within this I want to add another if statement for the reference number. (outlined as Ref in the code).
I'm not sure how to go about this but I want to add something along the lines of
if ref == 1 then echo ref, I've tried putting an if within an if and I just keep getting syntax errors. Can someone point me in the right direction please?
include "db_connect.php";
$result1 = mysql_query("SELECT * FROM updates ORDER BY id DESC limit 5");
$result2 = mysql_num_rows($result1);
$x = $result2;
while ($row1 = mysql_fetch_array($result1)) {
if (++$x % 2) {
echo "<blockquote class='example-right'>" . $row1['update'] .
"<div class='ref'>Ref: " . $row1['ref'] .
"</div><div class='date-right'> from " . $row1['date'] .
" to " . $row1['todate'] .
"</div> </blockquote> <p>" . $row1['username'] .
"</p> </td>";
echo "</p>";
} else {
echo "<blockquote class='example-obtuse'>" . $row1['update'] .
"<div class='ref'>Ref: " . $row1['ref'] .
"</div><div class='date-right'> from " . $row1['date'] .
" to " . $row1['todate'] .
"</div> </blockquote> <p>" . $row1['username'] .
"</p> </td>";
}
}
the bit I tried to do with 2nd if statement:
include "db_connect.php";
$result1 = mysql_query("SELECT * FROM updates1 ORDER BY id DESC limit 5");
$result2 = mysql_num_rows($result1);
$x = $result2;
while ($row1 = mysql_fetch_array($result1)) {
if (++$x % 2) {
$sch = $row1['schuedled'];
else if ($sch == '1') {
echo "<blockquote class='example-right'>" . $row1['update'] .
"<div class='ref'>Ref: " .$row1['ref'] .
"</div><div class='date-right'> from " . $row1['date'] .
" to " . $row1['todate'] .
"</div> </blockquote> <p>" . $row1['username'] .
"</p> </td>";
else {
echo "<blockquote class='example-right'>" . $row1['update'] .
"</div><div class='date-right'> from " . $row1['date'] .
" to " . $row1['todate'] .
"</div> </blockquote> <p>" . $row1['username'] .
"</p> </td>";
}
}
echo "</p>";
} else {
echo "<blockquote class='example-obtuse'>" . $row1['update'] .
"<div class='assyst-ref'>Ref: " . $row1['ref'] .
"</div><div class='date-right'> from " . $row1['date'] .
" to " . $row1['todate'] .
"</div> </blockquote> <p>" . $row1['username'] .
"</p> </td>";
}
}
Try something like this:
while($row1 = mysql_fetch_array($result1)){
$html = '';
if (++$x % 2 ){
$html .= "<blockquote class='example-right'>";
} else {
$html .= "<blockquote class='example-obtuse'>";
}
$html .= $row1['update'];
if($row1['schuedled'] == '1'){
$html .= "<div class='ref'>Ref: " .$row1['ref'] . "</div>";
}
$html .= "more html";
$html .= "more html";
$html .= "more html";
$html .= "</blockquote>";
echo $html;
}
Im wondering if its possible with PHP to add a class to X record returned. I know I can do this with JS only I'd like it to have the class added as the records are returned.
I have the following loop in my PHP, From what I've found in google I need to add a counter to do this only I've been unsuccessful so far...
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
echo '<div class="entry span3"><span class="name">' . $row['First_Name'] . ' ' . $row['Surname'] . "</span>";
echo '<img src="' . $row["picture_1"] . '" alt="' . $row['First_Name'] . ' ' . $row['Surname'] . ', text ' . $row['Date'] . ' ">';
echo '<span class="from">seen in ' . ucwords($row["Location_County__Seen"]) . '</span>View Profile</div>';
}
In front of your while, add $c = 1
Before the end of your while loop, add $c++;
Then, modify your first line:
echo '<div class="entry span3"><span class="name">'
To
echo '<div class="entry span3';
if (($c % 4) == 1) echo ' newclassname ';
echo '"><span class="name">'
For the final result:
$c = 1;
while ($row = $sth->fetch(PDO::FETCH_ASSOC)) {
echo '<div class="entry';
if (($c % 4) == 1) echo ' newclassname ';
echo ' span3"><span class="name">' . $row['First_Name'] . ' ' . $row['Surname'] . "</span>";
echo '<img src="' . $row["picture_1"] . '" alt="' . $row['First_Name'] . ' ' . $row['Surname'] . ', text ' . $row['Date'] . ' ">';
echo '<span class="from">seen in ' . ucwords($row["Location_County__Seen"]) . '</span>View Profile</div>';
$c++;
}