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.
Related
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 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
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)
If any any one of them are blank then show error message. But it is not working.I mean, if I any one between input and option remain empty then the error will show. One of them must be selected.
Here is .
<?php include "head.htm";?>
<br>
<br>
<body bgcolor="#FEF5E7">
<title>Search Profile</title>
<form method="post" action="search.php">
<input type="text" placeholder="Enter Student's ID/Name" name="query" />
<select name="BRANCH">
<option value="">Select</option>
<option value="Banani">Banani</option>
<option value="RayerBazar">RayerBazar</option>
</select>
<input type="submit" value="Find" name="completedsearch" />
</form>
<?php
if(isset($_POST['completedsearch']))
{
$term = $_POST['query'];
$term1 = $_POST['BRANCH'];
$mysql = mysql_connect("localhost","password","null");
mysql_select_db("mydb");
$qu = mysql_query("SELECT * FROM `stu` WHERE STUDENTID LIKE '%{$term}%' OR STUDENTID LIKE '%{$term}%' OR BRANCH LIKE '%{$term1}%' OR STUDENTID LIKE '%{$term}%' "); //selects the row that contains ANYTHING like the submitted string
$qu1 = mysql_query("SELECT * FROM `stu` WHERE BRANCH LIKE '%{$term1}%' ");
if ($term == "" || $term1 == "") {
// no results
echo '<a style="color:red;font-size: 30px;">Please Put Name OR ID Here</a><br><body background="ghost.gif" style="background-repeat:no-repeat;background-size: cover">';
} else {
echo "<table style='width:100%'>
<th style='width:10%;font-size:20px;border: 2px solid red; '>Info ID</th>
<th style='width:20%;font-size:20px;border: 2px solid red; '>School ID</th>
<th style='width:20%;font-size:20px;border: 2px solid red; '>Name</th>
<th style='width:10%;font-size:20px;border: 2px solid red; '>Class</th>
<th style='width:10%;font-size:20px;border: 2px solid red; '>Shift</th>
<th style='width:10%;font-size:20px;border: 2px solid red; '>Branch</th>
<th style='width:20%;font-size:20px;border: 2px solid red; '>Search</th>
";
while($row = mysql_fetch_array($qu))
{
echo "<tr><td style='width:10%;font-size:15px;border: 2px solid blue;'><p style='text-slign: center;font-family: cursive;text-align: center'>";
echo $row['id'];
echo "</p></td>";
echo "<td style='width:20%;font-size:15px;border: 2px solid blue;'><p style='text-slign: center;font-family: cursive;text-align: center'>";
echo $row['STUDENTID'];
echo "</p></td>";
echo "<td style='width:20%;font-size:15px;border: 2px solid blue;'><p style='text-slign: center;font-family: cursive;text-align: center'>";
echo $row['STUDENTNAME'];
echo "</p></td>";
echo "<td style='width:10%;font-size:15px;border: 2px solid blue;'><p style='text-slign: center;font-family: cursive;text-align: center'>";
echo $row['CLASS'];
echo "</p></td>";
echo "<td style='width:10%;font-size:15px;border: 2px solid blue;'><p style='text-slign: center;font-family: cursive;text-align: center'>";
echo $row['SHIFT'];
echo "</p></td>";
echo "<td style='width:10%;font-size:15px;border: 2px solid blue;'><p style='text-slign: center;font-family: cursive;text-align: center'>";
echo $row['BRANCH'];
echo "</p></td>";
echo " <td style='width:20%;font-size:15px;border: 2px solid blue;'><p style='text-slign: center;font-family: cursive;text-align: center'><a href='id.php?id=";
echo $row['id'];
echo "'>Visit This Profile</a></p></td>";
}
while($row = mysql_fetch_array($qu1))
{
echo "<tr><td style='width:10%;font-size:15px;border: 2px solid blue;'><p style='text-slign: center;font-family: cursive;text-align: center'>";
echo $row['id'];
echo "</p></td>";
echo "<td style='width:20%;font-size:15px;border: 2px solid blue;'><p style='text-slign: center;font-family: cursive;text-align: center'>";
echo $row['STUDENTID'];
echo "</p></td>";
echo "<td style='width:20%;font-size:15px;border: 2px solid blue;'><p style='text-slign: center;font-family: cursive;text-align: center'>";
echo $row['STUDENTNAME'];
echo "</p></td>";
echo "<td style='width:10%;font-size:15px;border: 2px solid blue;'><p style='text-slign: center;font-family: cursive;text-align: center'>";
echo $row['CLASS'];
echo "</p></td>";
echo "<td style='width:10%;font-size:15px;border: 2px solid blue;'><p style='text-slign: center;font-family: cursive;text-align: center'>";
echo $row['SHIFT'];
echo "</p></td>";
echo "<td style='width:10%;font-size:15px;border: 2px solid blue;'><p style='text-slign: center;font-family: cursive;text-align: center'>";
echo $row['BRANCH'];
echo "</p></td>";
echo " <td style='width:20%;font-size:15px;border: 2px solid blue;'><p style='text-slign: center;font-family: cursive;text-align: center'><a href='id.php?id=";
echo $row['id'];
echo "'>Visit This Profile</a></p></td>";
}
}
}
?>
</tr>
</table>
if(isset($_POST['completedsearch'])){
if(empty($_POST['query']) || empty($_POST['BRANCH'])) {
echo "Show your error!";
}else {
//execute your code.
}
}
As you ask that if any one between input and option remain empty then the error will show than use
if(!empty($_POST['query']) || !empty($_POST['BRANCH']) ) {
// one of them or both select
} else {
die("please select one of them ")
}
http://php.net/manual/en/function.empty.php
Please prefer to use PDO or mysqli instead of this msql
if you want show error on first page instead of search.php than use Ajax
as you said than try this
if(empty($_POST['query']) && empty($_POST['BRANCH'])) {
die ("Please select any one or both")
} else if (!empty($_POST['query']) && !empty($_POST['BRANCH']) {
// it mean user selected both than try to write your query whith And
// SELECT * FROM `table` WHERE `student_id` LIKE '%$id%' AND `BRANCH` LIKE `$branch`
} else if (!empty($_POST['query'])) {
// user only write in text box
//SELECT * FROM `table` WHERE `student_id` LIKE '%$id%'
} else {
//user choose select option
//SELECT * FROM `table` WHERE `BRANCH` LIKE `%$branch%`
}
I have a database that is out putting a specific row. My code does that but I want a dashed border around it for my table. The code below should make a dashed line around this row but I don't know why it not working. Can someone help?
$count = 1
echo "<table>";
echo "<tr> <th>Pos</th> <th>Team</th> <th>PLD</th> <th>W</th> <th>D</th>
<th>L</th> <th>F</th> <th>A</th> <th>GD</th> <th>PTS</th> </tr>";
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array( $result )) {
if($count == 5) {
echo "<tr style='border-style:dashed'><td>";
echo $row['Pos'];
echo "</td><td>";
echo $row['Team'];
echo "</td><td>";
echo $row['PLD'];
echo "</td><td>";
echo $row['W'];
echo "</td><td>";
echo $row['D'];
echo "</td><td>";
echo $row['L'];
echo "</td><td>";
echo $row['F'];
echo "</td><td>";
echo $row['A'];
echo "</td><td>";
echo $row['GD'];
echo "</td><td>";
echo $row['PTS'];
echo "</td></tr>";
}
else {
echo "<tr><td>";
}
Direct styling of is not allowed.
You should put the border on the elements and use border-right and border-left to remove the border in between columns.
<tr>
<td style="border: 1px dashed black; border-right: none">Left</td>
<td style="border: 1px dashed black; border-left: none; border-right: none">Middle</td>
<td style="border: 1px dashed black; border-left: none; border-right: none">Middle</td>
<td style="border: 1px dashed black; border-left: none">Right</td>
</tr>
You really should use html classes and a CSS file though.