I am trying to make a calender using php according to a video tutorial from youtube. I m doing just what they do but there is a difference from their table.I can't find my mistake...any body help please....give the code and the picture of this....
This is my calender-
This is the tutorial calender-
<html>
<head>
<title>Calender</title>
</head>
<body>
<?php
if(isset($_GET['day']))
{
$day = $_GET['day'];
}else
{
$day = date("j");
}
if(isset($_GET['month']))
{
$month = $_GET['month'];
}else{
$month = date("n");
}
if(isset($_GET['year']))
{
$year = $_GET['year'];
}else{
$year = date("Y");
}
//calender variable-----------
$currentTimeStamp = strtotime($year-$month-$day);
$monthName = date("F",$currentTimeStamp);
$numDays = date("t",$currentTimeStamp);
$counter = 0;
?>
<table border = "1">
<tr>
<th><input style = "width : 50px"type = "button" value = "<" name = "prevbutton"></input></th>
<th colspan = "5"><?php echo $monthName.", ".$year?></th>
<th><input style = "width : 50px" type = "button" value = ">" name = "nextbutton"></input></th>
</tr>
<tr>
<td width = "50px">Sun</td>
<td width = "50px">Mon</td>
<td width = "50px">Tue</td>
<td width = "50px">Wed</td>
<td width = "50px">Thu</td>
<td width = "50px">Fri</td>
<td width = "50px">Sat</td>
</tr>
<?php
echo "<tr>";
for($i = 1;$i<$numDays+1;$i++,$counter++)
{
$timeStamp = strtotime($year-$month-$i);
if($i == 1)
{
$firstDay = date('w', $timeStamp);
for($j = 0;$j<$firstDay;$j++,$counter++)
{
echo "<td> </td>";
}
}
if($counter%7==0)
{
echo "</tr><tr>";
}
}
echo "</tr>";
?>
</table>
</body>
You had 3 bugs in php code
echo "<tr>";
for($i = 1;$i<$numDays+1;$i++,$counter++)
{
$timeStamp = strtotime($year.'-'.$month.'-'.$i);// it should be string
if($i == 1)
{
$firstDay = date('w', $timeStamp);
for($j = 0;$j<$firstDay;$j++,$counter++)
{
echo "<td> </td>"; // show days
}
$counter++; // first row counter correction
}
echo "<td>$i</td>";
if($counter%7==0)
{
echo "</tr><tr>";
}
}
echo "</tr>";
Related
Im building a page with multiple selects inside each row, im using the select2 plugin to do that, my problem is: I did a lot of research but i sitll couldnt find a way of exporting this table to csv. I dont know if it is because of the placeholders that select2 plugin puts in each row or if its other error that i dont know that im making. I will leave some pics from my page and the script that i tried to do.
<form method="POST" action="select.php">
<table class="table-responsive table-striped table-bordered" id="example">
<thead>
<tr>
<th>Id</th>
<th>Nome Praia</th>
<th>Turno</th>
<?php
$x = 0;
$dias = array();
while ($row = mysqli_fetch_assoc($resultsett))
{
echo "<th>" . $row['dia'] . "</th>";
$dia = $row['dia'];
$id_dia = $row['id_dia'];
array_push($dias, $id_dia);
$x++;
}
?>
</tr>
</thead>
<tbody>
<?php
$sql_query = "SELECT * FROM tb_praia";
$resultset = mysqli_query($conn, $sql_query) or die("database error:" . mysqli_error($conn));
while ($res = mysqli_fetch_assoc($resultset))
{
$id_praia = $res['id_praia'];
$nome_praia = $res['nome_praia'];
$turno = $res['turno'];
?>
<tr id="<?php $id_praia; ?>">
<td> <?php echo $id_praia; ?></td>
<td><?php echo $nome_praia; ?> </td>
<td><?php echo $turno; ?></td>
<?php for ($i = 0;$i < $x;$i++)
{
if ($id_praia % 2 == 0){
$query = "SELECT tb_nadadores.id_nadador, nome from tb_disponibilidade inner JOIN
tb_nadadores on tb_disponibilidade.id_nadador=tb_nadadores.id_nadador
where id_dia = $dias[$i] and Tarde=1 order by id_nadador ASC";
}else{
$query = "SELECT tb_nadadores.id_nadador, nome from tb_disponibilidade inner JOIN
tb_nadadores on tb_disponibilidade.id_nadador=tb_nadadores.id_nadador
where id_dia = $dias[$i] and Manhã=1 order by id_nadador ASC ";
}
$resposta = mysqli_query($conn, $query);
echo (
'<td>
<select name="nadadores[]" size="1" class="form-select multiple-select" multiple>
<br>'
);
if (mysqli_num_rows($resposta) > 0)
{
while ($teste = mysqli_fetch_assoc($resposta))
{
$nadador = $teste['nome'];
$id_nadador = $teste['id_nadador'];
echo "<option value=$id_nadador>$nadador</option>";
}
echo '</select>';
}
else{
echo 'Não foram encontrados resultados!';
}
echo "<input type='hidden' name='dias[]' value=$dias[$i] >";
echo "<input type='hidden' name='turno' value=$turno >";
echo "<input type='hidden' name='id_praia' value=$id_praia >";
echo "<input type='hidden' name='nome_praia' value=$nome_praia>";
}
}
?>
</tr>
</tbody>
</table>
<input type="submit" name="enviar" value="Enviar">
</form>
$(document).ready(function() {
$(".multiple-select").select2({
maximumSelectionLength: 2,
width: 'resolve'
});
$('.multiple-select').on('select2:select', function (e) {
var {id} = e.params.data;
var { dia, praia, turno} = e.currentTarget.dataset
console.log({ dia, praia, id, turno});
$.post('data.php', { dia, praia, id, turno })
// console.log(data);
})
$('.multiple-select').on('select2:unselect', function (remove) {
var {id} = remove.params.data;
var { dia, praia, turno} = remove.currentTarget.dataset
$.post('remove.php', { dia, praia, id, turno })
console.log( { dia, praia, id, turno });
});
});
Export script
function downloadCSVFile(csv, filename) {
var csv_file, download_link;
csv_file = new Blob([csv], {type: "text/csv"});
download_link = document.createElement("a");
download_link.download = filename;
download_link.href = window.URL.createObjectURL(csv_file);
download_link.style.display = "none";
document.body.appendChild(download_link);
download_link.click();
}
document.getElementById("download-button").addEventListener("click", function () {
var html = document.querySelector("table").outerHTML;
htmlToCSV(html, "Horario_Definido.csv");
});
function htmlToCSV(html, filename) {
var data = [];
var rows = document.querySelectorAll("table tr");
for (var i = 0; i < rows.length; i++) {
var row = [], cols = rows[i].querySelectorAll("td, th");
for (var j = 0; j < cols.length; j++) {
row.push(cols[j].innerText);
}
data.push(row.join(","));
}
//to remove table heading
//data.shift()
downloadCSVFile(data.join("\n"), filename);
}
I have a table that gathers some data from a MySQL table. For some reason, it only displayed the contents as columns once I used fetch(PDO::FETCH_NUM); but now I am stuck, as no JS or PHP function seems to work conditionally formatting the results of the column. Those results range where everything between 52 and 120 should be in red.
$sql = "SELECT mac_address,upstream,downstream_snr,downstream,uptime from modems where rpi_serial='$rpi'";
$stmt = $pdo->query($sql);
$nRows = $stmt->fetch(PDO::FETCH_NUM);
if ($nRows > 0) {
echo '<table class="table table-bordered table-condensed table-hover" id="modems">
<tr><th class="col-md-5ths" id="MC">Mac</th><th class="col-md-5ths">Upstream</th>
<th class="col-md-5ths id="DWS">Downstream SNR</th><th class="col-md-5ths" id="DW">Downstream</th>
<th class="col-md-5ths">Uptime</th></tr>';
// Output data of each row
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
echo "<tr><td style=\"$colour\">".$row["0"]."</td><td>".$row["1"]."</td><td>".$row["2"]."</td><td>".$row["3"]."</td><td>".$row["4"]."</tr>";
}
echo "</table>";
} else {
echo "0 results";
}
In addition to the comments above, do this 2 loops - rows and fields.
// output data of each row
while ($row = $stmt->fetch(PDO::FETCH_NUM)) {
echo "<tr>";
for ($i = 0; $i < count($row); $i++) {
$value = $row[$i];
$colour = ($value >= 52 && $value <= 120) ? "red" : "green";
echo "<td style=\"color:$colour\">" . $value . "</td>";
}
echo "</tr>";
}
I have this pagination written in php that works fine, but I want to use ajax to implement this so that the pages won't have to reload every time a link is clicked. I have gone through previous questions asked on this same topic here on SO and other blogs but I'm not getting it right.
Here's my pagination code in nav_tbl.php
if(!empty($_POST['rownum'])){
$rowno = $_POST['rownum'];
//get current page
$currentpage = isset($_POST['currentpage']) ? $_POST['currentpage'] : 1;
$no_of_records_per_page = $rowno;
$setoff = ($currentpage - 1) * $no_of_records_per_page;
//get total number of records in database
$sqlcount = "SELECT *FROM evatbl WHERE RegNo = ?";
$stmt = $con->prepare($sqlcount);
$stmt->bind_param("s", $pregno);
$pregno = $_SESSION['regno'];
$stmt->execute();
$result = $stmt->get_result();
$num_rows = $result->num_rows;
$totalpages = ceil($num_rows/$no_of_records_per_page);
//query for pagination
$sqllimit = "SELECT *FROM evatbl WHERE RegNo = ? ORDER BY CourseTitle LIMIT $setoff, $no_of_records_per_page";
if ($stmt = $con->prepare($sqllimit))
{
$stmt = $con->prepare($sqllimit);
$stmt->bind_param("s", $pregno);
$pregno = $_SESSION['regno'];
$stmt->execute();
$result = $stmt->get_result();
$num_rows = $result->num_rows;
if ($num_rows>0)
{
$count = 1;
echo "<table id='t01' class='table' width='100%'>
<tr id='tblhead'>
<th>SN</th>
<th>Course Title</th>
<th>Course Code</th>
<th>Credit Unit</th>
<th>Course Lecturer</th>
<th>Rating(%)</th>
</tr>";
while($row = $result->fetch_assoc())
{
$ccode = $row['CourseCode'];
$ctitle = $row['CourseTitle'];
$cunit = $row['CreditUnit'];
$clec = $row['CourseLecturer'];
$crate = $row['Rating'];
echo "
<tr>
<td>$count</td>
<td>$ctitle</td>
<td>$ccode</td>
<td>$cunit</td>
<td>$clec</td>
<td>$crate</td>
</tr>";
$count++;
}
echo "</table>";
}
else{
echo "<p style='color:darkred;margin-bottom:0;'>Oops! No records found.</p>";
}
?><br>
<div class="nav_div" id="nav_div">
<label for="navno">Navigate pages: </label>
<?php
//First Page Button
if($currentpage > 1)
{
echo "<a class='nav_a' id='first' href='view_eva.php?limit=".$rowno."¤tpage=".(1)."' title='First'><<</a>";
}
//Previous Page Button
if($currentpage >= 2)
{
echo "<a class='nav_a' id='prev' href='view_eva.php?limit=".$rowno."¤tpage=".($currentpage - 1)."' title='Previous'><</a>";
}
?>
<select class='navno' name='navno' id='navno' onchange="pageNav(this)">
<?php
//Link to available number of pages with select drop-down
for($i = 1; $i <= $totalpages; $i++)
{
echo "<option class='bold'";
if ($currentpage==$i)
{
echo "selected";
}
echo " value='view_eva.php?limit=".$rowno."¤tpage=".$i."'>".$i."</option>";
}
?>
</select>
<?php
//Next Page Button
if($currentpage < $totalpages)
{
echo "<a class='nav_a' id='next' href='view_eva.php?limit=".$rowno."¤tpage=".($currentpage + 1)."' title='Next'>></a>";
}
//Last Page Button
if($currentpage <= $totalpages - 1)
{
echo "<a class='nav_a' id='last' href='view_eva.php?limit=".$rowno."¤tpage=".($currentpage = $totalpages)."' title='Last'>>></a>";
}
?>
</div>
<?php
}
else
{
echo "<p style='color:darkred;margin-bottom:0;'>Oops! No records found.</p>";
}
?>
And here's the Ajax code to set number of rows to display per page using a select dropdown option
$(document).on('change', '#rowno', function(e){
e.preventDefault();
var rownum = $('#rowno').val();
if($('#check').is(":checked")) {
$('#check').prop('checked',false);
}
$.ajax({
type: 'POST',
url: 'navtbl.php',
cache: false,
async: false,
data: {
rownum : rownum
},
success: function(datalog){
console.log(datalog);
$("#display_table").html(datalog).show();
},
error: function(datalog){
swal("Oops.", "An error occured! Unable to fetch result.", "error");
}
});
});
// Call Function to load and display table on Page Load
function Ini_loadTable(){
var rownum = $('#rowno').val();
$.ajax({
type: 'POST',
url: 'navtbl.php',
cache: false,
async: false,
data: {
rownum : rownum
},
success: function(datalog){
console.log(datalog);
$("#display_table").html(datalog).show();
},
error: function(datalog){
swal("Oops.", "An error occured! Unable to fetch result.", "error");
}
});
}
Please, any help will be much appreciated. Thank you.
Okay I am wondering how I get two countdown timers on the one page?
<script type = 'text/javascript'>
window.onload=function() {
setInterval("<?php
$array = count($settime);
for ($i = 0; $i < $array; $i++) {
$thitime = explode(":", $settime[$i]);
echo "timeleft(" . $thitime[1] . ", " . $thitime[0] . "); ";
}
?>", 1000);
}
function timeleft(string, id)
{
var xmlhttp=GetXmlHttpObject();
if(xmlhttp==null) { alert("Sorry, Your browser doesnt support HTTP Requests");
return;
}
var elem = "time" + id;
var load = "time_left.php?string=" + string;
xmlhttp.onreadystatechange=function() {
if(xmlhttp.readyState==4) {
document.getElementById(elem).innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", load, true);
xmlhttp.send(null);
}
function GetXmlHttpObject() {
var xmlhttp=null;
try {
xmlhttp=new XMLHttpRequest();
}
catch (e) {
try {
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlhttp;
}
</script>
The page I am trying to run the two timers off is only loading one of the timers, I have tried multiple things to try and fix the issue, and can't seem to figure out what it is that is wrong with it..
I even tried making two different timer scripts and that didn't work..
Here is the complete code of the page I want to run the two timers on..
<?php
/*------------includes--------------*/
include('./includes/connections.php');
include('./includes/brain_file.php');
include('./includes/style_top.php');
/*------------includes--------------*/
if ($pl['my_tuts_on'] == 'yes') {
echo "<tr bgcolor=#E6E6E6><td>
Here you can view all the inmates currently in jail. You may attempt to bust/bail them, Bailing them costs a fee, Busting them uses 10 energy and is not a garantee you will bust them, Just be carefull not to get caught and end up in jail yourself.
</td></td></tr></table></center><hr/ width=95%>";
}
echo "<center><main>Jail</main><hr width='95%'/>";
if ($pl['my_hosp'] > gmtime()) {
echo "Sorry this page is not viewable while in hospital!<hr width='85%'/>";
include('./includes/style_bottom.php');
exit();
}
$_GET['page'] = abs(intval($_GET['page']));
$min = ($_GET['page'] > '1') ? (($_GET['page'] - 1) * 25) : $min = 0;
$q_ry = array();
$q_ry = "SELECT `playerid` FROM `members`
WHERE `my_jail` > '" . mysql_real_escape_string(gmtime()) . "'";
$tot = array();
$tot = mysql_query($q_ry);
if ($joh['my_jail'] > gmtime()) {
$settime[] = $pl['playerid'] . ":" . $pl['my_jail'];
echo "<br><font size=2><b>", stripslashes($pl['jail_reason']), "</b>
<br>You will be in jail for another <span id = 'time" . $pl['playerid'] . "'><b>" . gettimeleft($pl['my_jail']) . "</b></span> yet!</font><br><br><hr width='85%'>";
}
?>
<script type = 'text/javascript'>
window.onload=function() {
setInterval("<?php
$array = count($settime);
for ($i = 0; $i < $array; $i++) {
$thitime = explode(":", $settime[$i]);
echo "timeleft(" . $thitime[1] . ", " . $thitime[0] . "); ";
}
?>", 1000);
}
function timeleft(string, id)
{
var xmlhttp=GetXmlHttpObject();
if(xmlhttp==null) { alert("Sorry, Your browser doesnt support HTTP Requests");
return;
}
var elem = "time" + id;
var load = "time_left.php?string=" + string;
xmlhttp.onreadystatechange=function() {
if(xmlhttp.readyState==4) {
document.getElementById(elem).innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", load, true);
xmlhttp.send(null);
}
function GetXmlHttpObject() {
var xmlhttp=null;
try {
xmlhttp=new XMLHttpRequest();
}
catch (e) {
try {
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlhttp;
}
</script>
<?php
if ($pl['my_jail'] > gmtime()) {
echo "<b>><a href='bust.php'>Try and escape for " . abs(intval($pl['my_maxnerve'] / 2)) . " nerve</a></b>
<hr width='85%'>";
}
echo "<b></b> ";
if (mysql_num_rows($tot) <= '25') {
echo "";
} else {
if ($_GET['page'] > '1') {
echo "<a href='jail.php?page=" . ($_GET['page'] - 1) . "'><<</a> ";
}
for ($i = 0; $i < (mysql_num_rows($tot) / 25); $i++) {
echo "<a href='jail.php?page=" . ($i + 1) . "'>";
if (($i + 1) == $_GET['page']) {
echo "<b>" . ($i + 1) . "</b>";
} else {
echo "<font color = '#999999'>" . ($i + 1) . "</font>";
}
echo "</a> ";
}
if ($_GET['page'] < $i) {
echo " <a href='jail.php?page=" . ($_GET['page'] + 1) . "'>>></a>";
exit();
}
}
echo "<table class='sidebarLink' border='0' width=95% class='rounded'><tr bgcolor=#151515>
<td height='20'><font color = '#FFFFFF'><b>ID#</b></font></td>
<td height='20'><font color = '#FFFFFF'><b>Player</b></font></td>
<td width=25%><font color = '#FFFFFF'><b>Time</b></font></td>
<td height='20'><font color = '#FFFFFF'><b>Level</b></font></td>
<td height='20'><font color = '#FFFFFF'><b>Reason</b></font></td>
<td height='20'><font color = '#FFFFFF'><b>Release</b></font></td></tr>";
$num = 0;
$q_ry = array();
$q_ry = "SELECT `playerid`,`playername`,`my_level`,`jail_offer`,`my_jail`,`jail_reason`
FROM `members`
WHERE `my_jail` > '" . mysql_real_escape_string(gmtime()) . "'
ORDER BY `my_jail` DESC
LIMIT $min,25";
$hopl = array();
$hopl = mysql_query($q_ry);
if (mysql_num_rows($hopl)) {
$hp = array();
while ($hp = mysql_fetch_array($hopl)) {
$num++;
if ($num % 2) {
$color = "#E6E6E6";
} else {
$color = "#E6E6E6";
}
$q_ry = array();
$q_ry = "SELECT `my_bustreward`
FROM `members_extra`
WHERE `playerid` = '" . $hp['playerid'] . "'";
$du = array();
$du = mysql_fetch_array(mysql_query($q_ry));
$settime[] = $hp['playerid'] . ":" . $hp['my_jail'];
echo "<tr bgcolor=#E6E6E6>
<td><a href = 'messages.php?action=send&XID=" . $hp['playerid'] . "'>" . $hp['playerid'] . "</a></td>
<td><a href = 'profile.php?XID=" . $hp['playerid'] . "'>" . htmlentities($hp['playername']) . "</a></td>
<td><span id = 'time" . $hp['playerid'] . "'><b>" . gettimeleft($hp['my_jail']) . "</b></span></td>
<td>" . $hp['my_level'] . "</td>
<td>" . stripslashes($hp['jail_reason']) . "</td>
<td>[<a href='release.php?action=bail&XID=" . $hp['playerid'] . "'>Bail</a>]
[<a href='release.php?action=bust&XID=" . $hp['playerid'] . "'>Bust</a>]</td></tr>";
}
} else {
echo "<tr>
<td colspan = '7' align = 'center'>
You walk into the jail to tease some inmates, but there are no inmates to tease!
</td></tr>";
}
echo "</table>
<hr width = '95%'>";
if ($pl['my_jail'] > gmtime() || $pl['am_i_staff'] > 4) {
if ($pl['am_i_staff'] > 4) {
echo '<table width="95%" align="center" border="0" bgcolor="#E6E6E6">
<b>Clear the current shoutbox.</b>
<form method="post" action="#"><tr>
<td><input type="hidden" name="clear"></td>
</tr><tr>
<td colspan="2" valign="middle" align="center"><input class="hospchat" type="submit" value="Clear ALL Shouts"></td>
<td></td>
</tr></form></table><br />';
}
if (isset($_POST['clear'])) {
if ($pl['am_i_staff'] < 5) {
print "Sorry, staff only. <a href=jail.php>> back</a>.";
exit();
} else {
mysql_query("TRUNCATE table `jailshoutsbox`");
print "All of the jail shouts have been <b>cleared</b> <a href=jail.php>> back</a>.";
}
}
if (isset($_POST['shout'])) {
if ($pl['lastShoutj'] == date("i") && $pl['am_i_staff'] < 5 && $pl['my_dondays'] < 1) {
echo "<div style='background: #DFDFDF;' width='85%'>Sorry, non donators can only post once per minute. <br /> <a href=jail.php> > back</a></div><br />";
exit();
}
if ($pl['my_jail'] <= 0 && $pl['am_i_staff'] < 5) {
echo "You are not in the jail. <a href=jail.php>> Back</a>";
exit();
}
echo "<div style='background: #E6E6E6;' width='85%'>You've shouted<br /><a href=jail.php>Refresh</a></div><br />";
$_POST['shout'] = htmlspecialchars(($_POST['shout']));
$not = array(
"'",
"/",
"<",
">",
";"
);
$_POST['shout'] = str_replace($not, "", $_POST['shout']);
mysql_query("INSERT INTO `jailshoutsbox` VALUES ('NULL', {$_SESSION['playerid']}, '{$_POST['shout']}', " . date("d") . ")");
}
echo ' <hr width=95% /> Post a message on the shoutbox.
<table width="95%" align="center" border="0" bgcolor="#E6E6E6">
<form method="post" action="#"><tr>
<td>Your Message: (max 155) </td>
<td><input class="hospchat" type="text" name="shout" maxlength="155"></td>
</tr><tr>
<td colspan="2" valign="middle" align="center"><input class="hospchat" type="submit" value="Shout"></td>
<td></td>
</tr></form></table><br /><table width="95%" style=text-align:left class="table2" border="0" cellspacing="2">
<tr bgcolor="#151515" style="font-style:bold; text-align:center;"><td style="font-style:bold;" width=55%><b><font color="#FFFFFF">Posted By:</b></td><td style="font-style:bold;" width="44%"><b><font color="#FFFFFF">Messsage:</b></td></tr>
';
$get = mysql_query("SELECT * FROM `jailshoutsbox` ORDER BY `ID` DESC LIMIT 10");
while ($r = mysql_fetch_array($get)) {
$num9 = $num9 + 1;
$odd9 = "#CCCCCC";
$even9 = "#e3e3e3";
if ($num9 % 2) {
$color9 = "$even9";
} else {
$color9 = "$odd9";
}
if ($r['User'] == 1) {
$r['Shout'] = "<font color='blue'>" . $r['Shout'] . "</font>";
}
$user = mysql_query("SELECT `playername` FROM `members` WHERE `playerid`={$r['User']}");
while ($user1 = mysql_fetch_array($user))
$player = ($r['User'] == 0) ? "SYSTEM" : "<a href='profile.php?XID={$r['User']}'>[{$r['User']}] {$user1['playername']}</a>";
echo "<tr height='50px' bgcolor=#E6E6E6><td>$player</td><td style='text-align:center;'>{$r['Shout']}</td></tr>";
}
echo "</table>";
}
include('./includes/style_bottom.php');
?>
And here is the gettimeleft function.
function gettimeleft($tl) {
if($tl <= time()) { $release = "0 Seconds"; }
else
{
$mins = floor(($tl - time()) / 60);
$hours = floor($mins / 60);
$mins -= $hours * 60;
$days = floor($hours / 24);
$hours -= $days * 24;
$months = floor($days / 31);
$days -= $months * 31;
$weeks = floor($days / 7);
$days -= $weeks * 7;
$timeleft = ($tl - time());
$secs = round($timeleft%60);
if ($months > 0)//MONTHS
{
$release .= " $months Month" . ($months > 1 ? "s" : "");
}
if ($weeks > 0)//WEEKS
{
if ($months > 0)
{
$release .= ",";
}
$release .= " $weeks Week" . ($weeks > 1 ? "s" : "");
}
if ($days > 0)//DAYS
{
if ($months > 0 ||$weeks > 0)
{
$release .= ",";
}
$release .= " $days Day" . ($days > 1 ? "s" : "");
}
if ($hours > 0)//HOURS
{
if ($months > 0 ||$weeks > 0 || $days > 0)
{
$release .= ",";
}
$release .= " $hours Hour" . ($hours > 1 ? "s" : "");
}
if ($mins > 0)//MINUTES
{
if ($months > 0 ||$weeks > 0 || $days > 0 || $hours > 0)
{
$release .= ",";
}
$release .= " $mins Minute" . ($mins > 1 ? "s" : "");
}
if($secs > 0)//SECONDS
{
if($release != "")
{
$release .= " and";
}
$release .= " $secs Second" . ($secs > 1 ? "s" : "");
}
}
return $release;
}
Is anyone please able to help me out with this?
I have a page with buttons that a user clicks on.
When the button gets clicked I need it to change the image and call a php script to save the change.
I somehow can't get the button to do both, it changes the pic but won't call the php.
CODE:
<?php
$db = new PDO('mysql:host=localhost;dbname=MySettings;charset=utf8mb4', 'TestUser', '1234567890');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
try {
$mytable = $_SESSION["SESS_myuserid"];
if($mytable == null)
{$url='login.php';
echo '<META HTTP-EQUIV=REFRESH CONTENT="1; '.$url.'">';}
$stmt = $db->prepare("SELECT * FROM ".$mytable);
$stmt->execute();
$result = $stmt->fetchAll(PDO::FETCH_ASSOC);
$conn = null;
echo'<script>';
$count = count($result);
for ($i = 0; $i < $count; $i++) {
$TheId = $result[$i]['Id'];
$TheFunction = $result[$i]['TheFunction'];
$TheSetting = $result[$i]['TheSetting'];
if ($TheSetting == "0"){
echo 'var newsrc'.$TheId.' = "on.jpg";';
}
else{
echo 'var newsrc'.$TheId.' = "off.jpg";';
}
echo 'function changeImage'.$TheId.'() {';
echo 'if ( newsrc'.$TheId.' == "off.jpg" ) {';
echo "document.getElementById('pic".$TheId."').src = '/images/Boff.png';";
echo "$('#newCode').load('Monitor.php?id=".$TheId."&Table=".$mytable."');";
echo 'newsrc'.$TheId.' = "on.jpg";';
echo '}';
echo 'else {';
echo "document.getElementById('pic".$TheId."').src = '/images/Bon.png';";
echo "$('#newCode').load('Monitor.php?id=".$TheId."&Table=".$mytable."');";
echo 'newsrc'.$TheId.' = "off.jpg";';
echo '}';
echo '}';
}
echo'</script>';
$myLeft=0;
$myTop=0;
$myRow=0;
for ($i = 0; $i < $count; $i++) {
$TheId = $result[$i]['Id'];
$TheFunction = $result[$i]['TheFunction'];
$TheSetting = $result[$i]['TheSetting'];
if ($TheSetting == "0"){
$ThePic = "images/Boff.png";
}
else{
$ThePic = "images/Bon.png";
}
echo '<div>';
echo ' ';
echo '</div>';
$myTop=$myTop + 30;
$myRow=$myRow + 1;
if ($myRow == 12){
$myRow=0;
$myTop=0;
if ($myLeft == 0){
$myLeft = 292;
}
else {
$myLeft = 615;
}
}
}
}
catch(PDOException $e) {
$url='login.php';
echo '<META HTTP-EQUIV=REFRESH CONTENT="1; '.$url.'">';
}
?>
Fixed :
Changed the script function. Added a hidden div to be called to load the php which outputs nothing so stays invisible.
echo'<script>';
$count = count($result);
for ($i = 0; $i < $count; $i++) {
$TheId = $result[$i]['Id'];
$TheFunction = $result[$i]['TheFunction'];
$TheSetting = $result[$i]['TheSetting'];
if ($TheSetting == "0"){
echo 'var newsrc'.$TheId.' = "on.jpg";';
}
else{
echo 'var newsrc'.$TheId.' = "off.jpg";';
}
echo 'function changeImage'.$TheId.'() {';
echo 'if ( newsrc'.$TheId.' == "off.jpg" ) {';
echo "document.getElementById('pic".$TheId."').src = '/images/Boff.png';";
echo 'newsrc'.$TheId.' = "on.jpg";';
echo '}';
echo 'else {';
echo "document.getElementById('pic".$TheId."').src = '/images/Bon.png';";
echo 'newsrc'.$TheId.' = "off.jpg";';
echo '}';
echo' $("#HtmlConvo").load("Monitor.php?id='.$TheId.'&Table='.$mytable.'");';
echo '}';
}
echo'</script>';