This is my full error:
Warning: Invalid argument supplied for foreach() in C:\xampp\htdocs\bilzar\components\com_blank\views\default\tmpl\default.php on line 14
My code is:
<?php
// Valid execution check
defined('_JEXEC') or die('Restricted Access');
?>
<h1>Blank Component</h1>
<input type="button" class="measure" value="Get New Measurement" />
<table id="thedata">
<thead>
<tr>
<th>Measurement</th><th>Timestamp</th>
</tr>
</thead>
<tbody class="measurements">
<?php foreach($this -> data as $data) : ?>
<?php
$unixTime = strtotime($data->timestamp);
?>
<tr>
<td><?php echo $data->measurement; ?></td><td><?php echo date("d-m-Y H:i:s", $unixTime); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="pagination"><?php echo $this->pagination->getPagesLinks(); ?></div>
<script>
window.addEvent('domready', function() {
$$(".measure").addEvent('click', function() {
var request = new Request.JSON(
{
url: 'http://localapache.dyndns.org/joomla_arduino/index.php/blank/sense/sense/raw',
onSuccess: function(e) {
var tr = new Element('tr', {html: '<td>'+e.measurement+'</td><td>'+e.timestamp+'</td>'});
var element = $('thedata').getElement('tbody');
tr.inject(element, 'top');
}
}).get();
});
/*
*/
});
</script>
<style>
table td { padding: 5px; }
input[type=button] { margin:10px 0;}
.pagination ul { list-style-type:none; }
.pagination ul li { float:left; }
</style>
Can anyone help me how I can fix this error?
Related
I have created a page, it has a select box which is used for filtering the results in a table below it. The select box is using ajax to filter results.The table which is loaded after ajax call has a button in one column, on its click a div should be added in the page. The onclick for this button was working fine when the table was static with static button to add div, now the table is being loaded through ajax the button doesn't work, it doesn't add the div that it was adding before. Can someone point out the problem please, I am a beginner in jquery and ajax
here is my code:
(function ( $ ) {
$(document).ready(function(){
var itemsArr = [];
$(".btn-add").on("click",function() {
var $row = $(this).closest("tr"); // Find the row
var $text = $row.find(".this-name").text(); // Find the text
// Let's test it out
$('#col2').append('<div class="item"><p>'+$text+'</p>X</div>');
itemsArr.push($text);
//alert(itemsArr);
console.log("added");
$("#items").val(JSON.stringify(itemsArr));
});
function getAll(){
$.ajax
({
url: 'http://asp4.walnut-labs.com/getproducts.php',
data: 'action=showAll',
contentType :'application/json',
cache: false,
success: function(r)
{
$("#col1").html(r);
}
});
}
getAll();
// function to get all records from table
// code to get all records from table via select box
$("#brands").change(function()
{
var id = $(this).find(":selected").val();
var dataString = 'action='+ id;
$.ajax
({
url: 'http://asp4.walnut-labs.com/getproducts.php',
data: dataString,
contentType :'application/json',
cache: false,
success: function(r)
{
$("#col1").html(r);
}
});
});
});
$(document).on('click','.delete-button', function(e){
e.preventDefault();
//alert('yes');
$(this).closest('.item').remove();
});
}( jQuery ));
HTML is :
<tbody>
<tr bgcolor="#238efb" color="white">
<td style="text-align: center; color: #fff;"><strong>ID</strong></td>
<td style="text-align: left; color: #fff; padding-left: 15px;"><strong>Item Code</strong></td>
<td style="text-align: left; color: #fff; padding-left: 15px;"><strong>Item Name</strong></td>
<td style="text-align: left; color: #fff; padding-left: 15px;"><strong>Brand</strong></td>
<td style="text-align: left; color: #fff; padding-left: 15px;"><strong>Button</strong></td>
</tr>
<?php
while($row = mysql_fetch_array($comments, MYSQL_ASSOC))
{
$id = $row['id'];
$name = $row['code'];
$level = $row['name'];
$number = $row['brand'];
?><tr>
<td class="this-id" style="text-align: center;"><?php echo $id;?></td>
<td class="this-name" style="text-align: left; padding-left: 15px;"><?php echo $name;?></td>
<td style="text-align: left; padding-left: 15px;"><?php echo $level;?></td>
<td style="text-align: left; padding-left: 15px;"><?php echo $number;?></td>
<td style="text-align: left; padding-left: 15px;"><button class="btn-add">Add Item</button></td>
</tr><?php
}
mysql_close($con);
?>
</tbody>
</table>
For selectbox that triggers AJAX:
<div class="searchbar">
<select name="brands" id="brands">
<option value="showAll" selected="selected">Show All Products</option>
<?php $querybrand = "SELECT DISTINCT brand FROM q1h27_data ";
$commentsbrand = mysql_query($querybrand);
while($row = mysql_fetch_array($commentsbrand, MYSQL_ASSOC))
{
//print_r($row['brand']);?>
<option value="<?php echo $row['brand']; ?>"><?php echo $row['brand']; ?></option>
<?php } ?>
</select>
</div>
Use the following:
$(document).ready(function(){
var itemsArr = [];
$(document).on('click','.btn-add',function() {
// code goes here.....
});
}
I have in defi.php a form with the following AJAX call:
$('#def').submit(function (event) {
var data = $(this).serialize();
$.post('defidos.php', data)
.success(function (result) {
$('#dos').html(result);
})
.error(function () {
console.log('Error loading page');
})
return false;
});
defidos.php has the following table row which contains a check box:
<tr>
<td>
<input type="checkbox" name="seleccion[]" value="<?php echo $id_plantilla; ?>" />
</td>
<td>
<?php echo $faquerynm['cve_plaza']; ?>
</td>
<td>
<?php echo $desc_cat; ?>
</td>
<td>
<?php echo $faquerynm['tiempo']; ?>
</td>
<td>
<?php echo $faquerynm['situacion']; ?>
</td>
<td>
<?php echo $div_areal; ?>
</td>
</tr>
After the call the checkbox is not shown.
If I put the checkbox outside the table it shows correctly.
I solved the problem using css , creating the table with divs .
#container {
display: table;
}
#row {
display: table-row;
}
#left, #right, #middle {
display: table-cell;
text-align: center;
}
.titulos {
font-weight: bold;
}
With this the checkbox shows correctly
in the below code i am searching a data before searching my url will be in coursemaster_site and when i search it will be in coursemaster_site/index1 and when i close the search results the url will be in coursemaster_site /coursemaster_site but i want url to be in coursemaster_site after closing the search results.
controller:coursemaster_site
function index1()
{
$data = array();
$keyword = $this->input->post('keyword');
if($keyword!=""){
$data['results'] = $this->coursemaster_model->search($keyword);
}
$this->load->view('coursemaster_view', $data);
}
view:coursemaster_view
<form action="<?php echo site_url('coursemaster_site/index1');?>" method = "post">
<br/><center>SEARCH:<input type="text" name = "keyword" required/>
<input type="submit" name="submit" id="opn" value = "Search" onClick="hide1('hiddendiv')" class="btn-success btn" /></center>
</form>
<?php
if (isset($_POST['submit'])) { // Here
// Do the search here
if($results){
?> <div id='hideme'>
CLOSE<a href='coursemaster_site' class='close_notification' title='Click to Close'>
<img src="<?php echo base_url('img/close.png'); ?>" width="15" height="15" alt="Close" onClick="hide('hideme')"/>
</a><div style="background:#FFFFFF; width:1000px; height: 540px; position: absolute; left: 20%; top: 35%; margin-left: -100px; margin-top: -120px" id="modal" >
<table class="display2 table table-bordered table-striped" id='results'>
<tr>
<th>course_code</th>
<th>course name</th>
</tr>
<tr><?php
foreach ($results as $row) {
?>
<td><?php echo $row->course_code;?></td>
<td><?php echo $row->course_name;?></td>
</tr>
<?php
}
}else{
echo"<div id='hideme'>
CLOSE<a href='coursemaster_site' class='close_notification' title='Click to Close'>";
echo "<div id='modal' style='background:#FFFFFF; width:1000px; height: 525px; position: absolute; left: 20%; top: 35%; margin-left: -100px; margin-top: -110px'>";
}
echo"no results";
echo'</div>';
echo '</div>'; }
// If closing
?>
</table>
</div></div>
<script>
$('a.modal').bind('click', function(event) {
event.preventDefault();
$('#modal').fadeIn(10);
});
function hide(obj) {
var el = document.getElementById(obj);
el.style.display = 'none';
}
function hide1(obj) {
var el = document.getElementById(obj);
el.style.display = 'none';
}
</script>
Change to:
<div id='hideme'>CLOSE
<a href='/coursemaster_site' class='close_notification' title='Click to Close'>
...
on both places. The leading slash makes the href start from root.
Do the following changes and check if it works or not:
<div id='hideme'>
CLOSE<a href='javascript:void(0);' class='close_notification' title='Click to Close'>";
I have an editable grid where I want to edit the CSS such that the textarea to show the maximum width, but somehow I can't increase the width of the text area.
My database has three columns:
ID
Name
Gossip
I'm retrieving everything and displaying it in an editable grid using PHP.
index.php code
<?php
$db = new mysqli('localhost', 'root', '', 'bollywood');
$db->set_charset('utf8');
if ($db->connect_errno) {
die('Check the database connection again!');
}
$userQuery = 'SELECT Id,Name,Gossip FROM bollywood';
$stmt = $db->query($userQuery);
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="style.css" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
var textBefore = '';
$('#grid').find('td input').hover(function() {
textBefore = $(this).val();
$(this).focus();
}, function() {
var $field = $(this),
text = $field.val();
$(this).blur();
// Set back previous value if empty
if (text.length <= 0) {
$field.html(textBefore);
} else if (textBefore !== text) {
// Text has been changed make query
var value = {
'row': parseInt(getRowData($field)),
'column': parseInt($field.closest('tr').children().find(':input').index(this)),
'text': text
};
$.post('user.php', value)
.error(function() {
$('#message')
.html('Make sure you inserted correct data')
.fadeOut(3000)
.html(' ');
$field.val(textBefore);
})
.success(function() {
$field.val(text);
});
} else {
$field.val(text);
}
});
// Get the id number from row
function getRowData($td) {
return $td.closest('tr').prop('class').match(/\d+/)[0];
}
});
</script>
<title></title>
</head>
<body>
<?php if ($stmt): ?>
<div id="grid">
<p id="message">Click on the field to Edit Data</p>
<table>
<thead>
<tr>
<th>Id</th>
<th>Name</th>
<th>Gossip</th>
</tr>
</thead>
<tbody>
<?php while ($row = $stmt->fetch_assoc()): ?>
<tr class="<?php echo $row['Id']; ?>">
<td><input type="text" value="<?php echo $row['Id']; ?>" /> </td>
<td><input type="text" value="<?php echo $row['Name']; ?>" /></td>
<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
</div>
<?php else: ?>
<p>No actors added yet</p>
<?php endif; ?>
</body>
</html>
user.php code
<?php
// Detect if there was XHR request
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) &&
strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
$fields = array('row', 'column', 'text');
$sqlFields = array('Id', 'Name', 'Gossip');
foreach ($fields as $field) {
if (!isset($_POST[$field]) || strlen($_POST[$field]) <= 0) {
sendError('No correct data');
exit();
}
}
$db = new mysqli('localhost', 'root', '', 'bollywood');
$db->set_charset('utf8');
if ($db->connect_errno) {
sendError('Connect error');
exit();
}
$userQuery = sprintf("UPDATE bollywood SET %s='%s' WHERE Id=%d",
$sqlFields[intval($_POST['column'])],
$db->real_escape_string($_POST['text']),
$db->real_escape_string(intval($_POST['row'])));
$stmt = $db->query($userQuery);
if (!$stmt) {
sendError('Update failed');
exit();
}
}
header('Location: index.php');
function sendError($message) {
header($_SERVER['SERVER_PROTOCOL'] .' 320 '. $message);
}
style.css code
body {
font: normal 14px Comic Sans, Comic Sans MS, cursive;
}
table {
width: 500px;
}
td, th {
border: 1px solid #d8d8bf;
}
th {
padding: 5px;
font: bold 14px Verdana, Arial, sans-serif;
}
td {
padding: 10px;
width: 200px;
}
td input {
margin: 0;
padding: 0;
// width:200px;
font: normal 14px sans-serif;
/** Less flicker when :focus adds the underline **/
border: 1px solid #fff;
}
td input:focus {
outline: 0;
border-bottom: 1px dashed #ddd !important;
}
#grid input {
// width: 200%;
}
You doing it wrong
<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
Should be:
<td ><textarea cols="500" rows="100"><?php echo $row['Gossip']; ?></textarea>
textarea is html tag name but not input type. so change this.
<td ><input type="textarea" cols="500" rows="100" value="<?php echo $row['Gossip']; ?>" /></td>
to
<td ><textarea cols="500" rows="100"><?php echo $row['Gossip']; ?></textarea>
also add this css.
<style>
textarea {
resize: both;
width:700px;
}
</style>
also are you sure that you can get content using this.
<?php echo $row['Gossip']; ?>
So I'm trying to make a "Simple" php + javascript drag and drop, here's my code:
<title>Web Editor</title>
<?php
mysql_connect("$host","$user","$pass");
mysql_select_db("$db");
if(isset($_POST['submit'])){
$name=$_FILES['file']['name'];
$temp=$_FILES['file']['tmp_name'];
move_uploaded_file($temp,"uploaded/".$name);
$url="http://www.bluejayke.com/edit/uploaded/$name";
}
?>
<?php
if(isset($_POST['submit'])){
mysql_query("INSERT INTO uploadedvideos(id,name,url) VALUES('','$name','$url')");
echo "</br>" . $name . " uploaded";
}
$query="SELECT * FROM uploadedvideos";
$result = mysql_query($query);
?>
<div class='wrapper' id='wrapper'>
<table cellpadding="0" cellspacing="0" border="1">
<tr>
<td style="width:400px; height:50px;"><form action="index.php" method="POST" enctype="multipart/form-data">
<input type="file" name="file">
<input type="submit" name="submit" value="Upload">
</form></td>
</tr>
<tr>
<td style="width:400px; height:500px;">
<div style="width:100%; height:100%; overflow:auto; ">
<script src="http://www.google.com/jsapi"></script>
<script>
google.load("jquery", "1");
</script>
<?php
while($row=mysql_fetch_array($result))
{
$id=$row['id'];
$name=$row['name'];
$url=$row['url'];
echo "<div style='position:absolute;cursor:pointer;' id='".$id."'><a href='javascript: click(\"$url\")'>$name</br><embed id='$id' src='$url' width='120' height='120' draggable='true' ondragstart='drag(event)'></embed></a><input type='button' id='delete' value='X' onclick='return Deleteqry($id)' /></div><br> ";
?>
<script type="text/javascript">
var dragging = false
$(function () {
var target<?php echo $id ?> = $('#<?php echo $id; ?>')
target<?php echo $id ?>.mousedown(function() { dragging<?php echo $id; ?> = true })
$(document).mouseup(function() { dragging<?php echo $id; ?> = false })
$(document).mousemove(function(e) {
if(dragging<?php echo $id; ?>){
target<?php echo $id ?>.css('left', e.pageX)
target<?php echo $id ?>.css('top', e.pageY)
}
})
})
</script>
<?php
}
?>
</div>
</table>
</div>
<div class='wactch' id='watching' height='480' width='720'>Loading..</div>
<script>
/*document.onmousemove=mouseMove;
function mouseMove(ev)
{
ev = ev || window.event;
var mousePos=mouseCords(ev);
}
function mouseCords(ev)
{
if(ev.pageX || ev.pageY)
{
return{x:ev.pageX,y:ev.pageY);
}
return
{
x:ev.clientX+document.body.scrollLeft-document.body.clientLeft, y:ev.clientY.document.body.scrollTop-document.body.clientTop
};
}
}*/
function Deleteqry(id)
{
if(confirm("Are you sure you want to delete this picture?")==true)
window.location="index.php?del="+id;
return false;
}
function allowDrop(ev)
{
ev.preventDefault();
}
function drag(ev)
{
ev.dataTransfer.setData("Text",ev.target.id);
}
function drop(ev)
{
ev.preventDefault();
var data=ev.dataTransfer.getData("Text");
ev.target.appendChild(document.getElementById(data));
}
window.onload=function()
{
click("http://www.bluejayke.com/edit/uploaded/dpnewslogo.png");
}
function click(url)
{
document.getElementById("watching").innerHTML='<embed src="'+url+'" width=720 height=480></embed>';
}
</script>
<?php
if($_GET['del']){
$delete_id=$_GET['del'];
mysql_query("DELETE FROM `uploadedvideos` WHERE `uploadedvideos`.`id` = $delete_id");
header("location: index.php");
}
?>
<style type="text/css">
.wrapper
{
width:500px;
overflow: hidden;
float: left;
}
#watching {
float: right;
}
.div1 {width:750px;height:120px;padding:10px;border:1px solid #aaaaaa; oveflow: hidden;}
</style>
The important part is in the while loop. The result of this code is all the divs I made in the while loop are piled up on top of each other, when I want them in a vertical line-like structure. Anyone have any insight on this? It's something with the div's styling I think, but I'm not sure how to resolve it while still keeping the drag and drop function.
Your divs are being positioned absolute. You simply need to change them to position:relative;
http://www.w3schools.com/css/css_positioning.asp