Fetch data from table and display it in bootstrap table - php

I am fetch data from table insdie php script and displaying in table. This php script is called by button click event.
Here is the php code which does this:
while ($row = #mysqli_fetch_array($result))
{
echo '<div class = "c2">
<table class="table table-condensed">
<tbody>
<tr class="active">
<td class="active"></td>
<td class="active">'.$row['date'].'</td>
<td class="success">'.$row['time'].'</td>
<td class="warning">'.$row['username'].'</td>
<td class="danger">'.$row['user_follower_count'].'</td>
<td class="info">'.$constant.'</td>
<td class="active">'.$row['tweet_text'].'</td>
<td class="success">...dfd</td>
</tr>
</tbody>
</div>
';
}
However the content display looks messed.
I have used bootstrap css here
Like
How can I display so that all rows appears with same width in proper manner?
Content is displayed when button is clicked.

Try this:
echo '<div class="c2"><table class="table table-condensed"><tbody>';
while ($row = #mysqli_fetch_array($result))
{
echo '<tr class="active">
<td class="active"></td>
<td class="active">'.$row['date'].'</td>
<td class="success">'.$row['time'].'</td>
<td class="warning">'.$row['username'].'</td>
<td class="danger">'.$row['user_follower_count'].'</td>
<td class="info">'.$constant.'</td>
<td class="active">'.$row['tweet_text'].'</td>
<td class="success">...dfd</td>
</tr>';
}
echo '</tbody></table></div>';

Related

Add a button with elseif $row?

I need to place a button that says "Yes", but I need that when clicking on the button take the user to a web page, here is the php code for them to review:
<table cellpadding="1" cellspacing="1" id="member">
<thead>
<tr>
<th colspan="10">Players Not Activated</th>
</tr>
<tr>
<td class="on">#</td>
<td class="on">ID</td>
<td class="on">Username</td>
<td class="on">Email</td>
<td class="on">Tribe</td>
<td class="on">Activation Code</td>
<td class="on">Act 2??</td>
<td class="on">Time</td>
<td class="on">PLAY</td>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT * FROM ".TB_PREFIX."activate";
$result = mysqli_query($GLOBALS["link"], $sql);
while($row = mysqli_fetch_assoc($result))
{
$i++;
if($row['tribe'] == 1) {$tribe = "Roman"; }
elseif($row['tribe'] == 2) {$tribe = "Teuton"; }
elseif($row['tribe'] == 3) {$tribe = "Gaul"; }
echo "
<tr>
<td>".$i."</td>
<td>".$row['id']."</td>
<td>".$row['username']."</td>
<td>".$row['email']."</td>
<td>".$tribe."</td>
<td>".$row['act']."</td>
<td>".$row['act2']."</td>
<td class=\"hab\">".date('d:m:Y H:i', $row['timestamp'])."</td>
</tr>";
}
?>
</tbody>
</table>
I need the button to appear where it says "PLAY"
and the destination url i want is this link:
<a href="activate.php?id=<?php echo $_GET['id']; ?>
I have tried 4 days ago to be able to make it work but whenever I modify the file I receive a blank error page.

Footer is Not Fit to Datatables Jquery After First Load

I have a problem with datatables jquery. My dashboard footer is not fit to datatables when the page first load a lot of data (paggging).
Here's the screenshot:
Click for screenshot
After i try to open inspect element, or try to zoom out/in the page, the footer will automatically fit.
The footer should be like this:
Click for screenshot 2
Video record: https://drive.google.com/file/d/1vSjzqGuknJhl_jPtnZTdf5mNYTNlvBmf/view?usp=drivesdk
Thanks before.
My datatables code:
<table id="datatable" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
<thead>
<tr>
<th>No</th>
<th>Nama Trainset</th>
<th>Status Aktif</th>
<th>Aksi</th>
</tr>
</thead>
<tbody>
<?php
foreach ($trainset_data as $trainset)
{
?>
<tr>
<td align="center" width="80px"><?php echo ++$start ?></td>
<td align="center" ><?php echo $trainset->nm_trainset ?></td>
<td align="center" ><?php echo $trainset->aktif ?></td>
<td style="text-align:center" width="200px">
<?php
echo anchor(site_url('trainset/update/'.$trainset->id_trainset),'Perbarui');
echo ' | ';
echo anchor(site_url('trainset/delete/'.$trainset->id_trainset),'Hapus','onclick="javasciprt: return confirm(\'Apakah Anda yakin akan menghapus data ini?\')"');
?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>

I want to show database result in PHP but it keeps giving the same error

<?php
require_once('../mysql_connect.php');
$query = "SELECT customerName
FROM customerName
WHERE membership = 0";
$result=mysqli_query($dbc,$query);
echo '<table width="75%" border="1" align="center" cellpadding="0"
cellspacing="0" bordercolor="#000000">
<tr>
<td width="10%"><div align="center"><b>CUSTOMER NAME
</div></b></td>
<td width="10%"><div align="center"><b>APPROVE
</div></b></td>
<td width="10%"><div align="center"><b>REJECT
</div></b></td>
</tr>';
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){
echo "<tr>
<td width=\"10%\"><div align=\"center\">{$row['customerName']}
</div></td>
<td width=\"10%\"><div align=\"center\"> /*this is supposed to show a button*/
</div></td>
<td width=\"10%\"><div align=\"center\"> /*this is supposed to show a button*/
</div></td>
</tr>";
}
echo '</table>';
?>
I want to show the content of my database in PHP
so I used a code used from another program!
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC))
(this statement is supposed to mean while the db /row has content?)
$result=mysqli_query($dbc,$displayName);
whenever I use it for my program it gives me the same error over and over, error is that:
mysqli_fetch_array() expects parameter 1 to be mysqli_result
I give it mysqli_result
but it says I gave a boolean!
I try to enclose mysqli_result in '' just because the former errors were like it's expecting 'mysqli_result' but it becomes a string so I tried changing mysqli_fetch_array into mysqli_fetch_row which shows the same error!!
also would it be because I am wanting to show buttons in the table?
It might be helpful to you.
db.php
<?php
$conn = mysqli_connect('localhost','root','','crud_db');
if(!$conn){
die('error connecting to database');
}
?>
index.php
<?php
require_once('db.php');
$query = "SELECT *
FROM employees";
$result=mysqli_query($conn,$query);
echo '<table width="75%" border="1" align="center" cellpadding="0"
cellspacing="0" bordercolor="#000000">
<tr>
<td width="10%"><div align="center"><b>EMPLOYEE NAME
</div></b></td>
<td width="10%"><div align="center"><b>APPROVE
</div></b></td>
<td width="10%"><div align="center"><b>REJECT
</div></b></td>
</tr>';
while($row=mysqli_fetch_array($result,MYSQLI_ASSOC)){
echo "<tr>
<td width=\"10%\"><div align=\"center\">{$row['ename']}
</div></td>
<td width=\"10%\"><div align=\"center\"> <button type=\"button\">Approve</button>
</div></td>
<td width=\"10%\"><div align=\"center\"> <button type=\"button\">Reject</button>
</div></td>
</tr>";
}
echo '</table>';
?>

Print text inputted in a php form

I put an input text in my form and when I click print it should print in the pdf the text I input in that text field following the table form format. I have a problem on how to catch data from the php file.
PFDF Here is my code:
<?php
$html = <<<MYTABLE
<table border="1" style="width:90%" title="Leave" cellpadding="5px" align="center">
<tr>
<td rowspan=1 width="70" align:"top-left"><center><b>1. Office/Agency</b> </center><br><select name="office_agency"></td>
<td rowspan=1 width="100" colspan="2" align:"top-left"><b>2. ID / Name</b><br> </td>
</tr>
<tr>
<td rowspan=1 align:"top-left"><b>3. Date of Filing:</b><br></td>
<td rowspan=1 align:"top-left"><b>4. Position</b><br></td>
<td rowspan=1 align:"top-left"><b>4. Salary</b><br></td>
..........
MYTABLE;
require('pdftable.inc.php');
mysql_connect('localhost','root','');
mysql_select_db('auth');
$p = new PDFTable();
$p->AddPage();
$p->setfont('times','',10);
$p->Cell(5,-5,' APPLICATION FOR LEAVE');
$p->Ln(3);
$p->htmltable($html);
$p->output();
?>
You need to write the content to the page using Write()
$pdf->Write("content here");
Write Documentation

store part of the page in variable

i have a page contains a table and this table contains a lot of coding like this
<table class="table">
<tbody>
<tr >
<td width="20" class="tabletop">م</td>
<td class="tabletop" >name</td>
<td class="tabletop" style="width:120px">date</td>
<td class="tabletop" style="width:120px">note1</td>
<td class="tabletop" style="width:100px">note2</td>
<td class="tabletop" style="width:90px">note3</td>
</tr>
<? $res=mysql_query($sql);
while($resArr=mysql_fetch_array($res)){ ?>
<tr style="width:700px">
<td class="tabletext"><?= ++$serial;?></td>
<td class="tabletext" ><?= $resArr[stName];?></td>
<td class="tabletext"><?= $resArr['date'];?></td>
<td class="tabletext" ><?= $resArr[matName];?></td>
<td class="tabletext" ><? if($resArr[exam]==1) echo "work";else echo "final";?></td>
<td class="tabletext" ><? if($resArr[exam_type]==1) echo "prac";else echo "test";?></td>
</tr>
<? }?>
</tbody>
</table>
as you see the table has php coding
now i want to store the whole table in variable so i can send it to pdf printing library tcpdf
You can use heredoc syntax, but you need to move the conditionals outside:
<?php
if($resArr['exam']==1) $exam = "work"; else $exam = "final";
if($resArr["exam_type"]==1) $examtype = "prac";else $examtype = "test";
$var = <<<EOT
<table class="table">
<tbody>
<tr >
<td width="20" class="tabletop">م</td>
<td class="tabletop" >name</td>
<td class="tabletop" style="width:120px">date</td>
<td class="tabletop" style="width:120px">note1</td>
<td class="tabletop" style="width:100px">note2</td>
<td class="tabletop" style="width:90px">note3</td>
</tr>
$res=mysql_query($sql);
while($resArr=mysql_fetch_array($res)){
<tr style="width:700px">
<td class="tabletext">{++$serial}</td>
<td class="tabletext" >{$resArr["stName"]}</td>
<td class="tabletext">{$resArr["date"]}</td>
<td class="tabletext" >{$resArr["matName"]}</td>
<td class="tabletext" >{$exam}</td>
<td class="tabletext" >{$examtype}</td>
</tr>
<? }?>
</tbody>
</table>
EOT;
echo $var;
Another way, if you already have all of this code and want to save it:
Before the table:
<?php ob_start(); ?>
After the table:
<?php $output = ob_get_contents(); ?>
The table will still be displayed and you can use $output to send to the PDF.

Categories