While m exporting data to excel grid lines are not coming - php

$html='<table style="border: 0.1pt solid #ccc">
<tr><td>क्षेत्र </td>
<td>विभाग</td>
<td>नाम </td>
<td>पद </td>
<td>मोबाइल नम्बर </td>
<td>कोई अन्य नम्बर</td>
<td>ई-मेल </td>
<td>पता</td>
</tr>' ;
while( $row = mysqli_fetch_array($result) ) {
$html.='<tr>
<td>'.$row['jila'].' '.$row['vibhag'].' '.$row['name'].'</td>
<td>'.$row['post'].'</td>
<td>'.$row['mobile1'].'</td>
<td>'.$row['mobile2'].'</td>
<td>'.$row['email'].'</td>
<td>'.$row['address'].'</td>
</tr>' ;
}
$html.= '</table>';
header('Content-Type:application/vnd.ms-excel');
header('Content-Disposition:attachment;filename=report.xls');
print chr(255) . chr(254) . mb_convert_encoding($html, 'UTF-16LE', 'UTF-8');
Adding table border was mentioned somewhere in a similar post so tried that but still the problem persist. Is there any problem with code due to which this is happening.

Related

$_SESSION problem - I have same ID on all <tr>

I don’t know, how I do this: I want to add $id from database to $_SESSION["dbID"] and after click, it shows me more information from database. But table generates in while function and $_SESSION["dbID"] every time set to the highest number of row from table. Please, Can you anyone change my code as I have $_SESSION["dbID"] on every <tr> of table different? Thank you
while($row = $result->fetch_assoc())
{
$id=$row['ID'];
$name=$row['Name'];
$subject=$row['Subject'];
$date=$row['Date'];
echo
'<tr class="trX" id="'.$id.'" href="google.com&id='.$row['ID'].'">
<td class="tdX"><a style="color:black; text-decoration: none;" href="page.php">' . $id . '</a></td>
<td class="tdX"><a style="color:black; text-decoration: none;" href="page.php">' . $name . '</td>
<td class="tdX"><a style="color:black; text-decoration: none;" href="page.php">' . $subject . '</td>
<td class="tdX"><a style="color:black; text-decoration: none;" href="page.php">' . $date . '</td>
</tr>';
}
$_SESSION["dbID"] = $id;
echo ' </table> ';
Explanation
You can do away with all of the a tags and use JavaScript to handle the redirect...
$url = "/path/to/file.php?id=" . $id;
Set the URL to the page that you want to link to. The line above shows the link to the file "file.php" on the server with the query string "id=$id".
onclick="window.location.href='...'"
The line above is a JS equivalent of href. If you want to navigate to a server outside of your domain remember to add the full url e.g. https://www.website.com
Code example
while ($row = $result->fetch_assoc()) {
$id = $row['ID'];
$name = $row['Name'];
$subject = $row['Subject'];
$date = $row['Date'];
$url = "/url/path.php?id=" . $id;
echo <<<EOT
<tr class="trX" onclick="window.location.href='{$url}'">
<td class="tdX">{$id}</td>
<td class="tdX">{$name}</td>
<td class="tdX">{$subject}</td>
<td class="tdX">{$date}</td>
</tr>
EOT;
}
echo ' </table> ';
if (mysqli_num_rows($sql) > 0) {
$row = mysqli_fetch_assoc($sql);
}
while($row = $result->fetch_assoc()){ ?>
<tr class="trX" id="'.<?php echo $row['ID']; ?>.'" href="google.com&id='.$row['ID'].'">
<td class="tdX"><a style="color:black; text-decoration: none;" href="page.php"><?php echo $row['ID']; ?></a></td>
<td class="tdX"><a style="color:black; text-decoration: none;" href="page.php"><?php echo $row['Name']; ?></td>
<td class="tdX"><a style="color:black; text-decoration: none;" href="page.php"><?php echo $row['Subject']; ?></td>
<td class="tdX"><a style="color:black; text-decoration: none;" href="page.php"><?php echo $row['Date']; ?> </td>
</tr>
<?php } ?>
Dont define the rows just make a call for them in the databse.

For loop is emailing one character per row in table

I have been stuck on this problem for a while. My requirements are to email data from mySQL to a client. I took code from another page in my company's codebase that works when it is emailed.
The problem that I am encountering is that it is emailing only one character per row.
Here is my code:
$message = "
<br /><hr /><br /><table style='font-size: 12px; width:100%'>
<tr>
<td td width='25%'><strong>Oligo Name</strong></td>
<td width='10%'><strong>Base</strong></td>
<td width='10%'><strong>Scale</strong></td>
<td width='10%'><strong>Mod</strong></td>
<td width='10%'><strong>Mod Position</strong></td>
<td style='word-break: break-all; width: 500px;'><strong>Oligo Sequence</strong></td>
<td width='15%' style='text-align: right'><strong>Price</strong></td>
</tr>";
$SampleID = 0;
$maxrow = $OligoQty;
for ($i; $i < $maxrow; $i++) {
if(trim($SampleName) == '' && trim($Sequence) == '')
continue;
// $SampleID++;
$bases = preg_replace('/\s+/', '', $Sequence);
$seq_length = strlen($bases);
$message .= "
<tr>
<td width='200'>{$SampleIDS} . {$SampleName[$i]}</td>
<td width='40'>{$sequence_length[$i]}</td>
<td width='40'>{$SampleScale[$i]}</td>
<td width='40'>{$modification[$i]}</td>
<td width='40'>{$mod_position[$i]}</td>
<td style='word-break: break-all; width: 500px;'>{$Sequence[$i]}</td>
</tr>";
</tr>";
}
When I remove the for loop, it prints out the row perfectly:
I believe there is something wrong with my for loop that is causing it to do that and I am not sure why. I hard coded $maxrow to 2 and that is why I am getting 2 rows for the email. Any help would be appreciated!

Foreach and skip specific HTML

I am using a foreach to elaborate some values scraped from a web site. It works but I have the follow problem (I put screens to explain my problem in the best way).
In the first screen, you can see that Derry City - Limerick doesn't have 1 X 2 odds
But when I get that values, my code fill empty odds with the first odds available, see the screen below:
This is the HTML code:
<table class="table-main js-tablebanner-t js-tablebanner-ntb">
<tr><th class="h-text-left" colspan="2">2. Round</th><th> </th><th class="table-main__bs">B's</th><th class="h-text-center">1</th><th class="h-text-center">X</th><th class="h-text-center">2</th></tr>
<tr>
<td class="table-main__datetime">21.03.2017 20:45</td>
<td class="h-text-left"><span>Derry City</span> - <span>Limerick</span></td>
<td class="h-text-right">
<ul class="list-tags"><li class="list-tags__item"><i class="icon icon__stream"></i><div class="list-tags__window list-tags__window--streams"><ul class="list-tags__window__in">
<li>Live streams</li>
<li>bwin</li>
<li>Sportingbet</li>
</ul></div></li></ul>
</td>
<td class="table-main__bs"> </td>
<td class="table-matches__odds" data-oid=""> </td>
<td class="table-matches__odds" data-oid=""> </td>
<td class="table-matches__odds" data-oid=""> </td>
</tr>
<tr><th class="h-text-left" colspan="2">5. Round</th><th> </th><th class="table-main__bs">B's</th><th class="h-text-center">1</th><th class="h-text-center">X</th><th class="h-text-center">2</th></tr>
<tr>
<td class="table-main__datetime">18.03.2017 15:00</td>
<td class="h-text-left"><span>Limerick</span> - <span>Finn Harps</span></td>
<td class="table-matches__odds" data-oid="2kou5xv464x0x5uaff"></td>
<td class="table-matches__odds" data-oid="2kou5xv498x0x0"></td>
<td class="table-matches__odds" data-oid="2kou5xv464x0x5uafg"></td>
</tr>
<tr>
<td class="table-main__datetime">18.03.2017 16:00</td>
<td class="h-text-left"><span>Derry City</span> - <span>Drogheda</span></td>
<td class="table-main__bs">23</td>
<td class="table-matches__odds" data-oid="2kp2nxv464x0x5uaoj"></td>
<td class="table-matches__odds" data-oid="2kp2nxv498x0x0"></td>
<td class="table-matches__odds" data-oid="2kp2nxv464x0x5uaok"></td>
</tr>
and, at least, this is my code:
$match_dates = $html->find("td[class=table-main__datetime]");
$titles = $html->find("a[class=in-match]"); // 1 per match
$odds = $html->find("td[class=table-matches__odds]/a"); // 2
function print_odd($odd) {
if (array_key_exists('data-odd', $odd->attr)) {
return $odd->attr['data-odd'];
}
return $odd->children(0)->children(0)->children(0)->attr['data-odd'];
}
$c=0; $b=0; $o=0; $z=0; // two counters
foreach ($titles as $match) {
list($num1, $num2) = explode(':', $res->innertext); // <- explode
list($home, $away) = explode('-', $titles[$z++]->innertext); // <- explode
list($date, $time) = explode('-', $match_dates[$o++]->innertext); // <- explode
$odd1 = print_odd($odds[$b++]);
$odd2 = print_odd($odds[$b++]);
$odd3 = print_odd($odds[$b++]);
$home = strip_tags($home);
$away = strip_tags($away);
$uniquefield = $home . ' ' . $away;
echo "<tr><td class='rtitle'>".
//"<td class='last-cell'>".$match_dates[$o++]->innertext. "</td> " .
"<td> ".$date.'</td><td> : </td><td>'.$time . " / " .
"<td> ".$home.'</td><td> : </td><td>'.$away . " / " .
"<td class='odds'>".$odd1 . ";" .
"".$odd2 . ";" .
"".$odd3 . "</td>" .
"".$uniquefield."</td></tr><br/>";

Printing Horizontal Tables Including Images Using PHP MySQL

I am trying to print out on my sites home page a horizontal table which includes a picture of a car and then below the make, model & price of the car.
Here's roughly what I have done:
<?php
$List = "";
$sql = mysql_query("SELECT * FROM Car ORDER BY listed DESC LIMIT 5");
$Count = mysql_num_rows($sql);
if ($Count > 0) {
while($row = mysql_fetch_array($sql)){
$id = $row["id"];
$make = $row["make"];
$model = $row["model"];
$price = $row["price"];
$List .= '<table width="100%" border="0" cellspacing="0" cellpadding="6">
<tr>
<td width="20%" valign="top"><a href="/motors/cars.php?id=' . $id . '"><img style="border:#666 1px solid;"
src="/../../motors-' . $id . '.jpg" alt="' . $status . ' ' . $title . '" width="100" height="80" border="1" /></a></td>
</tr>
<tr>
<td width="80%" valign="top" align="left"><font face="Arial" color="#000080"><B>
' . $make . ' ' . $model . '</B></font><br />' . $price . '
view car details</align></td>
</tr>
</table>';
}
} else {
$List = "No cars at present";
}
mysql_close();
?>
Can anyone help me sort this code to print out horizontally? Many Thanks!
The src of the image is most likely wrong, /../../motors... is still /motors...
you can move the images into your webapps /motors/images folder and set src as /motors/images/motors...
The table you create must be nested in another table.
<table>
<tr>
<td>
<table of a car>
</td>
<td>
<table of a car>
</td>
<td>
<table of a car>
</td>
.... etc.
</tr>
</table>
It will make sense to emit a tr every few cars to wrap to a new line.
table of a car is the html you collect in $List.

Changing column in HTML table to hyperlink

for ($i=0; $i<=$lines; $i++)
{
//get each line and exlplode it..
$part = explode('|', $file[$i]);
//now start printing ..
echo'<tr>
<td width="20%">'.$part[0].'</td>
<td width="20%">'.$part[1].'</td>
<td width="20%">'.$part[2].'</td>
<td width="20%">'.$part[3].'</td>
<td width="20%">'.$part[4].'</td>
</tr>';
}
This is my code, it read's from a text file and explode in table, but I have a little problem here cause this one needs to be link.
<td width="20%">'.$part[2].'</td>
.$part[2]. is just a word from file but it has query like www.somesite.com/?q= There at the end I need to have that
word from file
that kind of code did not work for me
<td width="20%"> <a herf='www.somesite.com/?q=''.$part[2].'> '.$part[2].' </a> </td>
I realy need some help with this...
<?php
//first, get the file...
$file = file('req.txt');
//now count the lines ..
$lines = count($file);
//start the table here..
echo'<table border="2" width="100%">';
echo'<tr>
<td width="20%">Naslov</td>
<td width="20%">Vrsta</td>
<td width="20%">IP</td>
<td width="20%">Dodano (DD.MM.YY - HH.MM)</td>
<td width="20%">Status</td>
</tr>';
//start the loop to get all lines in the table..
for ($i=0; $i<=$lines; $i++) {
//get each line and exlplode it..
$part = explode('|', $file[$i]);
//now start printing ..
echo'<tr>
<td width="20%">'.$part[0].'</td>
<td width="20%">'.$part[1].'</td>
<td width="20%">'.$part[2].'</td>
<td width="20%">'.$part[3].'</td>
<td width="20%">'.$part[4].'</td>
</tr>';
}
//close the table so HTML wont suffer :P
echo'</table>';
?>
This should produce this but ip column need to be link...
I think vprintf() is your friend.
<?php
$fmt = '<tr>
<td>%1$s</td>
<td>%2$s</td>
<td>%3$s</td>
<td>%4$s</td>
<td>%5%s</td>
</tr>';
for ($i=0; $i<=$lines; $i++)
{
// get each line and explode it..
$part = explode('|', $file[$i]);
// now start printing ..
vprintf($fmt, $part);
}
And put the width="20%" into your CSS.
I solve it alone with changing some values in input script "file writer"
$savestring = $title . "|" . $genre . "|<a href=http://www.example.com/ip?ip=" . $ip . ">" . $ip . "|" . $date . "|Za Naložit \n";
it works now ty anyway :)

Categories