Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I have a PHP program from OpenEMR that prints context to the console in HTML format. I wanted to save whatever it prints to another html file. I am not very familiar with PHP and front end technologies. Does anyone know a simple way to make it work? Thanks a lot.
Below is the code detail:
foreach($newpatient as $patient){
/*
$inclookupres = sqlStatement("select distinct formdir from forms where pid='".$pids[$iCounter]."'");
while($result = sqlFetchArray($inclookupres)) {
include_once("{$GLOBALS['incdir']}/forms/" . $result{"formdir"} . "/report.php");
}
*/
print "<div id='superbill_patientdata'>";
print "<h1>".xlt('Patient Data').":</h1>";
printRecDataOne($patient_data_array, getRecPatientData ($pids[$iCounter]), $N);
print "</div>";
print "<div id='superbill_insurancedata'>";
print "<h1>".xlt('Insurance Data').":</h1>";
print "<h2>".xlt('Primary').":</h2>";
printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"primary"), $N);
print "<h2>".xlt('Secondary').":</h2>";
printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"secondary"), $N);
print "<h2>".xlt('Tertiary').":</h2>";
printRecDataOne($insurance_data_array, getRecInsuranceData ($pids[$iCounter],"tertiary"), $N);
print "</div>";
print "<div id='superbill_billingdata'>";
print "<h1>".xlt('Billing Information').":</h1>";
if (count($patient) > 0) {
$billings = array();
echo "<table width='100%'>";
echo "<tr>";
echo "<td class='bold' width='10%'>".xlt('Date')."</td>";
echo "<td class='bold' width='20%'>".xlt('Provider')."</td>";
echo "<td class='bold' width='40%'>".xlt('Code')."</td>";
echo "<td class='bold' width='10%'>".xlt('Fee')."</td></tr>\n";
$total = 0.00;
$copays = 0.00;
//foreach ($patient as $be) {
$ta = split(":",$patient);
$billing = getPatientBillingEncounter($pids[$iCounter],$ta[1]);
$billings[] = $billing;
foreach ($billing as $b) {
// grab the date to reformat it in the output
$bdate = strtotime($b['date']);
echo "<tr>\n";
echo "<td class='text' style='font-size: 0.8em'>" . oeFormatShortDate(date("Y-m-d",$bdate)) . "<BR>" . date("h:i a", $bdate) . "</td>";
echo "<td class='text'>" . text($b['provider_name']) . "</td>";
echo "<td class='text'>";
echo text($b['code_type']) . ":\t" . text($b['code']) . " ". text($b['modifier']) . " " . text($b['code_text']) . " ";
echo "</td>\n";
echo "<td class='text'>";
echo oeFormatMoney($b['fee']);
echo "</td>\n";
echo "</tr>\n";
$total += $b['fee'];
}
// Calculate the copay for the encounter
$copays = getPatientCopay($pids[$iCounter],$ta[1]);
//}
echo "<tr><td> </td></tr>";
echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Sub-Total')."</td><td class='text'>" . oeFormatMoney($total + abs($copays)) . "</td></tr>";
echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Copay Paid')."</td><td class='text'>" . oeFormatMoney(abs($copays)) . "</td></tr>";
echo "<tr><td class='bold' colspan=3 style='text-align:right'>".xlt('Total')."</td><td class='text'>" . oeFormatMoney($total) . "</td></tr>";
echo "</table>";
echo "<pre>";
//print_r($billings);
echo "</pre>";
}
echo "</div>";
<?php
ob_start();
/*
YOUR CODE
*/
$page= ob_get_contents();
if ($fp = fopen('../page.htm', 'w+')) {
fwrite ($fp, $page);
fclose($fp);
}
ob_end_flush();
?>
Related
I have this block of text in an array:
"Stefan Olsson"
"Kungsvägen"
"Skolgatan"
xxxx-xx-xx
0735xxxxxx,
"Pär Davidsson"
"Skolgatan"
"Myntvägen"
xxxx-xx-xx
0709xxxxxx,
I parse this type of content to an CSV-file, for later usage in Excel. However, I want to fromat this text to fit in different columns in excell. So, when I open the CSV-file in Execel, I want the name to be in one column, the address in the column besides etcetc. How can I accomplish this? Should I use PHPExcel? Or could it be done with plain old PHP?
Here is my PHP-code
$gatunamn = $_POST['gata'];
$ort = $_POST['omrade'];
$csv_data = array();
$newSpider->fetchPage($gatunamn, $ort, $offset=0);
$obj = json_decode($newSpider->html);
echo "<div id='rightcontent'><table id='one-column-emphasis'>";
echo "<th><input type='checkbox' name='csv_all' id='csv_all'></th><th>Namn</th><th>Adress</th><th>Adress2</th><th>Adress3</th><th>Personnummer</th><th>Telefonnummer</th><th>Telefonnummer2</th>";
$antal_sidor = round($obj->search->wp->totalHits / $obj->search->wp->pageSize);
echo "<td></td>";
foreach($obj->search->wp->features as $fish) //Loopar ut 50st (pageSize)
{
echo "<tr>";
echo "<td><input type='checkbox' value='csv' class='csv'></td>";
echo "<td>" . $fish->name . "</td>";
$csv_data[] .= utf8_decode($fish->name);
foreach($fish->addresses as $ad)
{
echo "<td>" . $ad->label . " " . $ad->postcode . " " . $ad->area . "</td>";
$csv_data[] .= utf8_decode($ad->label . " " . $ad->postcode . " " . $ad->area);
}
if(!empty($fish->dateOfBirth))
{
$convert_date = substr($fish->dateOfBirth, 0, -3); //Gör om datum från timestamp
echo "<td>" . date("Y-m-d", $convert_date) . "</td>";
$convert_datee = date("Y-m-d", $convert_date);
$csv_data[] .= $convert_datee;
}
if(!empty($fish->phoneNumbers))
{
foreach($fish->phoneNumbers as $ph)
{
echo "<td>" . $ph . "</td>";
$csv_data[] .= $ph . ",";
}
}
echo "</tr>";
}
echo "</table>";
$j = 0;
for($i = 1; $i <= $antal_sidor; $i++)
{
echo "<a href='curl2.php?gatunamn=$gatunamn&ort=$ort&offset=$j'>" . $i . "</a> ";
$j += 100;
}
echo "</div>";
echo "<div id='debug'><pre>";
var_dump($csv_data);
echo "</pre></div>";
}
if(isset($_POST['export']))
{
$fp = fopen("eniroo.csv","w");
foreach(explode(",", implode("\n",$csv_data)) as $rad) {
fputcsv($fp, array(implode(',', str_getcsv($rad, "\n"))));
}
echo "<div id='csv_info'>";
echo "<a href='eniro.csv'>Hämta CSV-fil</a>";
echo "</div>";
}
// Restructure the original array into rows
$myDataArray = array_chunk($myDataArray, 5);
// Then write to CSV
$fp = fopen('file.csv', 'w');
foreach($myDataArray as $dataRow) {
fputcsv($fh, $dataRow);
}
fclose($fh)
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'm trying to create an table with PHP and HTML which gets the data from a MySQL database.
The problem is that the data is displayed horizontally and not vertical.
if (isset($_POST['winneron'])) {
echo "<tr>";
while ($printuser = mysql_fetch_array($user)) {
echo "<th>". $printuser['username'] . "</th>";
}
echo "</tr>";
while ($printgames = mysql_fetch_array($games)) {
if ( $printgames ['winner'] == $printgames ['team1'] ) {
echo "<td><b>". strtoupper($printgames ['winner']) . "</b></td>";
}
else {
echo "<td>". strtoupper($printgames ['winner']) . "</td>";
}
}
}
Hope somebody can help me.
If you want your display to be vertical then you have to put each piece of information into a table row <tr><td>...</td></tr>
while ($ausgabespiele = mysql_fetch_array($spiele)) {
if ( $ausgabespiele['sieger'] == $ausgabespiele['team1'] ) {
echo "<tr><td><b>". strtoupper($ausgabespiele['sieger']) . "</b></td></tr>";
}
else {
echo "<tr><td>". strtoupper($ausgabespiele['sieger']) . "</td></tr>";
}
}
There are no <tr> and </tr> in your while ($ausgabespiele = mysql_fetch_array($spiele)) { }...
You are missing TR in while
if (isset($_POST['winneron'])) {
echo "<tr>";
while ($ausgabeuser = mysql_fetch_array($user)) {
echo "<th>". $ausgabeuser['username'] . "</th>";
}
echo "</tr>";
while ($ausgabespiele = mysql_fetch_array($spiele)) {
echo "<tr>";
if ( $ausgabespiele['sieger'] == $ausgabespiele['team1'] ) {
echo "<td><b>". strtoupper($ausgabespiele['sieger']) . "</b></td>";
}
else {
echo "<td>". strtoupper($ausgabespiele['sieger']) . "</td>";
}
echo "</tr>";
}
}
You have to add the row-tags within the while loop...
if (isset($_POST['winneron'])) {
echo "<tr>";
while ($ausgabeuser = mysql_fetch_array($user)) {
echo "<th>". $ausgabeuser['username'] . "</th>";
}
echo "</tr>";
while ($ausgabespiele = mysql_fetch_array($spiele)) {
echo "<tr>";
if ( $ausgabespiele['sieger'] == $ausgabespiele['team1'] ) {
echo "<td><b>". strtoupper($ausgabespiele['sieger']) . "</b></td>";
}
else {
echo "<td>". strtoupper($ausgabespiele['sieger']) . "</td>";
}
echo "</tr>";
}
}
You forget to create a table row insde the loop. To display vertically you need to place the table cells in rows:
while ($ausgabespiele = mysql_fetch_array($spiele)) {
echo "<tr>";
if ( $ausgabespiele['sieger'] == $ausgabespiele['team1'] ) {
echo "<td><b>". strtoupper($ausgabespiele['sieger']) . "</b></td>";
}
else {
echo "<tr><td>". strtoupper($ausgabespiele['sieger']) . "</td></tr>";
}
echo "</tr>";
}
Try this -
if (isset($_POST['winneron'])) {
$echo = "<tr>";
while ($ausgabeuser = mysql_fetch_array($user)) {
$echo .= "<th>". $ausgabeuser['username'] . "</th>";
}
$echo .= "</tr><tr>";
while ($ausgabespiele = mysql_fetch_array($spiele)) {
if ($ausgabespiele['sieger'] == $ausgabespiele['team1'])
$echo .= "<td><b>". strtoupper($ausgabespiele['sieger']) . "</b></td>";
else
$echo .= "<td>". strtoupper($ausgabespiele['sieger']) . "</td>";
}
$echo .= "</tr>";
echo $echo;
}
I've got an array with images and a date for each one. I'm retrieving the date via array explode. I want to take this date value and compare it to the previous date value for the previous image. My goal here is to display these dates as headers for the sets of images that correspond to each different date.
Here is my code I've been fiddling with to try and make this work (sorry for all my slashes):
$p = 0;
$a = -1;
echo "<table>";
echo "<tr>";
foreach (array_combine($images,$locs) as $image => $loc)
{
$p++;
$a++;
$datesort = explode('>',$image);
echo "<style>";
echo "input[label=t" . $p . "] {";
echo "display: none;";
echo "}";
echo "input[label=t" . $p . "] + label {";
echo "border: 5px solid #FFFFFF;";
$image = "background: url('http://blah.com/" . $loctb[$p] . "');";
echo $image;
echo "height: 61px;";
echo "width: 92px;";
echo "display: inline-block;";
echo "padding: 0 0 0 0px;";
echo "}";
echo "input[label=t" . $p . "]:checked + label {";
echo "border: 5px solid #FF9900;";
echo "background: url('http://blah.com/" . $loctb[$p] . "');";
echo "height: 61px;";
echo "width: 92px;";
echo "display: inline-block;";
echo "padding: 0 0 0 0px;";
echo "}";
echo "</style>";
$lastdate = array("");
$lastdate[$a] = $datesort[1];
echo "<td>";
if ($lastdate[$a] <> $datesort[1]){
echo "<h2>";
echo $datesort[1];
echo "</h2>";
}
echo "<input type=\"checkbox\" label=\"t" . $p . "\" id=\"t" . $p . "\" name =\"boxes[]\" value=\"<img src=http://blah.com/" . $loc . "\" />";
echo "<label for=\"t" . $p . "\"></label>";
echo "</div>";
echo "</td>";
if ($p % 2 == 0)
{
echo "</tr>";
}
}
echo "</table>";
I've been trying to store the current date value into another array variable and then compare that to the new value the next time through my foreach loop, but I'm doing it wrong :-/...
I'd appreciate any help you can offer. Thanks
Here is a quick and dirty way, though you'll want to tune it to your needs (I had this issue but it was worse as I was also filling in the blank dates in between):
$previous_dates = array();
foreach (array_combine($images,$locs) as $image => $loc) {
$datesort = explode('>',$image);
if (end($previous_dates) <> $datesort[1]) {
echo "<h2>";
echo $datesort[1];
echo "</h2>";
}
// ... more stuff ...//
$previous_dates[] = $datesort[1];
}
Really I would reconsider the approach you're taking for the explode within the loop, but first-things-first, see if that gets you where you need to be.
I got code snippet from this site, which I used as shown below
$data = array();
while($row = mysql_fetch_assoc($num1)) {$data['row'][] = $row;}
while($row = mysql_fetch_assoc($num2)) {$data['row2'][] = $row;}
$count = count($data['row']);
echo "<table>" ;
echo "<tr>";
echo "<td width='300' bgcolor='#99CCF5' align='Left' style='padding-left:30px'><b>Country</b></td>" ;
echo "<td width='150' bgcolor='#99CCF5' align='center'><b>Mid Estimate 1</b></td>";
echo "<td width='150' bgcolor='#99CCF5' align='center'><b>Mid Estimate 2</b></td>";
echo "</tr>";
for($i=0;$i<=$count;$i++)
{
if(($i % 2) == 1)
{
echo "<tr>" ;
echo "<td align='center'>" . $data['row'][$i]['Country']."</td>";
echo "<td align='center'>" . $data['row'][$i]['MidEstimate']."</td>";
echo "<td align='center'>" . $data['row2'][$i]['MidEstimate']."</td>";
echo "</tr>" ;
}else
{
echo "<tr>" ;
echo "<td align='center'>" . $data['row'][$i]['Country'] ."</td>";
echo "<td align='center'>" . $data['row'][$i]['MidEstimate']."</td>";
echo "<td align='center'>" . $data['row2'][$i]['MidEstimate']."</td>";
echo "</tr>" ;
}
}
echo "</table>" ;
which gives a reult like below
image1 http://img4.pixa.us/8ba/19338641.jpg
where the correct result should be like this
image2 http://img4.pixa.us/c1d/19338642.jpg
that is if any value in a column is empty the next adjucent value gets that position. How can I make this correct? that is if any value is empty that column must be empty.
please help and thanks in advance.
You have to gather the data for each country. Your approach in the question messes up the listing since the keys for the array are not in sync. Let's sync your rows by 'Country':
$data = array();
while($row = mysql_fetch_assoc($num1))
{
$c = $row['Country'];
if (!isset($data[$c]))
{
$data[$c] = array('Country' => $c);
}
$data[$c]['MidEstimate1'] = $row['MidEstimate'];
}
while($row = mysql_fetch_assoc($num2))
{
$c = $row['Country'];
if (!isset($data[$c]))
{
$data[$c] = array('Country' => $c);
}
$data[$c]['MidEstimate2'] = $row['MidEstimate'];
}
Now you have a row in your array for every Country, with their data from each query.
$i = 0;
foreach ($data as $row)
{
echo ($i % 2) ? "<tr class='odd'>" : "<tr class='even'>" ;
echo "<td align='center'>" . $row['Country']."</td>";
echo "<td align='center'>" . $row['MidEstimate1']."</td>";
echo "<td align='center'>" . $row['MidEstimate2']."</td>";
echo "</tr>" ;
}
Note: this only works in 'Country' field is present in both SQL query.
I'm trying to have a "1" printed if there is a value in cDeviceRegistrationId column in the database. Here is the code:
$result is an SQL query
while($row = mysql_fetch_assoc($result))
{
if ($row['cDeviceRegistrationId'] > 0) {
$a = 1;
}
echo "<tr class='forum'>";
echo "<td class='forum'>" . $row['intUserID'] . "</td>";
echo "<td class='forum'>" . $row['cUsername'] . "</td>";
echo "<td class='forum'>" . $row['cEmail'] . "</td>";
echo "<td class='forum'>$a</td>";
echo "<td class='forum'>" . $row['uCreateDate'] . "</td>";
echo "</tr>";
}
The value of $a is not overwritten if it does not meet the condition, meaning other iterations may get the value of 1 incorrectly. Here is a fix (replace your if statement):
$a = ($row['cDeviceRegistrationId'] > 0) ? 1 : '';
How about:
if( !is_null($row['cDeviceRegistrationId']) ){
$a = 1;
}