php table isn't complete - php

i have table created inside php with css but the table isn't complete as you see in the photo from the download part. its coming half in the download part.
please someone look to my code and let me know where i gone wrong.
thank you.
my css code
<style type='text/css'>
.container3 {
float:left;
width:100%;
/*background:green;*/
overflow:hidden;
position:relative;
}
.container2 {
float:left;
width:100%;
background:#FFA500;
position:relative;
right:45%;
}
.container1 {
float:left;
width:100%;
/*background:red;*/
position:relative;
right:40%;
}
.col1 {
float:left;
width:26%;
position:relative;
left:87%;
bottom:-200px;
font-size:20px;
text-align:left;
overflow:hidden;
height:570px;
}
.col2 {
float:left;
width:50%;
position:relative;
left:90%;
overflow:hidden;
}
.col3 {
float:left;
width:26%;
position:relative;
left:80%;
overflow:hidden;
}
.footer {
border:1px solid orange;
position: relative;
padding:0px;
margin-top:-5px;
font-size:15px;
}
.signout {
position: absolute;
left: 5px;
bottom: 150px;
width: 130px;
clear: both;
font-size:20px;
text-align:center;
}
.tableClass{
margin-bottom:60px;
}
</style>
<style>
table
{
border-collapse:collapse;
}
table, td, th
{
border:1px solid black;
}
</style>
<style>
table,td,th
{
border:1px solid black;
}
td
{
text-align:center;
}
</style>
<style>
table,td,th
{
border:1px solid black;
}
table
{
width:100%;
}
th
{
height:50px%;
}
</style>
my php code
<div id="header" style="background-color:#FFA500;">
<h1 style="margin-bottom:0;">Wellcome To Balhaf Services Customer Reports</h1>
<div class="container3 ">
<div class="container1 ">
<div class="container2 ">
<div class="col1">
View Report <br />
View Chart <br />
</div>
<?php
$username = $_POST["username"];
$password = $_POST["password"];
// Connect to the database
$dbLink = new mysqli('localhost', 'sqldata', 'sqldata', 'balhaf');
if(mysqli_connect_errno()) {
die("MySQL connection failed: ". mysqli_connect_error());
}
//for mysql injection (security reasons)
$username = mysqli_real_escape_string($dbLink, $username);
$password = mysqli_real_escape_string($dbLink, $password);
mysqli_select_db($dbLink,"balhaf2");
//checking if such data exist in our database and display result
$login = mysqli_query ($dbLink,"select * from users where USERNAME = '$username' and
PASSWORD = '$password'");
if(mysqli_num_rows($login) == 1) {
// Fetch the file information
$query = "select * from users WHERE username = '".$dbLink->escape_string($username)."'";
$result = $dbLink->query($query);
$company = false;
//Now get the result information
$row = $result->fetch_object(); //will store the record in $row
//Access what you need
if($row) {
$company = $row->company; //variable name should match the field name in your database
echo $company; //See if you get the value stored in the database
}
mysqli_select_db($dbLink,"balhaf");
// Query for a list of all existing files
$sql = "SELECT id, name, mime, size, created FROM $company";
$result = $dbLink->query($sql);
// Check if it was successfull
if($result) {
// Make sure there are some files in there
if($result->num_rows == 0) {
echo '<p>There are no files in the database</p>';
}
else {
// Print the top of a table
echo '<div class="col2">';
echo '<div align="center">';
echo '<H2 align="center"> Report Table</H></div>';
echo '<table border="1" align="center"class="tableClass">
<tr>
<td><b>Name</b></td>
<td><b>Mime</b></td>
<td><b>Size (bytes)</b></td>
<td><b>Created</b></td>
<td><b>Download</b></td>
</tr>';
// Print each file
while($row = $result->fetch_assoc()) {
echo "
<tr>
<td>{$row['name']}</td>
<td>{$row['mime']}</td>
<td>{$row['size']}</td>
<td>{$row['created']}</td>
<td><a style='text-decoration:none;'href=' get_file_work.php?id={$row['id']}&company=$company'>Download</a></td>
</tr>";
}
// Close table
echo '</table>';
echo '</div>';
}
// Free the result
$result->free();
}
else
{
echo 'Error! SQL query failed:';
echo "<pre>{$dbLink->error}</pre>";
}
// Close the mysql connection
$dbLink->close();
}
else {
echo "worng user"."</br>";
}
?>
<div class="col3">
</div>
</div>
</div>
<div class="signout">
<a style='text-decoration:none;' href= "index.html">Sign Out </br></a>
</div>
<div class="footer" style="background-color:#FFA500;clear:both;text-align:center;">
Copyright balhaf services 20103-2014</div>
</div>

Your container3 is cutting off the display of it's contents with "overflow:hidden;"
You could switch it to:
.container3 {
float:left;
width:100%;
/*background:green;*/
overflow:auto;
position:relative;
}
Or if you don't want to bleed off the edge you could either replace the filename with a download link, something like "view document". Or you could limit the number of characters allowed to show in the table cell. OR you could look into the word-break property (not reliable across all browsers) - see the link below for documentation.
W3Schools - Word-break

Related

PHP/HTML: How I could change my image source depending on the value from the database

I have HTML in my PHP file, because I'm using data from a database to display on my website. (This is my first time using PHP so my knowledge is really little)
My question is how I could change my image source depending on the value from the database.
The depending value I'm talking about is called = SENT_NUMBER_1
<?php
//This line will make the page auto-refresh each 15 seconds
$page = $_SERVER['PHP_SELF'];
$sec = "15";?>
<html>
<head>
<style>
div.image{
transform: rotate(90deg);
width:100px;
height:200px;
background: transparent;
position: absolute;
top:30%;
bottom: 0;
left: 0;
right: 0;
margin: auto;
content:url(photo) // This is the url I'm wanting to change into either: Empty.png / 25.png / 50.png / 75.png /100.png || like = content:url(/50.png)
}
</style>
<div class="image"></div>
i also have something like this but I don't know if this works, and where to put it.
if(SENT_NUMBER_1 <= 10){
photo = "10.png"
}
elseif(SENT_NUMBER_1 >= 11 && <=25){
photo = "25.png"
}
elseif(SENT_NUMBER_1 >= 26 && <=49){
photo = "50.png"
}
elseif(SENT_NUMBER_1 >= 50 && <=74){
photo = "75.png"
}
elseif(SENT_NUMBER_1 >= 75 && <=100){
photo = "100.png"
}
Here is a screenshot from the [website], the image I'm wanting to change is the battery you see on the screenshot.
Whole code for if I missed something
<?php
//This line will make the page auto-refresh each 15 seconds
$page = $_SERVER['PHP_SELF'];
$sec = "15";
?>
<html>
<head>
<link rel="shortcut icon" href="/favicon-16x16.ico" type="image/x-icon">
<title>Rattengifmelder</title>
<style>
#font-face {
font-family: Asket Extended; src: url('AsketExtended-Light.otf');
font-family: Asket Extended; font-weight: bold; src: url('AsketExtended-Light.otf');
}
body{
height: 200vh;
}
tbody{
text-align: center;
}
td{
background-color: transparent;
width: 70px;
height: 70px;
}
table, th, td{
font-size: 30px;
width: 100px;
margin-left: auto;
margin-right: auto;
background: transparent;
border: 10px solid white;
font-family: 'Asket Extended', sans-serif;
}
div.image{
transform: rotate(90deg);
width:100px;
height:200px;
background: transparent;
position: absolute;
top:30%;
bottom: 0;
left: 0;
right: 0;
margin: auto;
content:url(/100.png)
}
div.image2{
width:100px;
height:200px;
background: transparent;
content:url(/Empty.png)
}
div.image3{
width:100px;
height:200px;
background: transparent;
content:url(/Empty.png)
}
.center{
position: sticky;
top: 0px;
text-align: center;
font-family: 'Asket Extended', sans-serif;
font-size: 50px;
font-weight: bold;
padding-top: 50px;
background-color: white;
}
.footer {
position: fixed;
left: 0;
bottom: 0;
height: 10%;
width: 100%;
background-color: white;
color: white;
text-align: center;
border-top: 1px solid lightgrey ;
}
div.container {
float: left;
margin: 100px;
padding: 20px;
width: 100px;
}
.menu{
position: absolute;
left: 70px;
top: 65px;
width:20px;
height:20px;
content:url(/menu.png)
}
.battery{
position: absolute;
left: 93%;
top: 50px;
width: 30px;
height:60px;
transform: rotate(90deg);
content:url(/100.png)
}
.one{
}
.two{
}
.three{
}
</style>
<!--//I've used bootstrap for the tables, so I inport the CSS files for taht as well...-->
<meta http-equiv="refresh" content="<?php echo $sec?>;URL='<?php echo $page?>'">
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css">
<!-- jQuery library -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Latest compiled JavaScript -->
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script>
</head>
<body>
<?php
include("database_connect.php"); //We include the database_connect.php which has the data for the connection to the database
// Check the connection
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
//Again, we grab the table out of the database, name is ESPtable2 in this case
$result = mysqli_query($con,"SELECT * FROM ESPtable2");//table select
//Now we create the table with all the values from the database
//loop through the table and print the data into the table
while($row = mysqli_fetch_array($result)) {
$column1 = "RECEIVED_BOOL1";
$column2 = "RECEIVED_BOOL2";
$column3 = "RECEIVED_BOOL3";
$column4 = "RECEIVED_BOOL4";
$column5 = "RECEIVED_BOOL5";
}
?>
<div class="center">
<div class="menu"></div>
<div class="battery"></div>
<p>Rattengifmelder</p>
</div>
<?php
include("database_connect.php");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM ESPtable2");//table select
echo "<table>
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
<tr class='active'>
<td style='color: grey;'>Grasveld achter</td>
</tr>
";
while($row = mysqli_fetch_array($result)) {
$cur_sent_bool_1 = $row['SENT_BOOL_1'];
$cur_sent_bool_2 = $row['SENT_BOOL_2'];
$cur_sent_bool_3 = $row['SENT_BOOL_3'];
if($cur_sent_bool_1 == 1){
$label_sent_bool_1 = "label-success";
$text_sent_bool_1 = "Actief";
}
else{
$label_sent_bool_1 = "label-danger";
$text_sent_bool_1 = "Inactief";
}
/*echo "<tr class='info'>";
$unit_id = $row['id'];
echo "<td>" . $row['id'] . "</td>"; */
echo "<td>
<span class='label $label_sent_bool_1'>"
. $text_sent_bool_1 . "</td>
</span>";
}
echo "</table>";
?>
<?php
include("database_connect.php");
if (mysqli_connect_errno()) {
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
$result = mysqli_query($con,"SELECT * FROM ESPtable2");//table select
echo "<table>
<thead>
<tr>
<th></th>
</tr>
</thead>
<tbody>
<tr class='active'>
</tr>
";
while($row = mysqli_fetch_array($result)) {
echo "<tr class='info'>";
echo "<td style='background-color: transparent;'>" . $row['SENT_NUMBER_1'] . "% </td>";
echo "</tr></tbody>";
}
echo "</table>
<br>
";
?>
<div class="footer">
<p></p>
</div>
<div class="image"></div> // this is where the image is displayed
I didn't get where you are getting value of SENT_NUMBER_1 in your php code ??
then
SENT_NUMBER_1 should be $SENT_NUMBER_1
photo should be $photo
if($SENT_NUMBER_1 <= 10){
$photo = "10.png";
}
if($SENT_NUMBER_1 >= 11 && $SENT_NUMBER_1 <=25){
$photo = "25.png";
}
if($SENT_NUMBER_1 >= 26 && $SENT_NUMBER_1 <=49){
$photo = "50.png";
}
if($SENT_NUMBER_1 >= 50 && $SENT_NUMBER_1 <=74){
$photo = "75.png";
}
if($SENT_NUMBER_1 >= 75 && $SENT_NUMBER_1 <=100){
$photo = "100.png";
}
and then
<div class="image"><img src="<?php echo $photo;?>"></div> // this is where the image is displayed
also declare full path of image.
e.g.
$photo = 'imagefolder/100.png';

PHP MySQL display data with table rows (clickable)

I have tables that are the publish date of a article and a columns article summary, and those are clickable and should go to a edit page when you click on this. The article should be filled in when you click on it, so you can easy edit the text. I have make the table rows linked but I think I need to take the ID from the tables so it knows what the edit page should be filled in with.
Here is my current code:
<?php
include 'index.php';
include 'login2.php';
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="alleartikelen.css">
</head>
<body>
<h2> Widget news admin </h2>
<!-- Echo username -->
<?php
$user = $_SESSION['user'];
echo "<p>You are logged in as <b>$user</b>.</p>";
?>
<a class="logout" href="index.php">Log out </a>
<hr>
<h1> All Articles </h1>
<?php
$sql = "SELECT art_date, art_head FROM article";
$result = $conn->query($sql); //it makes the query
?>
<style>
.table td {
font-family: Merriweather, serif;
font-size: 16px;
padding: 10px 5px;
overflow: hidden;
word-break: normal;
}
.table th:first-child,
.table td:first-child {
width: 14%;
height: 10%;
}
td,th{
font-family: "Calibri ";
}
tr:nth-child(even){
background-color: #ddd;
}
tr:hover {
background-color: #F6F6F6;
}
th{
color:white;
}
.aa {
text-decoration: none;
color: inherit;
}
</style>
<section>
<div class="container">
<table class="table">
<tr>
<th>Publication date</th>
<th>Article</th>
</tr>
<?php
$res=$result->fetch_all(MYSQL_ASSOC); //Splitting all rows in arrays
$keys = array_keys($res[0]); //Arrays getting attached to $keys
// Make the results as rows
echo "<tbody>";
foreach($res as $rows)
{
echo "<tr>";
foreach($rows as $date)
{
echo "<td><a href='bewerkartikel.php'class ='aa'>$date</a>";
echo "</td>";
}
echo "</tr>";
}
echo "</tr>";
}
?>
</section>
</body>
</html>
Add article id to your link ?art_id=some_id
<?php
include 'index.php';
include 'login2.php';
?>
<html>
<head>
<link rel="stylesheet" type="text/css" href="alleartikelen.css">
<style>
.table td {
font-family: Merriweather, serif;
font-size: 16px;
padding: 10px 5px;
overflow: hidden;
word-break: normal;
}
.table th:first-child,
.table td:first-child {
width: 14%;
height: 10%;
}
td,th {
font-family: "Calibri ";
}
tr:nth-child(even){
background-color: #ddd;
}
tr:hover {
background-color: #F6F6F6;
}
th {
color:white;
}
.aa {
text-decoration: none;
color: inherit;
}
</style>
</head>
<body>
<h2> Widget news admin </h2>
<!-- Echo username -->
<?php
$user = $_SESSION['user'];
echo "<p>You are logged in as <b>$user</b>.</p>";
?>
<a class="logout" href="index.php">Log out </a>
<hr>
<h1> All Articles </h1>
<?php
$sql = "SELECT art_date, art_head, art_id FROM article"; //get article id too
$result = $conn->query($sql); //it makes the query
?>
<section>
<div class="container">
<table class="table">
<tr>
<th>Publication date</th>
<th>Article</th>
</tr>
<?php
echo "<tbody>";
while($rows = $result->fetch_assoc()) {
echo "<tr>";
echo "<td>". $rows['art_date'] . "</td>";
echo "<td><a href='bewerkartikel.php?art_id=" . $rows['id'] . "' class ='aa'> " . $rows['art_head'] . "</a>";
echo "</td>";
echo "</tr>";
}
echo "</tr>";
?>
</section>
</body>
</html>
Screenshot
You need to pass the id to next page so what you need to do is add a id to url
like below
"<td><a href='bewerkartikel.php?id=".$date['id']." ' class='aa' >$date</a></td>";
and get the id on bewerkartikel page using
$id = $_GET['id'];
and then you get the particular id to edit.

How can i make background auto adjust after text lenght?

I want to make a warning message apear on my index if the website will be unavailable or for some other reason i need to display important information.
This is my CSS:
.warning-container {
margin:0 auto;
width:50%;
height:60px;
border:2px solid rgba(207,35,35, 0.5);
border-radius:7px;
background-color:rgba(255,61,61,0.3) !important;
padding:10px;}
.warning-icon {
width:60px;
float:left;}
.warning-h1 {
font-size:13px;
color:#c91b1b !important;
font-weight:bold;
float:left !important;}
.warning-message {
font-size:12px;
color:#e31a1a !important;
float:left;}
It will display a red background with a warning icon aswell as a title for the warning and the text.
The php is not 100% yet but this is what i got.
<center>
<?php
$conn = mysqli_connect("localhost", "root", "pass", "table");
$sql = "SELECT * FROM warning";
$result = $conn->query($sql);
//if(!empty("warning")){
// echo"";
//}else{
echo"<div class='warning-container'>";
echo "<img class='warning-icon' src='/warning-icon.png'>";
echo "<div class='warning-h1'>Warning:</div>";
echo "<div class='warning-message'>";
echo "<br/><br/>";
echo "
Warning message goes here!
";
echo"</div>";
echo"</div>";
//}
?>
</center>

Unable to add link in for loop

I am tryig to make a photo gallery on my website. I have a small problem with making link on images I have in for loop
Since You requested full code here it is:
<html>
<head>
<meta charset="UTF-8">
<title>Fotečky</title>
<style>
.foto{
position: relative;
display: inline-block;
text-align: center;
width: 200px;
border: solid;
margin-left: 6%;
}
#date{
position: relative;
text-align: center;
width: 200px;
}
a { color: #000000; text-decoration: none; }
.menu {
background-color: #FF9933;
height: 10%;
line-height: 300%;
}
</style>
</head>
<body>
<div class="menu">
<center><h2>Upload photo</h2></center>
</div>
<br>
<?php
mb_internal_encoding("UTF-8");
$connect = mysql_connect("","","") or die("Couldn't connect");
mysql_set_charset('utf8',$connect);
mysql_select_db("") or die("Couldn't find db");
$SQLCommand = "SELECT * FROM foto";
$result1 = mysql_query($SQLCommand); $database = array(); $index = 1; // make a new array to hold all your data
while($row1 = mysql_fetch_assoc($result1)) // loop to give you the data in an associative array so you can use it however.
{
$database[$index] = $row1;
$index++;
}
for ($i=1; $i < count($database); $i++) {
echo '<a href="photo.php?id='.$database[$i]['id'].'">';
echo '<div class="foto">';
echo '<img title="'.$database[$i]['description'].'" alt="'.$database[$i]['description'].'" src="data:image/jpg/png/jpeg;base64,'.base64_encode( $database[$i]['image'] ).'" width="200px"/>';
echo "<div id='date'>".$database[$i]['uploaded']."</div>";
echo '</div>';
echo '</a>';
if ((($i % 4) == 0) && ($i != 0)) {
echo '<br><br>';
}
}
?>
</body>
I want to display image one by one and be able to click on them -> link that brings me to photo.php?id= with id of that image. (id is from 1 to n)
db sructure:
enter image description here

select name from php query and refresh seprate query on same page.

I have just used my first bit of AJAX to search a MySQL database. This is for a persons name I would normally add a href to the result (which i have) and post to a seprate page to show all the the relevant details, eg address, grade and location. However i was wondering if this is possible staying on the same page. This is what i have so far. ( and yes the CSS will be moving to a seprate page)
<?php
if(!strlen(trim($_SESSION['Unique_Id']))) {
header("Location:roster.php");
exit();
}
?>
<title>Search Roster</title>
<style>
body {
font-family: "Lucida Grande", Verdana, Arial, sans-serif;
font-size: 12px;
}
#results {
color: #fff;
background: #414141;
width: 180px;
max-height: 200px;
padding-left: 4px;
border: 1px solid #000;
overflow-y: scroll;
overflow-x: hidden;
}
a { color: #fff; display: block; }
a:hover { background: #666666; }
</style>
Keyword Search:
<form id="searchform" method="post" onsubmit="return false;"><input autocomplete="off" id="searchbox" name="searchq" onkeyup="sendRequest()" type="textbox">
</form><div id="show_results"></div><script src="config/prototype.js" type="text/javascript">
</script>
<script>
function sendRequest() {new Ajax.Updater('show_results', 'pages/login/search.php', { method: 'post', parameters: $('searchform').serialize() });
}
</script>
<?php include("pages/include/footer.php"); ?>
and the search.php page
<?php
$host="****"; // Host name
$sqlusername="****"; // Mysql username
$sqlpassword="****"; // Mysql password
$db_name="****"; // Database name
$tbl_name="****"; // Table name
mysql_connect("$host", "$sqlusername", "$sqlpassword")or die("cannot connect");
mysql_select_db("$db_name")or die("cannot select DB");
$searchq = $_POST['searchq'];
if(empty($searchq)) {
echo "";
} else {
echo "<div id='results'-->";
//This query searches the name field for whatever the input is.
$sql = "SELECT * FROM USER WHERE Employee LIKE '%$searchq%' OR staff LIKE '%$searchq%'";
echo "<table border='3'>
<tr>
</tr>";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result)) {
$name = $row['EmployeeName'];
$id=$row['Unique_Id'];
echo "<a href=anotherpage.php?item=".$id."</a>";
echo "$name";
echo "</br>";
}
echo "</div>";
}
?>
You have did mistake in following line of code in "search.php". Also verify other line of code.
echo "<a href=anotherpage.php?item=".$id."</a>";
echo "$name";
Above code should be like as follows :
echo "".$name."";

Categories