I have made a page on my website that has a table with information that supposed to displayed whenever a new record is add on my MySQL database here is my code:
<?php
while($r = mysqli_fetch_assoc($queryD))
{
echo "<table width='800' border='0' align='center' style='margin-top: 10px; margin-bottom: 10px; background-color: #FFFFFF;' border-radius: '5px;' cellspacing='0px' cellpadding='2px;'>";
echo "<tbody>";
echo "<tr>";
echo "<td width='93' class='generalFONT' style='border: 1px solid black;'>" . "Name" . "</td>";
echo "<td width='193' class='generalFONT' style='border: 1px solid black;'>" . "Type" . "</td>";
echo "<td width='98' class='generalFONT' style='border: 1px solid black;'>" . "Phone" . "</td>";
echo "<td width='98' class='generalFONT' style='border: 1px solid black;'>" . "Age" . "</td>";
echo "<td width='148' class='generalFONT' style='border: 1px solid black;'>" . "Gender" . "</td>";
echo "<td width='160' class='generalFONT' style='border: 1px solid black;'>" . "Natunality" . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td width='93' class='generalFONT' style='border: 1px solid black;'>" . $r["Name"] . "</td>";
echo "<td width='93' class='generalFONT' style='border: 1px solid black;'>" . $r["Type"] . "</td>";
echo "<td width='93' class='generalFONT' style='border: 1px solid black;'>" . $r["Phone"] . "</td>";
echo "<td width='93' class='generalFONT' style='border: 1px solid black;'>" . $r["Age"] . "</td>";
echo "<td width='93' class='generalFONT' style='border: 1px solid black;'>" . $r["Gender"] . "</td>";
echo "<td width='93' class='generalFONT' style='border: 1px solid black;'>" . $r["Natu"] . "</td>";
echo "</tr>";?>
and here is my query:
$queryD = mysqli_query($con, "SELECT * FROM users");
All the code above is working fine but, my problem here is I want to repeat the table whenever a new user registered on the database. I have multiple record on my database but this code is showing only one table and only the first record. I want to show all the records, each one in a separated table and displaying them by stack them on top of each other. So how can I do that? hope you understand my question. Thank you
Related
I have Created the Program where I am Fetching the Content from a text file from a cpanel server,
In my Table Fields It shows the Date Format in Server format i.e (YYYY/MM/DD) I want it to Display as
(DD/MM/YYYY).
This is My Code
<?php
$data = file_get_contents("file-path.txt");
$arr = explode(";", $data);
echo "<thead>";
echo "<tr style=\"border: 1px solid black;\">";
echo "<th style=\"border: 1px solid black;\">Doctor Name</th>";
echo "<th style=\"border: 1px solid black;\">Leave From (YYYY/MM/DD)</th>";
echo "<th style=\"border: 1px solid black;\">Leave To (YYYY/MM/DD)</th>";
echo '<th style="border: 1px solid black;">Remarks</th>';
echo "</tr>";
echo "</thead>";
echo "<tbody>";
for($value = 0; $value < count($arr)-1; $value=$value+4) {
echo "<tr style=\"border: 1px solid black;\">";
echo "<td style=\"border: 1px solid black;\">".$arr[$value]."</td>";
echo "<td style=\"border: 1px solid black;\">".$arr[$value+1]."</td>";
echo "<td style=\"border: 1px solid black;\">".$arr[$value+2]."</td>";
echo '<td style="border: 1px solid black;">'.$arr[$value+3].'</td>';
echo "</tr>";
}
echo "</tbody>";
echo "</table>";
?>
You should use date_format() function bro
date_format($arr[$value+2],"d/m/Y");
date('d/m/Y', strtotime($arr[$value+2]));
Have a try, you can do it.
I have a php file designed to retrieve information from database. The problem is that if i use a normal table tags like the following it would work and show the page for me.
<?php /*Template Name: contactread */
get_header();
$servername = "localhost";
$username = "***** (for security purpose only)";
$password = "*****";
$dbname = "*****";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$query = "SELECT * FROM contact";
$result = mysqli_query($conn,$query);
echo "<table class='table'>
<tr>
<th class='tda' style='border-bottom: 1px solid #313131; border-top: 1px solid #313131; border-right: 1px solid #313131;'>نام</th>
<th class='tda' style='border-bottom: 1px solid #313131; border-top: 1px solid #313131; border-right: 1px solid #313131;'>ایمیل</th>
<th class='tda' style='border-bottom: 1px solid #313131; border-top: 1px solid #313131; border-right: 1px solid #313131;'>پیام</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td class='tda' style='border-bottom: 1px solid #313131; border-right: 1px solid #313131;'>" . $row['name'] . "</td>";
echo "<td class='tda' style='border-bottom: 1px solid #313131; border-right: 1px solid #313131;'>" . $row['email'] . "</td>";
echo "<td class='tda' style='border-bottom: 1px solid #313131; border-right: 1px solid #313131;'>" . $row['message'] . "</td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
?>
And When i use it like the following which is calling everything from the framework, it gives me the http 500 error. (I included the entire page for showing the first type of table so you have the idea of the page, however i dont see a reason to re write it all again)
echo "<table>
<thead>
<tr>
<th>نام</th>
<th>ایمیل</th>
<th>پیام</th>
</tr>
</thead>
<tbody>";
while($row = mysqli_fetch_array($result))
{
echo <tr>
echo <td>. $row['name'] .</td>
echo <td>. $row['email'] .</td>
echo <td>. $row['message'] .</td>
echo </tr>
}
echo "</tbody>
</table>";
Can someone help me why is this making the error? I couldnt find anything helpful in the internet.
EDIT: I have added materialize-css css files with the link in the header and i have included the header as well.
Simple mistake. You are not wrapping the data you want to echo in quotes, so try doing it like this.
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>$row[name]</td>";
echo "<td>$row[email]</td>";
echo "<td>$row[message]</td>";
echo "</tr>";
}
I have made a page on my website that has a table with information displayed whenever a new record is add on my MySQL database here is my code:
<?php
while($r = mysqli_fetch_assoc($queryD))
{
echo "<table width='800' border='0' align='center' style='margin-top: 10px; margin-bottom: 10px; background-color: #FFFFFF;' border-radius: '5px;' cellspacing='0px' cellpadding='2px;'>";
echo "<tbody>";
echo "<tr>";
echo "<td width='93' class='generalFONT' style='border: 1px solid black;'>" . "Name" . "</td>";
echo "<td width='193' class='generalFONT' style='border: 1px solid black;'>" . "Type" . "</td>";
echo "<td width='98' class='generalFONT' style='border: 1px solid black;'>" . "Phone" . "</td>";
echo "<td width='98' class='generalFONT' style='border: 1px solid black;'>" . "Age" . "</td>";
echo "<td width='148' class='generalFONT' style='border: 1px solid black;'>" . "Gender" . "</td>";
echo "<td width='160' class='generalFONT' style='border: 1px solid black;'>" . "Natunality" . "</td>";
echo "</tr>";
echo "<tr>";
echo "<td width='93' class='generalFONT' style='border: 1px solid black;'>" . $r["Name"] . "</td>";
echo "<td width='93' class='generalFONT' style='border: 1px solid black;'>" . $r["Type"] . "</td>";
echo "<td width='93' class='generalFONT' style='border: 1px solid black;'>" . $r["Phone"] . "</td>";
echo "<td width='93' class='generalFONT' style='border: 1px solid black;'>" . $r["Age"] . "</td>";
echo "<td width='93' class='generalFONT' style='border: 1px solid black;'>" . $r["Gender"] . "</td>";
echo "<td width='93' class='generalFONT' style='border: 1px solid black;'>" . $r["Natu"] . "</td>";
echo "</tr>";
and here is my query:
$queryD = mysqli_query($con, "SELECT * FROM users");
All the code above is working fine but, my problem here is I want to repeat the table whenever a new user registered on the database. I have multiple record on my database but this code is showing only one table and only the first record. I want to show all the records, each one in a separated table. So how can I do that? hope you understand my question. Thank you
try working with foreach
http://php.net/manual/en/control-structures.foreach.php
this is a example of php.net
$arr = array(1, 2, 3, 4);
foreach ($arr as &$value) {
$value = $value * 2;
}
// $arr is now array(2, 4, 6, 8)
Is there a way to wrap the text within the database?
I have a address being added into the database under the address column, but whenever I try to output the database through PHP it shows that the address column is seriously long which goes all the way out of the range of the paper size. Is there a method I could wrap these text into a specific amount of letters and have it line break on the output file or within the database?
edit: updated question with code
CODE:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>UGGL PEUI Customer Dividend - 12-01-2014</title>
<style type="text/css">
body,td,th {
font-family: Lato, Calibri, Arial, sans-serif;
font-style: normal;
font-weight: normal;
font-size: 12px;
}
body {
background: #C28E33;
color: #E6FFF2;
}
table{
border: 0px solid black;
border-spacing: 0px;
}
table thead tr{
font-family: Arial, monospace;
font-size: 14px;
}
table thead tr th{
border-bottom: 2px solid black;
border-top: 1px solid black;
margin: 0px;
padding: 2px;
background-color: #cccccc;
font-weight:bold
}
table tr {
font-family: arial, monospace;
color: black;
font-size:12px;
background-color: white;
}
table tr.odd {
background-color: #AAAAAA;
}
table tr td, th{
border-bottom: 1px solid black;
padding: 2px;
}
a:link{
font-family:arial, monospace;
text-decoration: none;
color: teal;
}
a:hover{
text-decoration: underline;
}
a:visited{
color:black;
text-decoration: none;
}
</style>
</head>
<body>
<?php
// HTML Table Output
echo
"<table border='1'>
<thead>
<tr>
<th>ID</th>
<th>Purchase Date</th>
<th>Mature Date</th>
<th>Amount</th>
<th>Beneficiary First Name</th>
<th>Beneficiary Last Name</th>
<th>Beneficiary ID</th>
<th>Beneficiary Contact No.</th>
<th>Beneficiary Address</th>
<th>Bank Account Name</th>
<th>Bank Account No.</th>
<th>Bank Swift Code</th>
<th>Bank Name</th>
<th>Bank Address</th>
<th>Bank Contact No.</th>
<th>Agent Name</th>
<th>Dec. 1, 2014 (Days)</th>
<th>Dec. 1, 2014 (Dividend)</th>
</thead>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['purchase_date'] . "</td>";
echo "<td>" . $row['mature_date'] . "</td>";
echo "<td>" . $row['unit'] . "</td>";
echo "<td>" . $row['beneficiary_first'] . "</td>";
echo "<td>" . $row['beneficiary_last'] . "</td>";
echo "<td>" . $row['beneficiary_id'] . "</td>";
echo "<td>" . $row['beneficiary_no'] . "</td>";
echo "<td>" . $row['beneficiary_add'] . "</td>";
echo "<td>" . $row['bank_acc_name'] . "</td>";
echo "<td>" . $row['bank_acc_no'] . "</td>";
echo "<td>" . $row['bank_swift'] . "</td>";
echo "<td>" . $row['bank_name'] . "</td>";
echo "<td>" . $row['bank_add'] . "</td>";
echo "<td>" . $row['bank_no'] . "</td>";
echo "<td>" . $row['agent'] . "</td>";
echo "<td>" . $row['first_days'] . "</td>";
echo "<td bgcolor=#E6FFF2><b>" . $row['first_payment'] . "</b></td>";
echo "</tr>";
}
echo "</table>";
// Close MySQL
mysqli_close($con);
?>
</body>
</html>
You can use two CSS properties:
<style>
.your-element{
word-wrap:break-word;
word-break:break-all;
}
</style>
Demo
References:
Word Wrap
Word Break
I am taking data from database and put it in html table that html table looks fine but when i press the send button for email send some times the html table is not aligned in email,it looks like below the date is not align in the specific coloumn
also like this
i don't why it showing "!". can any one guide why this happens,thanks
my code:
$text_mail.= "<table style='border:1px solid black;border-collapse:collapse;'>
<tr >
<th style='border:1px solid black; width:130px; padding:0 0 0 5px'>Country</th>
<th style='border:1px solid black; width:130px; padding:0 0 0 5px'>Network Name </th>
<th style='border:1px solid black; width:50px; padding:0 0 0 5px'>MCC</th>
<th style='border:1px solid black; width:50px; padding:0 0 0 5px'>MNC</th>
<th style='border:1px solid black; width:130px; padding:0 0 0 5px'>Old Price (Euro)</th>
<th style='border:1px solid black; width:130px; padding:0 0 0 5px'>New Price (Euro)</th>
<th style='border:1px solid black; width:130px; padding:0 0 0 5px'>Change</th>
<th style='border:1px solid black; width:130px; padding:0 0 0 5px'>Valid From (DD.MM.YYYY) </th>
</tr>";
while($row = mysql_fetch_array($queryRes))
{
if($row['pricefrom']==0){
$pricefrom="NA";
$change="New Network";
}else{
$pricefrom= $row['pricefrom'];
$change= $row['statusto'];
}
if($row['priceto']==0){
$priceto="NA";
$change="Not Covered";
}else{
$priceto= $row['priceto'];
$change= $row['statusto'];
}
$text_mail.= "<tr>";
$text_mail.= "<td style='border:1px solid black; width:130px; padding:0 0 0 5px;'><span></span><span></span><span></span><span></span>" . $row['country'] . "</td>";
$text_mail.= "<td style='border:1px solid black; width:130px; padding:0 0 0 5px;'><span></span><span></span><span></span><span></span>" . $row['networkname'] . "</td>";
$text_mail.= "<td style='border:1px solid black; width:50px; padding:0 0 0 5px;'><span></span><span></span><span></span><span></span>" . $row['mcc'] . "</td>";
$text_mail.= "<td style='border:1px solid black; width:50px; padding:0 0 0 5px;'><span></span><span></span><span></span><span></span>" . $row['mnc'] . "</td>";
$text_mail.= "<td style='border:1px solid black; width:130px; padding:0 0 0 5px;'><span></span><span></span><span></span><span></span>" . $pricefrom . "</td>";
$text_mail.= "<td style='border:1px solid black; width:130px; padding:0 0 0 5px;'><span></span><span></span><span></span><span></span>" . $priceto . "</td>";
$text_mail.= "<td style='border:1px solid black; width:130px; padding:0 0 0 5px;'><span></span><span></span><span></span><span></span>" . $change . "</td>";
$text_mail.= "<td style='border:1px solid black; width:130px; padding:0 0 0 5px;'><span></span><span></span><span></span><span></span>" .date('d.m.Y', $row['datetime']) . "</td>";
$text_mail.= "</tr>";
}
$text_mail.= "</table> <br><br>";
You should try like this:
$text_mail.= "<tr>
<td style='border:1px solid black; width:130px; padding:0 0 0 5px;'><span></span><span></span><span></span><span></span>" . $row['country'] . "</td>
<td style='border:1px solid black; width:130px; padding:0 0 0 5px;'><span></span><span></span><span></span><span></span>" . $row['networkname'] . "</td>
<td style='border:1px solid black; width:50px; padding:0 0 0 5px;'><span></span><span></span><span></span><span></span>" . $row['mcc'] . "</td>
<td style='border:1px solid black; width:50px; padding:0 0 0 5px;'><span></span><span></span><span></span><span></span>" . $row['mnc'] . "</td>
<td style='border:1px solid black; width:130px; padding:0 0 0 5px;'><span></span><span></span><span></span><span></span>" . $pricefrom . "</td>
<td style='border:1px solid black; width:130px; padding:0 0 0 5px;'><span></span><span></span><span></span><span></span>" . $priceto . "</td>
<td style='border:1px solid black; width:130px; padding:0 0 0 5px;'><span></span><span></span><span></span><span></span>" . $change . "</td>
<td style='border:1px solid black; width:130px; padding:0 0 0 5px;'><span></span><span></span><span></span><span></span>" .date('d.m.Y', $row['datetime']) . "</td>
</tr>";