I am trying to display name and age in a single field of the table and I want data to be displayed in the place of . I tried the code below but it doesn't work.
CODE:
<?php
$con=mysqli_connect("localhost","root","","dva");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM apform");
while($row = mysqli_fetch_array($result)) {
echo "My Mood: ";
echo $row['mood'];
echo "<br>";
}
?>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Doctor</th>
<th>Telephone</th>
<th>Mobile</th>
<th>Meeting Time</th>
<th>Fee</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<tr>
<td data-title="Name"><span> <?php echo $row['name']; ?> </span></td>
<td data-title="Relationship"><span> </span></td>
<td data-title="Address"><span> </span></td>
<td data-title="Telephone"><span> </span></td>
<td data-title="Mobile"><span> </span></td>
<td data-title="Contact at night"><span> </span></td>
<td data-title="Next of kin"><span> </span></td>
<td data-title="Delete"><span> </span></td>
</tr>
You can easily achieve what you need to putting the while loop inside of your table and echoing out all of the relevant fields.
<?php
$con=mysqli_connect("localhost","root","","dva");
// Check connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM apform");
while($row = mysqli_fetch_array($result)) {
echo "My Mood: ";
echo $row['mood'];
echo "<br>";
}
?>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Doctor</th>
<th>Telephone</th>
<th>Mobile</th>
<th>Meeting Time</th>
<th>Fee</th>
<th>Date</th>
</tr>
</thead>
<tbody>
<?php while($row = mysqli_fetch_array($result)) { ?>
<tr>
<td data-title="Name"><span><?php echo $row['name']; ?></span></td>
<td data-title="Relationship"><span><?php echo $row['relationship']; ?></span></td>
<td data-title="Address"><span><?php echo $row['address']; ?></span></td>
<td data-title="Telephone"><span><?php echo $row['telephone']; ?></span></td>
<td data-title="Mobile"><span><?php echo $row['mobile']; ?></span></td>
<td data-title="Contact at night"><span><?php echo $row['contact']; ?></span></td>
<td data-title="Next of kin"><span><?php echo $row['nok']; ?></span></td>
<td data-title="Delete"><span>Delete</span></td>
</tr>
<?php } ?>
</tbody>
Related
I am fetching some data from the table using codeigniter
My table picture
This is my table that i have fetched from the table.in this i have show the balance column in first row as 10 and next row as 35 how i calculate this using java script or php itself.
My code:
<table class="table datatable-button-html5-basic">
<thead>
<tr><h6>
<th class="col-sm">Bill No</th>
<th class="col-sm" >Date</th>
<th class="col-sm" >Particulars</th>
<th class="col-sm" >Op.Stock</th>
<th class="col-sm-7">Pur/Prod</th>
<th class="col-sm" >Sales/Cons</th>
<th class="col-sm" >Balance</th>
</tr>
</thead>
<tbody>
<?php foreach ($query as $row): ?>
<tr>
<?php $total = 0;
$total += $row['qty']; ?>
<td> <?php echo $row['orderno'];?></td>
<td ><?php echo $row['orderdate'];?></td>
<td >PRODUCTION</td>
<td></td>
<td dir="rtl"><?php echo $row['qty'];?></td>
<td></td>
<td><?php echo "$total" ;?></td>
</tr><?php endforeach ?>
<tr><?php foreach ($query1 as $row1): ?>
<td> <?php echo $row1['billno'];?></td>
<td ><?php echo $row1['billdate'];?></td>
<td ><?php echo $row1['accName'];?></td>
<td></td>
<td></td>
<td dir="rtl"><?php echo $row1['salesqty'];?></td>
<td></td>
</tr>
<?php endforeach ?>
</tbody>
This is my table code.
My another sample table:
Define $balance before foreach, and sum as $balance += $total; every row of balance column.
<table class="table datatable-button-html5-basic">
<thead>
<tr><h6>
<th class="col-sm">Bill No</th>
<th class="col-sm" >Date</th>
<th class="col-sm" >Particulars</th>
<th class="col-sm" >Op.Stock</th>
<th class="col-sm-7">Pur/Prod</th>
<th class="col-sm" >Sales/Cons</th>
<th class="col-sm" >Balance</th>
</tr>
</thead>
<tbody>
<?php
$balance = 0;
foreach ($query as $row): ?>
<tr>
<?php $total = 0;
$total += $row['qty'];
$balance += $total;
?>
<td> <?php echo $row['orderno'];?></td>
<td ><?php echo $row['orderdate'];?></td>
<td >PRODUCTION</td>
<td></td>
<td dir="rtl"><?php echo $row['qty'];?></td>
<td></td>
<td><?php echo "$total" ;?></td>
</tr><?php endforeach ?>
<tr><?php foreach ($query1 as $row1): ?>
<td> <?php echo $row1['billno'];?></td>
<td ><?php echo $row1['billdate'];?></td>
<td ><?php echo $row1['accName'];?></td>
<td></td>
<td></td>
<td dir="rtl"><?php echo $row1['salesqty'];?></td>
<td></td>
</tr>
<?php endforeach ?>
</tbody>
I have a html table Image table, and I would like to populate or fill the html table using data from database(mysql). This is the data from my database Image Data. I can not think of anything to put the data into my html table per supplier name. Do you guys know how to do this? Using any of the languages such as PHP, JavaScript.
This is my actual table Actual Image. I already tried it myself but I only get the supplier name. This is the my code to get the supplier name. This should be the expected output Output Image
<thead>
<tr id="tr-1">
<th><th><th><th><th></th></th></th></th></th>
<?php $i = 1; foreach ($supp_name as $key => $value) { ?>
<th colspan="2" class="supplier_name_class"><input type="text" class="supplier_name" placeholder="Supplier Name" id="supplier_name-1" value="<?php echo $value->supplier_name; ?>" style="width: 300px; text-align: center;"></th>
<?php $i++; } ?>
</tr>
<tr id="tr-2">
<th>LN</th>
<th>PR No</th>
<th>Description</th>
<th>Qty</th>
<th>Unit</th>
<?php $i = 1; foreach ($supp_name as $key => $value) { ?>
<th>Price</th>
<th>Total</th>
<?php $i++; } ?>
</tr>
</thead>
<tbody>
<?php $i = 1; foreach ($supp_dtl as $key => $value) { ?>
<tr>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
</tr>
</tbody>
i created an appointments table where user1 would add appointments and user2 would accept/reject the appointment. now my problem is when the accept and reject are clicked it is displayed in the table respectively but i just cant understand how to add the insert query into it so that it could be inserted into the db. i tried several methods in trying to insert the state[accept/reject] into the db but i found no success. i would request someone to pls provide me some help inn fixing the issue. Thanks.
<form method="post" action="delete.php" >
<table cellpadding="0" cellspacing="0" border="0" class="table table-condensed" id="example">
<thead>
<tr>
<th>appoinment ID</th>
<th>Date</th>
<th>time</th>
<th>teacher</th>
<th>parent</th>
<th> accept/reject </th>
<th>label</th>
</tr>
</thead>
<tbody>
<?php
$query=mysqli_query($conn, "select * from `app` left join `par` on par.par_id=app.par_id
left join `tea` on tea.tea_id=app.tea_id
ORDER BY app_id DESC");
if($query === false)
{
throw new Exception(mysql_error($conn));
}
while($row=mysqli_fetch_array($query))
{
$ann_id=$row['app_id'];
$date=$row['date'];
$msg=$row['time'];
$username = $row['username'];
$username = $row['p_username'];
?>
<tr>
<td><?php echo $row['app_id'] ?></td>
<td> <?php echo date('j/m/y',strtotime($row['date'])); ?></td>
<td><?php echo $row['time'] ?></td>
<td><?php echo $row['p_username'] ?></td>
<td><?php echo $row['username'] ?></td>
<td>
reject
accept
</td>
<td>
<div class="chgtext">PENDING</div>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</form>
One way is to pass the ID via query string (GET). So you would update the appointment if the appropriate query string key-pairs are given.
Personally, I believe you should not mix querying while outputting. Do the database stuff at the top first and leave the outputting at the bottom.
Note: I am not too familiar with mysqli_ but it would be something like this:
<?php
// accept or reject appointment with ID
if (isset($_GET['state'], $_GET['app_id'])) {
$stmt = mysqli_prepare($conn, "UPDATE app SET state = ? WHERE app_id = ?");
mysqli_stmt_bind_param($stmt, "sd", $_GET['state'], $_GET['app_id']);
mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
}
// query appointments
$query = mysqli_query($conn, "
SELECT * FROM app
LEFT JOIN par ON par.par_id = app.par_id
LEFT JOIN tea on tea.tea_id = app.tea_id
ORDER BY app_id DESC
");
?>
<form method="post" action="delete.php" >
<table cellpadding="0" cellspacing="0" border="0" class="table table-condensed" id="example">
<thead>
<tr>
<th>appoinment ID</th>
<th>Date</th>
<th>time</th>
<th>teacher</th>
<th>parent</th>
<th>accept/reject</th>
<th>label</th>
</tr>
</thead>
<tbody>
<?php while($row = mysqli_fetch_array($query)) : ?>
<tr>
<td><?= $row['app_id'] ?></td>
<td><?= date('j/m/y', strtotime($row['date'])) ?></td>
<td><?= $row['time'] ?></td>
<td><?= $row['p_username'] ?></td>
<td><?= $row['username'] ?></td>
<td>
<!-- upon clicking a link, it will redirect to the same page with a query string -->
reject
accept
</td>
<td>
<div class="chgtext">PENDING</div>
</td>
</tr>
<?php endwhile ?>
</tbody>
</table>
</form>
This question already has answers here:
Reference - What does this error mean in PHP?
(38 answers)
Closed 6 years ago.
This is my form distributor data code.
If I click the button before it would be an error
Warning: mysql_query() expects parameter 2 to be resource, null given in C:\xampp\htdocs\3s_shop\admin\pembelian_data.php on line 6
error paging:
What's wrong in the code?
<?php
# UNTUK PAGING (PEMBAGIAN HALAMAN)
$baris = 50;
$hal = isset($_GET['hal']) ? $_GET['hal'] : 0;
$pageSql = "SELECT * FROM pembelian";
$pageQry = mysql_query($pageSql, $koneksidb) or die ("error paging: ".mysql_error());
$jml = mysql_num_rows($pageQry);
$maksData = ceil($jml/$baris);
?>
<table width="800" border="0" cellpadding="2" cellspacing="1" class="table-border">
<tr>
<td colspan="2" align="right"><h1><b>DATA PEMBELIAN</b></h1></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2" align="right"><img src="../images/btn_add_data.png" height="30" border="0" /></td>
</tr>
<tr>
<td colspan="2"><table class="table-list" width="100%" border="0" cellspacing="1" cellpadding="2">
<tr>
<th width="35" align="center" bgcolor="#CCCCCC">No</th>
<th width="250" bgcolor="#CCCCCC">Nama Reseller</th>
<th width="100" bgcolor="#CCCCCC">Tanggal Pembelian</th>
<th width="250" bgcolor="#CCCCCC">Nama Produk</th>
<th width="150" bgcolor="#CCCCCC">Harga Produk </th>
<th width="50" bgcolor="#CCCCCC">Jumlah Produk </th>
<th width="150" bgcolor="#CCCCCC">Total Harga </th>
<td colspan="2" align="center" bgcolor="#CCCCCC"><strong>Tools</strong></td>
</tr>
<?php
$mySql = "SELECT * FROM pembelian ORDER BY nm_reseller, tgl_pembelian, nama_barang, hrg_barang, qty ASC LIMIT $hal, $baris";
$myQry = mysql_query($mySql, $koneksidb) or die ("Query salah : ".mysql_error());
$nomor = $hal;
while ($myData = mysql_fetch_array($myQry)) {
$nomor++;
$Kode = $myData['kd_pembelian'];
// Warna baris data
if($nomor%2==1) { $warna=""; } else {$warna="#F5F5F5";}
?>
<tr bgcolor="<?php echo $warna; ?>">
<td align="center"><?php echo $nomor; ?></td>
<td><?php echo $myData['nm_reseller']; ?></td>
<td><?php echo $myData['tgl_pembelian']; ?></td>
<td><?php echo $myData['nama_barang']; ?></td>
<td><?php echo $myData['hrg_barang']; ?></td>
<td><?php echo $myData['qty']; ?></td>
<td width="44" align="center">Edit</td>
<td width="44" align="center">Hapus</td>
</tr>
<?php } ?>
</table></td>
</tr>
<tr class="selKecil">
<td><b>Jumlah Data :</b> <?php echo $jml; ?> </td>
<td align="right"><b>Halaman ke :</b>
<?php
for ($h = 1; $h <= $maksData; $h++) {
$list[$h] = $baris * $h - $baris;
echo " <a href='?open=Pembelian-Data&hal=$list[$h]'>$h</a> ";
}
?> </td>
</tr>
</table>
I think you are not establishing connection to your database. The second input should be that connection variable. like this:
$link = mysql_connect("localhost","root","");
$koneksidb = mysql_select_db('databaseName', $link);
$pageSql = "SELECT * FROM pembelian";
$pageQry = mysql_query($pageSql, $koneksidb) or die ("error paging: ".mysql_error());
I have a table like this:
<table>
<tr>
<td>100</td>
</tr><br>
<tr>
<td>200</td>
</tr><br>
<tr>
<td>300</td>
</tr><br>
<tr>
<td>400</td>
</tr><br>
<tr>
<td>500</td>
</tr><br>
<tr>
<td>600</td>
</tr><br><br>
<tr>
<td>Total: </td>
<td>2100</td>
</tr>
</table>
I want to count and display the total of the column as shown above using PHP but I am not sure how to make this possible. Please help.
You could easily do this with javascript document.getElementById("idHere").value and stock the sum of them in a single variable.
The bad part is that you should give every td an Id.
In PHP you should give them name attribute, add a submit button and get the values from the global-variable $_POST["nameOfTD"];
You can use buffer to read the content of the page then parse html:
<?php
ob_start();
?><table>
<tr>
<td class="foo">100</td>
</tr><br>
<tr>
<td class="foo">200</td>
</tr><br>
<tr>
<td>300</td>
</tr><br>
<tr>
<td>400</td>
</tr><br>
<tr>
<td>500</td>
</tr><br>
<tr>
<td>600</td>
</tr><br><br>
<tr>
<td>Total: </td>
<?php
$DOM = new DOMDocument;
$DOM->loadHTML(ob_get_contents());
$items = $DOM->getElementsByTagName('td');
function getClass($item) {
foreach ($item->attributes as $name => $attrNode) {
if ($name == 'class') {
return $attrNode->nodeValue;
}
}
}
$sum = 0;
for ($i = 0; $i < $items->length; $i++) {
$item = $items->item($i);
if (getClass($item) == 'foo') {
$sum += intval($item->nodeValue);
}
}
echo "<td>" . $sum . "</td>";
?>
</tr>
</table>
<?php
ob_end_flush();
?>