pdo code for fetching data dynamically in a table - pdo

I want a pdo code for fetching data from database into a table dynamically when the page is opened.It took me an entire day but I still didnt get an appropriate code,PLEASE HELP ME OUT
<div class="card">
<div class="card-header">
<h2>Selection Example <small>Ensure that the data attribute [data-identifier="true"] is set on one column header.</small></h2>
</div>
<table id="data-table-command" class="table table-striped table-vmiddle">
<thead>
<tr>
<th data-column-id="id" data-type="numeric">ID</th>
<th data-column-id="sender">Sender</th>
<th data-column-id="received" data-order="desc">Received</th>
<th data-column-id="commands" data-formatter="commands" data-sortable="false">Commands</th>
</tr>
</thead>
<tbody>
<tr>
<td>10238</td>
<td>eduardo#pingpong.com</td>
<td>14.10.2013</td>
</tr>
<tr>
<td>10243</td>
<td>eduardo#pingpong.com</td>
<td>19.10.2013</td>
</tr>
<tr>
<td>10248</td>
<td>eduardo#pingpong.com</td>
<td>24.10.2013</td>
</tr>
<tr></tbody>
</table>
</div></div>

$data = $pdo->query("SELECT * FROM t")->fetchAll();
if ($data) {
echo "<table><tr>";
foreach (array_keys($data[0] as $col)) {
echo "<th>$col</th>";
}
echo "</tr>";
foreach($pdo->query("SELECT * FROM t") as $row) {
echo "<tr>";
foreach ($row as $col) {
echo "<td>$col</td>";
}
echo "</tr>";
}
echo "</table>";
}

Related

auto refresh div only when data is changed in laravel-8

I can auto-refresh the page every 5 seconds using this code
?php
$page = $_SERVER['PHP_SELF'];
$sec = "10";
?>
<html>
<head>
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
</head>
<body>
<div id="auto_refresh">
<table id="example1" class="table table-bordered table-striped table-sm">
<thead>
<tr>
<th>SL</th>
<th>Match Name</th>
<th>Team Name</th>
</tr>
</thead>
<tbody>
#foreach ($databowlersecond as $key => $row)
<tr>
<td>{{ $key + 1 }}</td>
<td>{{ $row->matchh->match_name }}</td>
<td>{{ $row->team->team_name }}</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</body>
</html>
But I want auto-refresh my div when data is updated how to do this?

how to get data from database in wordpress

Hello i want to get the data from database and put in on pages i write this code but it didnt work. how can i get the data from sql to be appear in the page thank for helping
<?php
global $wpdb;
$table_name = $wpdb wp_ ."sheet1";
$sql = "SELECT * FROM sheet1 WHERE Course='Filipino' ORDER BY Lastname";
$results = $wpdb->get_results( $sql);
?>
Data should be appear in this table
<table id="passers_table">
<thead>
<tr>
<th><center>Course</center></th>
<th><center>Student Number</center></th>
<th><center>Name</center></th>
<th><center>LinkedIn Account</center></th>
<th><center>Email Address</center></th>
<th><center>Nationality</center></th>
<th><center>City</center></th>
<th><center>Country</center></th>
</tr>
</thead>
<tbody>
<tr>
<td>$print->;Course</td><br>
<td>$print->;Studno</td><br>
<td>$print->;Title $print->Firstname $print->Lastname</td><br>
<td style="font-style: italic;"><center>PRIVATE</center></td><br>
<td><center><a href="$print->Linkedin" target="_blank" rel="noopener
noreferrer"><u>Click Here</u></a></center></td><br>
<td style="font-style: italic;"><center>PRIVATE</center></td><br>
<td><center>$print->;Email</center></td><br>
<td>$print->;Nationality</td><br>
<td>$print->;City</td><br>
<td>$print->;Country</td>
</tr>
</tbody>
</table>
Table and data wont appear do it have a problem in my code?
this is the other code that i tried but the data wont appear also
<?php global $wpdb; $table_name = $wpdb wp_ ."sheet1";
$sql = "SELECT * FROM sheet1 WHERE Course='Filipino' ORDER BY Lastname";
<br>$result = $wpdb-> ;get_results($sql) or die(mysql_error());
<p>foreach ( $result as $print )<br>{<br>echo"</p>
<p>";</p>
<p>if ($print->Linkedin==null)<br>{<br>echo"</p>
<p>";<br>}else<br>{<br>echo"</p>
<p>";<br>}</p>
<p>if ($print->Email==null)<br>{<br>echo"</p>
<p>";<br>}else<br>{<br>echo"</p>
<p>";<br>}</p>
<p>echo"</p>
<p>";<br>}<br>?>;</p> ?>
<table id="passers_table">
<thead>
<tr>
<th><center>Course</center></th>
<th><center>Student Number</center></th>
<th><center>Name</center></th>
<th><center>LinkedIn Account</center></th>
<th><center>Email Address</center></th>
<th><center>Nationality</center></th>
<th><center>City</center></th>
<th><center>Country</center></th>
</tr>
</thead>
<tbody>
<tr>
<td>$print->;Course</td><br>
<td>$print->;Studno</td><br>
<td>$print->;Title $print->Firstname $print->Lastname</td><br>
<td style="font-style: italic;"><center>PRIVATE</center></td><br>
<td><center><a href="$print->Linkedin" target="_blank" rel="noopener
noreferrer"><u>Click Here</u></a></center></td><br>
<td style="font-style: italic;"><center>PRIVATE</center></td><br>
<td><center>$print->;Email</center></td><br>
<td>$print->;Nationality</td><br>
<td>$print->;City</td><br>
<td>$print->;Country</td>
</tr>
</tbody>
</table>
i put it on the wp-login in the page where should the table and the data should appear
Hi please check below code and let me know if its not working. can i know which file you add this code ?
<?php
global $wpdb;
$table_name = $wpdb->prefix."sheet1";
$sql = "SELECT * FROM ".$table_name." WHERE Course ='Filipino' ORDER BY Lastname";
$results = $wpdb->get_results($sql);
?>
<!-- Data should be appear in this table-->
<table id="passers_table">
<thead>
<tr>
<th><center>Course</center></th>
<th><center>Student Number</center></th>
<th><center>Name</center></th>
<th><center>LinkedIn Account</center></th>
<th><center>Email Address</center></th>
<th><center>Nationality</center></th>
<th><center>City</center></th>
<th><center>Country</center></th>
</tr>
</thead>
<tbody>
<tr>
<?php
foreach($results as $print){
?>
<td><?php echo $print->Course;?></td><br>
<td><?php echo $print->Studno;?></td><br>
<td><?php echo $print->Title.' '.$print->Firstname.' '.$print->Lastname;?></td><br>
<td style="font-style: italic;"><center>PRIVATE</center></td><br>
<td><center><a href="<?php echo $print->Linkedin;?>" target="_blank" rel="noopener
noreferrer"><u>Click Here</u></a></center></td><br>
<td style="font-style: italic;"><center>PRIVATE</center></td><br>
<td><center><?php echo $print->Email;?></center></td><br>
<td><?php echo $print->Nationality;?></td><br>
<td><?php echo $print->City;?></td><br>
<td><?php echo $print->Country;?></td>
<?php } ?>
</tr>
</tbody>
</table>
Here is your code
<?php
global $wpdb;
$table_name = $wpdb wp_ ."sheet1";
$sql = "SELECT * FROM sheet1 WHERE Course='Filipino' ORDER BY Lastname";
$results = $wpdb->get_results( $sql);
?>
//Data should be appear in this table
<table id="passers_table">
<thead>
<tr>
<th><center>Course</center></th>
<th><center>Student Number</center></th>
<th><center>Name</center></th>
<th><center>LinkedIn Account</center></th>
<th><center>Email Address</center></th>
<th><center>Nationality</center></th>
<th><center>City</center></th>
<th><center>Country</center></th>
</tr>
</thead>
<tbody>
<tr>
<?php foreach($results as $print-> )
{ ?>
<td><?php echo $print->Course;?></td><br>
<td><?php echo $print->Studno;?></td><br>
<td><?php echo $print->Title;.$print->Firstname.$print->Lastname;?></td><br>
<td style="font-style: italic;"><center>PRIVATE</center></td><br>
<td><center><a href="<?php echo $print->Linkedin;?>" target="_blank" rel="noopener
noreferrer"><u>Click Here</u></a></center></td><br>
<td style="font-style: italic;"><center>PRIVATE</center></td><br>
<td><center><?php echo $print->Email;?></center></td><br>
<td><?php echo $print->Nationality;?></td><br>
<td><?php echo $print->City;?></td><br>
<td><?php echo $print->Country;?></td>
<?php } ?>
</tr>
</tbody>
</table>

Data is not showing up in html

I am running into a issue with showing the data from my variable, itemListPrice. I have checked in the console and the data is populated into the itemListPrice, but its not showing up in my html, am I loading it all wrong?
Here is the markup
<div id="app2">
<div id="TableContainer" style="width:798px !important">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<td><label>Catalog Name</label></td>
</tr>
</thead>
<tbody>
<tr>
<td>{{ currentCatalogName }}</td>
</tr>
</tbody>
</table>
<table class="table">
<thead>
<tr>
<td><label>Item Name</label></td>
</tr>
</thead>
<tbody>
<tr>
<td> {{ itemPriceList.Name }}</td>
</tr>
</tbody>
</table>
<table class="table">
<thead>
<tr>
<td colspan="2"><label>Item List</label></td>
</tr>
</thead>
<tbody>
<tr>
<td width="575px">${{ itemPriceList.ItemListPrice }}</td>
<td>${{ itemPriceList.ItemListPrice }}</td>
</tr>
</tbody>
</table>
<table class="table">
<thead>
<tr>
<td colspan="3"><label>Item Features</label></td>
<td></td>
</tr>
</thead>
<tbody>
<template v-for="item in itemPriceList.ItemFeatures">
<tr v-if="item.FeatureQuantity != 0">
<td width="250px">{{ item.FeatureName }}</td>
<td>{{ item.FeatureQuantity }}</td>
</tr>
</template>
</tbody>
</table>
<table class="table">
<thead>
<tr>
<td><label>Item IAM</label></td>
</tr>
</thead>
<tbody>
<tr>
<td>{{ itemPriceList.ItemIAM }}</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
and here is my code
new Vue({
el: '#app2',
beforeCreate: function () {
StartBusyIndicator("#ItemPriceListWindow");
},
created: function () {
this.GetItemDetails();
},
mounted: function () {
StopBusyIndicator("#ItemPriceListWindow");
},
data: {
itemPriceList: [],
orderItems: currentOrderItems,
currentCatalogName: currentCatalog,
priceList: null
},
methods: {
GetItemDetails: function () {
TryCatch(function() {
let result = GetItemPriceDetails();
this.itemPriceList = result;
priceList = result;
});
},
GetOrderItems: function () {
},
OptionPriceSplitter: function (optionprice) {
return TryCatch(function() {
let sentenceSplit = optionprice.split('& ');
let comp = '';
for (let i = 0; i < sentenceSplit.length; i++) {
comp += sentenceSplit[i] + '\n';
}
return sentenceSplit;
});
},
GlobalListPriceCalculation: function (globalgroupid) {
return TryCatch(function() {
let listPrice = 0.00;
let priceList = this.itemPriceList;
let result = priceList.GlobalListPrices.filter(function(item) {
if (item.GlobalGroupID == globalgroupid) {
listPrice = listPrice + item.Price;
}
});
if (listPrice == 0) {
listPrice = "";
} else {
listPrice = "$" + listPrice.toFixed(2);
}
return listPrice;
});
}
}
});
assuming TryCatch(cb) is something along the lines of
function TryCatch(cb){ let x = null; try { x = cb() } catch(e) {} return x; }
you loose 2 important things:
this (you could bind it via cb.call(this))
utterly usefull error messages
furher points:
I have checked in the console
checkout the excellent browser plugin for ff and chrome vue-devtools
itemPriceList = []
you initalize itemPriceList as array, use it as array item in itemPriceList, but also use it as object {{ itemPriceList.Name }} - what shall it be ?

how to print data in pdf format yii

in yii 1.1,I want to print list of data displayed in table into pdf format .I have no idea about this.I am in need of help.
My view code:
<?php echo CHtml::link('Print Envelop','marketingEmail/pdfPrint', array('class'=>'btn','target'=>'_blank')); ?>
<?php $form=$this->beginWidget('CActiveForm', array(
'id'=>'search-form',
'enableClientValidation'=>true,
'clientOptions'=>array(
'validateOnSubmit'=>true,
),
));
?>
<table class="bluetable" id="myDemoTable" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th colspan="24"><b>Mail Listing</b></th>
</tr>
</thead>
<tbody>
<tr>
<td><b>S.N.</b></td>
<td width="300"><b>Company</b></td>
<td width="300"><b>Follow up By</b></td>
</tr>
</tbody>
</table>
<?php
$this->endWidget();
?>

Post form data to controller

I want to submit the table row values of the rows that are checked to my controller. My controller is always receiving a parameter of value null.
#model IEnumerable<GoogleMapsAPIWeb.Models.Schedule>
#using (Html.BeginForm("Route", "Home", FormMethod.Post))
{
<div>
<table id="schedulerTable">
<thead>
<tr>
<th scope="col"></th>
<th scope="col" >View</th>
<th scope="col">Site Id</th>
</tr>
</thead>
<tbody>
#foreach (var row in Model)
{
<tr>
<td>#Html.CheckBoxFor(c=>row.isSelected)</td>
<td class="smallerDataField">
<a>View</a>#*TODO add code to view*#
</td>
<td><div class="smallerDataField">#row.SiteId</div></td>
</tr>
}
</tbody>
</table>
<input id="btnFindRoute" type="submit" value="Plan Route" />
</div>
}
[HttpPost]
public ActionResult Route(IEnumerable<Schedule> Schedules)
{
Use for loop for this purpose. More info
for (int i = 0; i < Model.Count(); i++)
{
<tr>
<td>#Html.CheckBoxFor(c=> Model[i].isSelected)</td>
</tr>
...
}