It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
Since I am new to PHP I want to know how to print a file content in PHP?
Actually my project consist of form from which data is choosed to print on a report but I want a print button on my form to print the report contents directly. Can anyone help please?
Here's my code .. I have used CSS, html and PHP and it has two buttons view and print
<?php
if ($_POST["submit"] == "View") {
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<head>
<style type="text/css" media="all">
* {
margin:0px;
padding:0;
}
body {
margin:0px;
padding:0px;
font-family:Verdana, Arial, Helvetica, sans-serif;
font-size:12px;
}
span {
font-size:12px;
}
th, td {
width: 100mm;
height: 33.5mm;
}
table {
border-collapse:collapse;
}
</style>
<title>Hotel Label - <?php echo $_SESSION["tourname"]; ?></title>
</head>
<body>
<div style="margin:0px; padding:0; width:210mm; margin-top:12mm; margin-bottom:12mm; margin-left:0.5cm; margin-right:0cm; ">
<?php
//echo $getno;
/* } // View Tag Close
else {
ini_set("memory_limit", "50M");
ob_start();*/
?>
<style type="text/css" media="all">
<!--
body {
margin:0px;
font-family:Verdana, Arial, helvetica, sans-serif;
font-size:12px;
}
span {
font-size:12px;
}
td {
width: 100mm;
max-width: 100mm;
height: 33.5mm;
max-height:33.5mm;
top:0mm;
}
table {
border-collapse:collapse;
}
-->
</style>
<page backtop="13mm" backbottom="1mm" backleft="5mm" backright="5mm" style="font-size: 10px; font-family: Verdana;">
<?php
?>
<?php
$ctr16 = 0;
$ctr16_2 = 0;
$nctr = 0;
$ctr = 0;
$mctr = 0;
$lblctr = 0;
while ($lbl = mysql_fetch_assoc($get)) {
$ctr16++;
$ctr16_2++;
$nctr++;
$ctr++;
$lblctr++;
$getno--;
if ($ctr == 1) {
echo "<table border=\"0\" align=\"left\" style =\"width: 210mm;\">";
echo "\n <tr> \n ";
echo "\n <tr> \n ";
echo "\n <td style=\"width: 100mm; max-width: 100mm; height:33.5mm; padding-left:1mm;\" valign=\"top\"> \n";
if ($lblctr > 16) {
echo "<br>";
echo "<br>";
$lblctr = 1;
}
if ($ctr16 > 64) {
echo "<br>";
echo "<br>";
$ctr16 = 1;
}
}
else {
echo "\n <td style=\"width: 100mm; max-width: 100mm; height:33.5mm; padding-left:15mm;\" valign=\"top\"> \n";
if ($nctr > 16) {
echo "<br>";
echo "<br>";
$nctr = 1;
}
if ($ctr16_2 > 64) {
echo "<br>";
echo "<br>";
$ctr16_2 = 1;
}
}
echo "<br />". "<span><font size='3px'><b>$lbl[hotelname]</b></font>";
// echo "<font size='2px'>$lbl[hotelname]";
echo "<br />"."<br />"."<font size='2px'>Haji No.-$lbl[hajino]</font>";
echo "<br />"."$lbl[suffix] $lbl[surname] $lbl[name]$lbl[midname] <br />";
echo "<br />"."<font size='2px'><b>Room No - $lbl[roomno] Bus No - $lbl[busname]</font></b>";
echo "<br />";
echo "<br />";
echo "<br />";
echo "</span> ";
// echo "<br />";
echo "</td>";
if ($ctr == 2 || $getno == 0) {
echo '<br />';
$ctr = 0;
echo "</table>";
}
}
mysql_free_result($get);
?>
</div>
</body>
</html>
<?php
} else($_POST["submit"]== "Print"){
$filecontents = file_get_contents("hotel_label_print.php");
print $filecontents;
} ?>
You can use file_get_contents()
(http://php.net/manual/en/function.file-get-contents.php)
<?php
$homepage = file_get_contents('filename.txt');
echo $homepage;
?>
Related
I am developing an online examination system. Everything works fine but the questions are selected and displayed from question number one to the last question. I wanted to do the following:
Select the questions and display them one after the other at random.
Add a skip button so that students can skip any question they can't answer and it will be rolled back to them later.
Give a time to the answering session so that when the time is up it will stop the student.
This is my code for the question selection.
<!DOCTYPE html">
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css">
body{background-color:#f4fff8;}
#aq{
position:relative;
top:50px;
}
#st{
position:relative;
top:30px;
}
.btn{
background-color:#dedbb8;
color:#016e37;
text-shadow:3px 3px 3px gray;
box-shadow:3px 3px 3px gray;
height:40px;
text-align:center;
font-size:25px;
font-family:'Times New Roman';
font-weight:bold;
font-style:italic;
margin-top:2px;
border-radius: 2px;
}
.style8{
padding-top:5px;
font-size:20px;
}
#pt{
padding-top:20px;
}
h1{
position:relative;
color:green;
top:30px;
}
h2{
position:relative;
color:orange;
top:30px;
}
</style>
</head>
<body>
<?php
require_once("dbconnect.php");
include("header.php");
include("footer.php");
include("stdlogsession.php");
extract($_GET);
extract($_POST);
extract($_SESSION);
$student_id=$_SESSION['login_user'];
$student_id = stripslashes($student_id);
$student_id = mysqli_real_escape_string($db_conn,$student_id);
if(!empty($_GET['examid']))
{
$examid =$_GET['examid'];
}
// Selecting Database
$db = mysqli_select_db($db_conn,$mysql_database);
$rs=mysqli_query($db_conn,"select * from objquestions where exam_id='$examid'") or die('Error: ' .mysql_error($db_conn));
if(!isset($_SESSION['qn']))
{
$_SESSION['qn']=0;
}
if(!empty($_POST['submit'])=='Answer' && isset($ans))
{
mysqli_data_seek($rs,$_SESSION['qn']);
$row= mysqli_fetch_row($rs);
if($ans==$row[8])
{
$remarks= "Correct";
$mark=$row[9];
} else {
$remarks= "Wrong";
$mark=0;
}
mysqli_query($db_conn,"insert into results(exam_id,student_id,quesNum,choice,remarks,mark) values ('$row[1]','$student_id','$row[2]', '$ans','$remarks','$mark')") or die(mysqli_error($db_conn));
$_SESSION['qn']=$_SESSION['qn']+1;
}
if($_SESSION['qn']>mysqli_num_rows($rs)-1)
{
$examN=mysqli_query($db_conn,"select examName from exampaper where exam_id='$examid'") or die('Error: ' .mysqli_error($db_conn));
$row = mysqli_num_rows($examN);
if ($row > 0) {
$rows=mysqli_fetch_assoc($examN);
$Enam=$rows['examName'];
}
echo "<center><h1>congrats! you have successfully finished your " .$Enam."</h1></center>";
echo "<center><h2> Click <a href=instresult.php>here</a> for your results </h2></center>";
unset($_SESSION['qn']);
exit();
}
if(!empty($_POST['submit'])=='Skip' && !isset($ans))
{
mysqli_data_seek($rs,$_SESSION['qn']);
$row= mysqli_fetch_row($rs);
$_SESSION['qn']=$_SESSION['qn']+1;
}
$rs=mysqli_query($db_conn,"select * from exampaper where exam_id='$examid'") or die('Error: ' .mysql_error($db_conn));
$rows = mysqli_num_rows($rs);
while($rows=mysqli_fetch_row($rs))
{
echo "<center>";
echo "<table id=aq >";
echo "<tr><td>
<span class=style8>SUBJECT:</span></td>
<td class=style8>$rows[2]</td>
</tr>";
echo "<tr><td>
<span class=style8>EXAMINATION NAME:</span></td>
<td class=style8>$rows[1]</td>
</tr>";
echo "<tr><td>
<span class=style8>EXAMINATION DATE:</</span></td>
<td class=style8>$rows[3]</td>
</tr>";
echo "<tr><td>
<span class=style8>TOTAL TIME:</span></td>
<td class=style8>$rows[4]</td>
</tr>";
echo "<tr><td>
<span class=style8>INSTRUCTIONS:</span></td>
<td class=style8>$rows[5]</td>
</tr>";
echo "</table>";
echo "</center>";
}
$rs=mysqli_query($db_conn,"select * from objquestions where exam_id='$examid'") or die(mysqli_error($db_conn));
if($_SESSION['qn']>mysqli_num_rows($rs)-1)
{
unset($_SESSION['qn']);}
echo "<center>";
echo "<table id=st>";
mysqli_data_seek($rs,$_SESSION['qn']);
$row= mysqli_fetch_row($rs);
echo "<form name=myfm method=post action=exam.php>";
$n=$_SESSION['qn']+1;
echo "<tR ><td id=pt><span class=style8>Quetion ". $n .": $row[3]</style></td></tr>";
echo "<tr><td class=style8><input type=radio name=ans value=A>$row[4]</td></tr>";
echo "<tr><td class=style8> <input type=radio name=ans value=B>$row[5]</td></tr>";
echo "<tr><td class=style8><input type=radio name=ans value=C>$row[6]</td></tr>";
echo "<tr><td class=style8><input type=radio name=ans value=D>$row[7]</td></tr>";
echo "<tr><td><input class=btn type=submit name=submit value='Answer'> <input align=right class=btn type=submit name=submit value='Skip'></td></tr></form>";
echo "</table>";
echo "</center>";
?>
</body>
</html>
I am having two drop down lists on a html page. The data is coming from a mysql database and contains information like latitude, longitude and address. The user selects one item from the drop down and clicks on submit.
At this stage, I want to display a google map and put a marker at the latitude and longitude. Then, when the user selects the option from second drop down, I want to just add a marker on that map.
Currently, I am able to load the map once he clicks the submit from first drop down but all the options I tried to drop the pins are not working.
Here is the code I have achieved till now:
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once('auth.php');
include ('LoginConfig.php');
include ('FetchAgentDetails.php');
include ('FetchDeliveryDetails.php');
?>
<!--
To change this template, choose Tools | Templates
and open the template in the editor.
-->
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Delivery Management System</title>
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyA0Rm5aK0BYu1f_TzhjkG97cchHHlQfrQY&sensor=false">
</script>
<style type="text/css">
html {height:100%}
body {height:100%;margin:0;padding:0}
#googleMap {height:100%}
</style>
<script>
function initialize()
{
var mapProp = {
center:new google.maps.LatLng(51.508742,-0.120850),
zoom:5,
mapTypeId:google.maps.MapTypeId.ROADMAP
};
var map=new google.maps.Map(document.getElementById("googleMap")
,mapProp);
}
google.maps.event.addDomListener(window, 'load', initialize);
</script>
</head>
<style type="text/css">
<!--
.style1 {
font-size: 20px;
font-weight: bold;
}
-->
</style>
<style type="text/css">
table.collection {width:250px;border:2px solid black;border-style: outset;border-collapse:collapse;}
table.collection tr {background-color:#fff; border-bottom: 1px #99b solid;padding:10px;}
table.collection tr:hover {background-color:#ffe;}
table.collection td {display:table-cell;border-bottom: 1px #99b solid; padding:10px;}
table.collection td a {text-decoration:none; display:table-row; padding:0px; height:100%;}
</style>
</head>
<body bgcolor="#8E8E38"
<div style="clear: right;">
<p align="left" class="style1">Welcome Delivery Manager! </p>
<img style="position: absolute; top: 0; right: 0;" src="./Images/logo.jpg" alt="Company Logo" width="90" height="60" align="middle"></img>
</div>
<p align="left">Home</p>
<hr></hr>
<!-- START Main Wrap -->
<form method="post">
<fieldset>
<div style="clear: left;float:left;">
<label for="deliveryList">Delivery Items:</label>
<select name="deliveryList" id="deliveryList">
<option value="Select delivery item" selected="selected">Select delivery item</option>
<?php
$deliveryHandler = new FetchDeliveryDetails();
$itemNameArray = $deliveryHandler->getItemNames();
foreach ($itemNameArray as $innerArray) {
if (is_array($innerArray)) {
$value = $innerArray['itemName'];
echo "<option value=\"$value\"";
if (isset($_POST['deliveryList']) && $_POST['deliveryList'] == $value)
echo 'selected';
echo ">" . $value . "</option>\n";
}
}
?>
</select>
<input type="submit" name="submit" id="submit" value="Submit"/>
</div>
<div style="clear: right;float:right;">
<label for="agentList">Avaliable Agent:</label>
<select name="agentList" id="agentList">
<option value="" selected="selected">Select agent to assign</option>
<?php
$agentHandler = new FetchAgentDetails();
$agentNameArray = $agentHandler->getAgentNames();
foreach ($agentNameArray as $innerArray) {
if (is_array($innerArray)) {
$agentId = $innerArray['agentId'];
$firstNameValue = $innerArray['firstname'];
$lastNameValue = $innerArray['lastname'];
$fullName = $firstNameValue . ' ' . $lastNameValue;
echo "<option value=\"$agentId\">$fullName</option>\n";
}
}
?>
</select>
<input type="submit" name="agentSubmit" id="agentSubmit" value="Check Location"/>
</div>
</fieldset>
</form>
<?php
if (isset($_POST['deliveryList'])) {
$selectedItemName = $_POST['deliveryList'];
$deliveryHander = new FetchDeliveryDetails();
$itemDetailsArray = $deliveryHander->getAllDeliveryDetails($selectedItemName);
foreach ($itemDetailsArray as $valuesArray) {
$itemNameValue = $valuesArray['itemName'];
$itemDescriptionValue = $valuesArray['itemDescription'];
$ownerFirstname = $valuesArray['firstName'];
$ownerLastname = $valuesArray['lastName'];
$dateAdded = $valuesArray['dateAdded'];
$deliveryDate = $valuesArray['deliveryDate'];
$deliveryAddress = $valuesArray['deliveryAddress'];
$deliveryLatitude = $valuesArray['deliveryLatitude'];
$deliveryLongitude = $valuesArray['deliveryLongitude'];
$assignedAgent = $valuesArray['assignedAgentId'];
if ($assignedAgent == 0) {
$assignedAgent = "-";
}
echo "<table border=\"1\" align=\"left\" class =\"collection\">\n";
echo "<tr>\n";
echo "<td >Item Name:<b>$itemNameValue</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Item Description: <b>$itemDescriptionValue</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Owner Name: <b>$ownerFirstname $ownerLastname</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td>Date Added: <b>$dateAdded</td>\n";
echo "</tr>\n";
echo "<tr>";
echo "<td>Delivery Date: <b>$deliveryDate</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Delivery Address: <b>$deliveryAddress</td>";
echo "</tr>";
echo "<tr>";
echo "<td>Assigned Agent: <b>$assignedAgent</td>";
echo "</tr>";
echo "</table>";
echo "<div id=\"googleMap\" style=\"width:500px;height:380px;\"></div>";
}
}
if (isset($_POST['agentList'])) {
}
?>
</body>
</html>
I almost forgot, this is my first PHP application, in fact my first web application. So please go easy on me. Point out other errors also, but please stick to the question.
Ok got it working by using iframe :) and a bit of php
Reference:
http://www.youtube.com/watch?v=HTm-3Cduafw
echo "<iframe style =\"display: block;
width: 800px;
padding-top: 2px;
height: 400px;
margin: 0 auto;
border: 0;\" width=\"425\" height=\"350\" align=\"center\" frameborder=\"0\" scrolling=\"no\" marginheight=\"0\" marginwidth=\"0\"
src=\"https://maps.google.com/maps?f=d&source=s_d&saddr=$agent_map_url&
daddr=$map_url&hl=en&z=10&t=m&mra=ls&ie=UTF8&output=embed\"></iframe><br/>";
SQL/PHP query works in PHPmyAdmin but not the site.
I notice that many have had this problem but admittedly I am not as advanced as some of the coders on this site...yet. =) I humbly request any experience you may have laying around :P Thank you.
<?php
// session_start();
// ob_start();
ini_set("display_errors", true);
error_reporting(-1);
// Connection to database.
mysql_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_db('') or die(mysql_error());
?>
<?php
// Maintenance page.
$maintenance = 1; // 1 = Site Online || 0 = Site Offline
if ($maintenance == 0) {
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<head>
<style type="text/css">
body {
color:#ffffff;
background-color: #000000;
font-family: Arial, Helvetica, sans-serif;
}
</style>
</head>
<title></title>
</head>
<body>
<center><img src="images/p4flogo.png" /></center><br />
<?php
echo "<br/><br /><center>This site is currently under maintenance.</center>";
} else {
// Start of main website.
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<head>
<style type="text/css">
body {
color:#ffffff;
background-color: #000000;
font-family: Arial, Helvetica, sans-serif;
}
a:link {color: orange; text-decoration: underline; }
a:active {color: red; text-decoration: underline; }
a:visited {color: orange; text-decoration: underline; }
a:hover {color: red; text-decoration: none; }
table {
border-color: #333333;
}
th {
background-color:#ffffff;
color:#000000;
font-family: Arial, Helvetica, sans-serif;
height:30px;
}
td { font-family: Arial, Helvetica, sans-serif;
color:#ffffff;
height:35px;
}
</style>
</head>
<title></title>
</head>
<body>
<table border="0" cellspacing="1" align="center">
<tr><td>
<center><img src="images/p4flogo.png" /></center><br /><br />
<form action="" method="post">
Search for a soldier: <input type="text" name="value" size="35" /><input type="submit" value="search" /><br />
<?php
if (isset($_POST['value']) && !empty($_POST['value'])) {
$value = mysql_real_escape_string($_POST['value']);
// query to database for soldier stats
// query works in phpmyadmin but not on site.
$sql = "
SELECT
`Name`,
MAX(`Level`),
`Class`,
SUM(`Kills`),
SUM(`Deaths`),
SUM(`Points`),
SUM(`TotalTime`),
SUM(`TotalVisits`),
`CharacterID`
FROM
`Characters`
WHERE
`Name` LIKE '$value%' OR `CharacterID` LIKE '$value'
GROUP BY
`Name`,
`Class`,
`CharacterID`
ORDER BY
`Name` ASC;";
$query = mysql_query($sql);
$numrow = mysql_num_rows($query);
if ($numrow >= 1) {
echo "<br /><b>View TOP 100 Players!</b><br />";
echo "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\"> ";
echo "<th>Soldier Name</th><th>Level</th><th>Class</th><th>KDR</th><th>Kills</th><th>Deaths</th><th>Points</th><th>Hours Played</th><th>Total Visits</th><th>CharacterID</th>";
echo "<br />";
WHILE ($row = mysql_fetch_assoc($query)) {
$SoldierName = $row['Name'];
$Level = $row['Level'];
$Class = $row['Class'];
if ($Class == NULL | empty($Class)) {
$Class = '<center>n / a</center>';
}
if ($Class == 1) {
$Class = 'Assault';
}
if ($Class == 2) {
$Class = 'Recon';
}
if ($Class == 3) {
$Class = 'Medic';
}
if ($Class == 4) {
$Class = 'Engineer';
}
echo $Kills = $row['Kills'];
if ($Kills == 0) {
$Kills = 1;
}
$Deaths = $row['Deaths'];
if ($Deaths == 0) {
$Deaths = 1;
}
$Kdr = round($Kills / $Deaths, 2);
$Points = $row['Points'];
$TimePlayed = $row['TotalTime'];
if ($TimePlayed == 0) {
$TimePlayed = 1;
} else {
$TimePlayed = round(($TimePlayed / 3600), 0);
}
$TotalVisits = $row['TotalVisits'];
$CharacterID = $row['CharacterID'];
echo "<tr>";
echo "<td><b>$SoldierName</b></td>";
echo "<td>$Level</td>";
echo "<td>$Class</td>";
if ($Kdr > 3.9) {
echo "<td><font color=\"red\"><b>$Kdr</b></font></td>";
} else if ($Kdr > 2.5 && $Kdr < 4) {
echo "<td><font color=\"orange\"><b>$Kdr</b></font></td>";
} else {
echo "<td><font color=\"limegreen\">$Kdr</font></td>";
}
echo "<td>$Kills</td>";
echo "<td>$Deaths</td>";
echo "<td>$Points</td>";
echo "<td>$TimePlayed</td>";
echo "<td>$TotalVisits</td>";
echo "<td>$CharacterID</td>";
echo "</tr>";
}
echo "</table>";
} else {
echo "No player found with that name. Please try again.";
}
} else {
if (empty($_POST['value'])) {
echo "<font color=\"red\">You must enter a search value.</font>";
}
// query to p4f database for top 100 players.
$sql = "SELECT * FROM `Characters` WHERE `Points` > 1 GROUP BY `Name` ORDER BY `Points` DESC LIMIT 100;";
$query = mysql_query($sql);
echo "<h3>TOP 100 PLAYERS</h3>";
echo "<table border=\"1\" cellspacing=\"0\" cellpadding=\"5\"> ";
echo "<th></th><th>Soldier Name</th><th>Level</th><th>Class</th><th>KDR</th><th>Kills</th><th>Deaths</th><th>Points</th><th>Hours Played</th><th>Total Visits</th><th>CharacterID</th>";
// echo "Made it to loop!";
$Rank = 1;
WHILE ($row = mysql_fetch_assoc($query)) {
$SoldierName = $row['Name'];
$Level = $row['Level'];
$Class = $row['Class'];
if ($Class == NULL | empty($Class)) {
$Class = '<center>n / a</center>';
}
if ($Class == 1) {
$Class = 'Assault';
}
if ($Class == 2) {
$Class = 'Recon';
}
if ($Class == 3) {
$Class = 'Medic';
}
if ($Class == 4) {
$Class = 'Engineer';
}
$Kills = $row['Kills'];
if ($Kills == 0) {
$Kills = 1;
}
$Deaths = $row['Deaths'];
if ($Deaths == 0) {
$Deaths = 1;
}
$Kdr = round($Kills / $Deaths, 2);
$Points = $row['Points'];
$TimePlayed = $row['TotalTime'];
if ($TimePlayed == 0) {
$TimePlayed = 1;
} else {
$TimePlayed = round(($TimePlayed / 3600), 0);
}
$TotalVisits = $row['TotalVisits'];
$CharacterID = $row['CharacterID'];
echo "<tr>";
echo "<td>$Rank</td>";
echo "<td><b>$SoldierName</b></td>";
echo "<td>$Level</td>";
echo "<td>$Class</td>";
if ($Kdr > 3.9) {
echo "<td><font color=\"red\"><b>$Kdr</b></font></td>";
} else if ($Kdr > 2.5 && $Kdr < 4) {
echo "<td><font color=\"orange\"><b>$Kdr</b></font></td>";
} else {
echo "<td><font color=\"limegreen\">$Kdr</font></td>";
}
echo "<td>$Kills</td>";
echo "<td>$Deaths</td>";
echo "<td>$Points</td>";
echo "<td>$TimePlayed</td>";
echo "<td>$TotalVisits</td>";
echo "<td>$CharacterID</td>";
echo "</tr>";
$Rank++;
}
echo "</table>";
}
}
?>
</td></tr>
</table>
</body>
</html>
I'm not sure about MySQL, but I know that in SQL when you do an aggregate function, like SUM(Kills), then you can't reference the row via $row['kills']. I don't know if this is your problem, but you could try doing SUM(Kills) as 'kills' in your SELECT statement. Doing this for your aggregate SELECTs will allow you to reference them all this way.
I have a generated php table which I would like to apply style in my style sheet, so for example top:15px, left:10px ect..., not sure how call the table and link it with css -
echo "<table border=1>";
for ($i=0;$i<count($calls);$i++){
for ($j=0;$j<count($days);$j++){
$k = $days[$i].$times[$j];
if (array_key_exists($k,$date)){
echo "<td colspan='{$date[$k][1]}'>".
"{$date[$k][0]}</td>";
$j+=$date[$k][1]-1;
}else
echo "<td style='color:gray'>$k</td>";
}
echo "</tr>";
}
echo "</table>";
any help much appreciated, thank you
echo '<table style="top: 15px; left:10px;">';
or
echo '<table class="someClass">';
and then use CSS
.someClass{
top: 15px;
left: 10px;
}
Give the table an id
echo "<table id=\"my_table\" border=1>";
And then use this in the <head> tag of the document:
<style type="text/css">
#my_table {
top: 15px;
...
}
</style>
echo "<table style=\"border: 1px; top:15px; left: 10px;\">";
Is this statement not working?
echo "<table border=1 style=\"top:15px; left:10px\">";
for ($i=0; $i<count($calls); $i++) {
for ($j=0;$j<count($days);$j++) {
$k = $days[$i].$times[$j];
if (array_key_exists($k,$date)) {
echo "<td colspan='{$date[$k][1]}'>".
"{$date[$k][0]}</td>";
$j+=$date[$k][1]-1;
} else {
echo "<td style='color:gray'>$k</td>";
}
}
echo "</tr>";
}
echo "</table>";
I am fetching data from the following database:
I have arduino-box that send that data.
And display the data with this CSS & HTML code:
<div class="event">
<img src="http://dummyimage.com/80x70/f00/fff.png" alt="picture" />
<p>Room 2</p>
<p class="patient-name">Jon Harris</p>
<p class="event-text">This is a pixel. A flying pixel!</p>
<p class="event-timestamp">feb 2 2011 - 23:01</p>
</div>
.event {
display:block;
background: #ececec;
width:380px;
padding:10px;
margin:10px;
overflow:hidden;
text-align: left;
}
.event img {
display:block;
float:left;
margin-right:10px;
}
.event p {
font-weight: bold;
}
.event img + p {
display:inline;
}
.patient-name {
display:inline;
color: #999999;
font-size: 9px;
line-height:inherit;
padding-left: 5px;
}
.event-text{
color: #999999;
font-size: 12px;
padding-left: 5px;
}
.event-timestamp{
color: #000;
padding-left: 5px;
font-size: 9px;
}
Here is my PHP code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>DASHBOARD - Arduino 3</title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<body>
<?php
$con = mysql_connect("localhost","*****","***");
if(!con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("arduino_db",$con);
$result = mysql_query("SELECT * FROM events");
//Start container
echo " <div id='background_container'> ";
while($row = mysql_fetch_array($result))
{
echo "<div class='event'>";
echo "<img src='img/ev_img/red.jpg' alt='picture' />";
echo "<p>" . $row['inneboende'] . "</p>";
echo "<p class='patient-name'>" . "$row['overvakare']" . "</p>";
echo "<p class='event-text'>" . "$row['handelse']" . "</p>";
echo "<p class='event-timestamp'>" . "$row['tid']" . "</p>";
echo "</div>";
}
//end container
echo "</div>"
mysql_close($con);
?>
</body>
</html>
The arduino box is sending data to the database.. lets say every 3sec. I dont want to press F5 every 5sec to get the new data. Should I use AJAX for this? I have read some AJAX on the net, but I havenĀ“t find any good tuts for it.
Put this in a separate php file, e.g. getEvents.php:
<?php
$con = mysql_connect("localhost","*****","***");
if(!con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("arduino_db",$con);
$result = mysql_query("SELECT * FROM events");
while($row = mysql_fetch_array($result))
{
echo "<div class='event'>";
echo "<img src='img/ev_img/red.jpg' alt='picture' />";
echo "<p>" . $row['inneboende'] . "</p>";
echo "<p class='patient-name'>" . "$row['overvakare']" . "</p>";
echo "<p class='event-text'>" . "$row['handelse']" . "</p>";
echo "<p class='event-timestamp'>" . "$row['tid']" . "</p>";
echo "</div>";
}
mysql_close($con);
Then, load jquery and put the following in the head of the page:
<script type="text/javascript">
$(document).ready(function() {
$.get('getEvents.php', function (data) {
$('#background_container').html(data);
});
});
</script>
Note: This is not the exact code you should use, take a look at it and change it so it works correctly for you.
If you are just trying to refresh the page every 5 seconds, you should use javascript and look at setTimeout:
setTimeout("location.reload(true);",5000);
5000 is equal to 5 seconds.