echo '<table class="table table-striped">
<tr>
<th>Character Name</th>
<th>Ban Reason</th>
<th>Ban Length</th>
<th>Proof</th>
<th>Banned On</th>
</tr>';
while($row = $result->fetch_assoc()){
echo '<tr>
<td>'.$row['charactername'].'</td>
<td>'.$row['banMessage'].'</td>
<td>'.convertToHumanReadableTime($row['banDuration']).'</td>
<td>'<img src='".$row['spy']."' />;'</td>
<td>'.date("m/d/Y", strtotime($row['banTime'])).'</td>
</tr>';
}
echo '</table>';
the Image loading isn't working cause idk it should get the link ending on .jpg inside the db
You have an issue with your quotes.
Change
echo '<tr>
<td>'.$row['charactername'].'</td>
<td>'.$row['banMessage'].'</td>
<td>'.convertToHumanReadableTime($row['banDuration']).'</td>
<td>'<img src='".$row['spy']."' />;'</td>
<td>'.date("m/d/Y", strtotime($row['banTime'])).'</td></tr>';
To
echo '<tr>
<td>'.$row['charactername'].'</td>
<td>'.$row['banMessage'].'</td>
<td>'.convertToHumanReadableTime($row['banDuration']).'</td>
<td><img src="'.$row['spy'].'" />;</td>
<td>'.date("m/d/Y", strtotime($row['banTime'])).'</td></tr>';
Related
Hello the id that im getting is "$id" instead of the int id what i would like to happen is that basically it will go to the full size of the image in the "showImage.php"
<?php
while($row = mysqli_fetch_array($result)) {
$id = $row[0];
echo "<tr>";
echo "<td>".$row[0]."</td>";
echo "<td>".$row[1]."</td>";
echo "<td>".$row[2]."</td>";
echo "<td>".$row[3]."</td>";
echo "<td>".$row[4]."</td>";
echo "<td>".$row[5]."</td>";
echo "<td>".$row[7]."</td>";
echo "<td>".$row[8]."</td>";
echo "<td>".$row[9]."</td>";
echo "<td>".$row[10]."</td>";
echo '<td>
<img id="$id" src="data:image/jpeg;base64,'.base64_encode($row[11] ).'" height="200" width="200" />
</td> ';
?>
in case you're wondering this is the html
<tr>
<th>ID</th>
<th>Voter's ID</th>
<th>Username</th>
<th>Password</th>
<th>Email</th>
<th>Confirmation Code</th>
<th>UserType </th>
<th>Age</th>
<th>Gender</th>
<th>Birthday</th>
<th>Action</th>
<th>Image</th>
<tr>
Hello i just create my support system and i get ticket detalis with echo but it show all td line as picture i need to show only the first line
my code
<table cellpadding="0" cellspacing="0" border="0" class="data">
<thead>
<tr>
<th width="115"><p2>Ticket ID</p2></th>
<th width="90"><p2>Status</p2></th>
<th width="160"><p2>Ticket Topic</p2></th>
<th width="160"><p2>Client</p2></th>
</tr>
</thead>
<tr> <?php
echo "<td><a href='?page=ticket&id=".$row[id]."'</a>#".$row[id]."</td>";
echo "<td>".$row[status]."</td>";
echo "<td>".$row[naslov]."</td>";
$userr = mysql_query('SELECT * FROM client WHERE clientid='.$row["user_id"].'');
$useri = mysql_fetch_array($userr);
echo "<td><a href='clientsummary.php?id=".$row[user_id]."'</a>".$useri['firstname']." ".$useri['lastname']."</td>";
?>
</tr>
you need to move your table header outside the loop. without seeing the mechanics of the loop, I'm guessing it will need to look similar to this:
<table cellpadding="0" cellspacing="0" border="0" class="data">
<thead>
<tr>
<th width="115"><p2>Ticket ID</p2></th>
<th width="90"><p2>Status</p2></th>
<th width="160"><p2>Ticket Topic</p2></th>
<th width="160"><p2>Client</p2></th>
</tr>
</thead>
<tbody>
<?php include 'missing.query.on.other.script.php';
while ($row = mysql_fetch_array($whatever_resource)){
?>
<tr> <?php
echo "<td><a href='?page=ticket&id=".$row[id]."'</a>#".$row[id]."</td>";
echo "<td>".$row[status]."</td>";
echo "<td>".$row[naslov]."</td>";
$userr = mysql_query('SELECT * FROM client WHERE clientid='.$row["user_id"].'');
$useri = mysql_fetch_array($userr);
echo "<td><a href='clientsummary.php?id=".$row[user_id]."'</a>".$useri['firstname']." ".$useri['lastname']."</td>";
?>
</tr>
<?php } // end while ?>
</tbody>
</table>
I am trying to display my mysql rows to html bootstrap table. Database connection is working, displaying data is working, but it is not fancy as i want. I'd like to maybe save in arrayData maybe and then print this arrayData in html tag. Please any suggestions much appreciated. I want to do this easiest way and most convenient for editing later on. php code to display data :
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["name"]. " " . $row["lastName"]. "<br>"; /* and so on..*/
}
} else {
echo "0 results";
}
and this is my html code for bootstrap
<table class="table table-striped">
<div class="table responsive">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Last Name</th>
<th>Number</th>
<th>Info</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">1</th>
<td>ales</td>
<td>king</td>
<td></td>
<td></td>
</tr>
<tr>
<th scope="row">2</th>
<td>love</td>
<td>2</td>
<td>code</td>
<td></td>
</tr>
</tbody>
</div>
</table>
EDIT: i want this, but loaded from database not manually typed :)!
You can use a php loop this way
<table class="table table-striped">
<div class="table responsive">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Last Name</th>
<th>Number</th>
<th>Info</th>
</tr>
</thead>
<tbody>
<?php
....
if ($result->num_rows > 0) {
// output data of each row
while($row = $result->fetch_assoc()) {
echo '<tr>
<td scope="row">' . $row["id"]. '</td>
<td>' . $row["name"] .'</td>
<td> '.$row["lastName"] .'</td>
</tr>';
}
} else {
echo "0 results";
}
?>
</tbody>
</div>
</table>
I would do something like this:
( but you should really read some basic PHP )
<?php
echo "<table>";
// table header
echo "<tr><th>id</th><th>Name</th><th>Lastname</th></tr>";
// output data of each row
while($row = $result->fetch_assoc()) {
echo "<tr><td>".$row["id"]."</td><td>".$row["name"]."</td><td>".$row["lastName"]."</td></tr>";
}
// table footer
echo "</table>";
?>
i am exporting data from database (MySQL) in excel sheet. i also want to export images in Excel using PHP.if any demo link is available, please share it here
You have to use one of the followig library to do that.
URLS:
https://github.com/PHPOffice/PHPExcel
https://phpexcel.codeplex.com/
https://code.google.com/p/php-excel/
What you're looking for is PHPExcel.
Here are some examples.
This is how I solved mine. Hope this helps!
public function export_items_to_excel(){
$items = $this->transaction->view_all_items();
$output = '';
$output .= "<table class='table' border='1'>
<thead>
<th style='background-color:#c7c7c7;'>NAME</th>
<th style='background-color:#c7c7c7;'>DESCRIPTION</th>
<th style='background-color:#c7c7c7;'>QUANTITY</th>
<th style='background-color:#c7c7c7;'>WEIGHT (KG)</th>
<th style='background-color:#c7c7c7;'>HS CODE</th>
<th style='background-color:#c7c7c7;'>SERIAL NO.</th>
<th style='background-color:#c7c7c7;'>UNIT VALUE</th>
<th style='background-color:#c7c7c7;'>CURRENCY</th>
<th style='width:220px !important;background-color:#c7c7c7;'>PICTURE</th>
</thead>
<tbody>
";
foreach($items as $item){
$output .= "
<tr>
<td style='text-align:center;'>".$item->item_name."</td>
<td style='text-align:center;'>".$item->item_description."</td>
<td style='text-align:center;'>".$item->item_quantity."</td>
<td style='text-align:center;'>".number_format($item->item_weight, 2)."</td>
<td style='text-align:center;'>".$item->item_hs_code."</td>
<td style='text-align:center;'>".$item->item_serial_number."</td>
<td style='text-align:center;'>".number_format($item->item_unit_value, 2)."</td>
<td style='text-align:center;'>".$item->item_currency."</td>
<td style='text-align:center;width:220px !important;height:220px !important;'><img src='".base_url()."assets/uploads/".$item->item_picture."' style='width:200px !important;height:152px !important;'> </td>
</tr>
";
}
$output .= "</tbody>
</table>
";
header("Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet");
header("Content-Disposition: attachment; filename=items.xls");
header("Cache-Control: max-age=0");
echo $output;
}
What I am trying to do is get it so there is a different hyper link address for each row echoed. Code is below:
echo "<table border='1' cellpadding='10'>";
echo "<tr> <th>Product Name</th> <th>Product Description</th> <th>Product Price</th> <th>Product Image</th> <th>View Product Details</th></tr>";
while($row = mysql_fetch_array( $result )) {
echo "<tr>";
echo '<td>' . $row['Product_Name'] . '</td>';
echo '<td>' . $row['Product_Description'] . '</td>';
echo '<td>' . $row['Product_Price'] . '</td>';
echo '<td>Picture Enlarge</td>';
echo '<td>View Details</td>';
echo "</tr>";
}
echo "</table>";
You can put php variables inline in your echo'ed anchors just as you are doing with the other variables.
Assuming that you're using the id field in your database you can do this:
echo '<td>View Details</td>';
If you echo a php variable (e.g. $row['id']) then it will echo out to HTML (not necessarily text). So as this one is contained in an anchor tag (in the HTML) it echos to the anchor tag and builds the id part. :)
<table border='1' cellpadding='10'>
<tr>
<th>Product Name</th>
<th>Product Description</th>
<th>Product Price</th>
<th>Product Image</th>
<th>View Product Details</th>
</tr>
while($row = mysql_fetch_array( $result )) {
<tr>
<td> <?php echo $row['Product_Name']; ?></td>
<td><?php echo $row['Product_Description']; ?></td>
<td><?php $row['Product_Price']; ?></td>
<td>Picture Enlarge</td>
<td>View Details</td>
</tr>
}
</table>
I would probably go for something like that. This assumes that your table returns a unique id, from something like an auto incremented column.
This doesn't include any escaping so could be vulnerable to exploitation. I would also look into templating. It may help you with your presentation, makes it a little easier to read the mixed html and php.
"<td align=\"center\" valign=\"top\"><<") . "</td>\n"