this code is not working to display data from mysql using php and angularjs
html code -
<div class="container" ng-app="shoppingcart"
ng-controller="shoppingcartcontroller"> <div class="row " >
<div class="box col-md-3" style="margin-top: 20px;" ng-repeat="p in
products">
<div style="border: 1px solid #ccc; background-color: #f4f5f6">
<img src="/images/{{p.image}}.jpg" class="img img-responsive">
<h3>{{p.name}}</h3>
<h3>{{p.price}}</h3>
</div> </div>
</div> </div>
angular code -
<script >
var app=angular.module("shoppingcart",[]);
app.controller("shoppingcartcontroller",function($http,$scope){
$scope.loadproduct=function(){
$http.get("fetch.php").success(function(data){
$scope.products=data;
});
};
});
</script>
A simple example
HTML
<div ng-repeat="p in products">
{{p.name}}
{{p.price}}
</div>
JS
var app=angular.module("shoppingcart",[]);
app.controller("shoppingcartcontroller",function($http,$scope){
$scope.loadproduct=function(){
$http.get("fetch.php").then(function(response){
$scope.products=response.data;
});
};
});
Related
I have tried
<?php session_start(); ?>
.
.
.
<p><?php $_SESSION['loggeduser']; ?>;</p>
I have also tried this JS after the
<script type="text/javascript">
let vuser = '<%= session.getAttribute("loggeduser") %>';
document.getElementById("userid").value= "Not set";
</script>
If someone can tell me what am I doing wrong please!
This is my full body code:
<body>
<section id="MyHeader" style="border:solid red thin;">
<div id="TheHead" style="width:80%; display:inline-block;">
<div id="HeadImg" style="width: 100px; height:100px;">
<a href="main.html">
<img src="../images/icon-redcross.png" alt="AGR">
</a>
</div>
<div id="HeadLegend">
<div id="AGRbrand"><h1>AGR</h1></div>
<div id="quote">
<span style="font-size: small;"><i>Properties catalogue</i></span>
</div>
</div>
</div>
<div id="user" style="display:inline-block; width:12%; height:25px;">
<p id="userid" style="width:100%;"><?php $_SESSION['loggeduser'];?></p>
<script type="text/javascript">
let vuser = '<%= session.getAttribute("loggeduser") %>';
document.getElementById("userid").value= "Not set";
</script>
</div>
<div style="width:100%; display:block;">
<div id="MenuButtons" style="width:80%; display:flex; justify-content:right;">
<div id="newbtn" class="TopButton">New</div>
<div id="exitbtn" class="TopButton">Exit</div>
</div>
</div>
<div class="Subtitle">
<div style="display: flex; justify-content: left; width:100%;">
<h4>Properties</h4>
</div>
</div>
</section>
<div id="Estates" class="pagebreak"></div>
<section id="MyPage">
<div id="Home"></div>
<div class="page" style="width:100%; background-color: white; ">
<div style="display: flex; justify-content:center; width:100%;">
<div class="ServiceBox">
<div class="div-img">
<img src="../../images/house-B.png" alt="AGR">
</div>
<div class="div-info">
</div>
<div class="div-desc">
</div>
<div class="div-btns">
<a class="SideButton" href="Edit.html">Edit</a>
<a class="SideButton" href="Delete.html">Delete</a>
<a class="SideButton" href="pdf-file.html">Pdf</a>
</div>
</div>
</div>
</div>
</section>
</body>
Notes: $_SESSION["loggeduser"] is populated before this page,at the login page; I verified the variable was properly set by a log file I have, and I was able to see the value printed in the log, after the user logs in and before this page is loaded.
Not sure if it is the php version or the goDaddy servers, but in my case the problem was, I was using html extension for the files, I changed them to .php extension and the php code started to work.
This is continuation of my question first question
Here i am drag and drop sticky notes from one to another. i have
<div class="rTable">
<div class="rTableRow">
<div id="a" title="Backog" class="rTableHead rTabletd"><strong>Backlog</strong></div>
<div id="a" title="WIP" class="rTableHead rTabletd"><span style="font-weight: bold;">WIP</span></div>
<div id="a" title="Testing" class="rTableHead rTabletd">Testing</div>
<div id="a" title="DOD" class="rTableHead rTabletd">DOD</div>
</div>
<div class="rTableRow rTableh" >
<div class="rTableCell"></div>
<div class="rTableCell"><a></a></div>
<div class="rTableCell"></div>
<div class="rTableCell"></div>
</div>
</div>
and sticky notes
<?php
foreach ($this->getallstores as $stories):
?>
<div id="draggable-<?php echo $stories['id']; ?>" class="draggable " onchange="javascript:position(this)" style="position:absolute; left: <?php echo $stories['_left']; ?>px; top: <?php echo $stories['_top']; ?>px">
<img class="pin" src="/manage/public/img/pin.png" alt="pin" />
<blockquote class="quote-box note-<?php echo $stories['color']; ?>">
<p class="quote-text" id="content-<?php echo $stories['id'];?>">
<?php echo $stories['message']; ?>
</p>
<hr>
<div class="blog-post-actions">
<p>
<button class="btn btn-primary popEdit pull-left" data-toggle='tooltip' title="Edit" onClick="popOverEdit(<?php echo $stories['id'];?>)" id="pop-<?php echo $stories['id'];?>"><span class="glyphicon glyphicon-edit"></span></button>
<div class="popover-markup blog-post-bottom" >
<div class="head hide">Edit</div>
<div class="content hide" id="popoverContent<?php echo $stories['id'];?>">
<div class="form-group">
<textarea id="<?php echo $stories['id']; ?>" class="quick" ><?php echo $stories['message']; ?></textarea>
</div>
<button data-vendor-id="" data-act="send" onClick="getText(<?php echo $stories['id'];?>)" class="btn btn-info save_notes">Save</button>
</div>
</div>
</p>
<p class="blog-post-bottom pull-right">
<a class="delete" href="?delete=<?php echo $stories['id']; ?>" style="float:right"> <button class="btn btn-danger" title="delete"><span class="glyphicon glyphicon-trash"></span></button> </a>
</p>
</div>
</blockquote>
</div>
<?php endforeach;?>
demo
my requirement is i want to drag and drop stickys and save to database.Now i have save position.is there any way to save column name?eg if drag sticky note from backlog to testing how can i get placed position name is testing?Please help me.
jquery
jQuery(function() {
jQuery( ".draggable" ).draggable({ containment: "#containment-wrapper", scroll: false ,
// Find position where image is dropped.
stop: function(event, ui) {
// Show dropped position.
var id=$(this).attr('id');
var ti=$(".rTabletd").attr("title");
var Stoppos = $(this).position();
model = {
id:id,
left: Stoppos.left,
top: Stoppos.top
};
$.ajax({
url: "/scrum/save",
type: "post",
data: model,
success: function(data){
jQuery.HP({
title: "Success!",
message: "Saved..."
});
},
error:function(){
// alert('error is saving');
}
});
}
});
});
You can create an array and use the droppable index position to select the array value.
var table = ['Backlog', 'WIP', 'Testing', 'DOD'];
$(".rTableCell > div").draggable();
$(".rTableCell").droppable({
drop: function(event, ui) {
var table = ['Backlog', 'WIP', 'Testing', 'DOD'];
var droppedOn = event.target;
alert(table[$(droppedOn).index()]);
}
});
.rTableHead,
.rTableCell {
display: inline-block;
width: 23%;
}
.rTableCell {
border: 1px solid black;
height: 100vh;
}
.rTableCell>div {
background-color: blue;
padding: 5px;
color: white;
border-radius: 5px;
margin: 5px;
cursor: pointer;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script src="https://code.jquery.com/ui/1.12.0/jquery-ui.js"></script>
<div class="rTable">
<div class="rTableRow">
<div id="backlog" title="Backog" class="rTableHead rTabletd"><strong>Backlog</strong></div>
<div id="WIP" title="WIP" class="rTableHead rTabletd"><span style="font-weight: bold;">WIP</span></div>
<div id="TESTING" title="Testing" class="rTableHead rTabletd"><span style="font-weight: bold;">Testing</span></div>
<div id="DOD" title="DOD" class="rTableHead rTabletd"><span style="font-weight: bold;">DOD</span></div>
</div>
<div class="rTableRow rTableh">
<div class="rTableCell">
<div>
Item 1
</div>
</div>
<div class="rTableCell">
<div>
Item 2
</div>
</div>
<div class="rTableCell">
<div>
Item 3
</div>
</div>
<div class="rTableCell">
<div>
Item 4
</div>
</div>
</div>
</div>
I'm trying to convert my html template into a php script that simply takes returned database values and uses comparisons on certain values to place the correct content in the placeholders.
The data is being returned properly and is showing on the page but my html formatting is breaking.
This should output a very simple format of a container row, 2 half-width columns each of which with its own internal div like this:
<div class="row middle">
<div class="col-lg-6 leftFifty">
<div class="leftContent" style="background-color: white; height: 100%; ">
Content
</div>
</div>
<div class="col-lg-6 rightFifty">
<div class="rightContent" style="background-color: white; height: 100%; ">
Content
</div>
</div>
</div>
But when I add in the PHP conditions it breaks the format completely including anything included after this section
<div class="row middle">
<?php foreach($panelResult as $PR): ?>
<div class="col-lg-6 leftFifty">
<?php if($PR['panel_type_id'] == 2){ ?>
<div class="leftContent" style="background-color: white; height: 100%; ">
<?php echo $PR['content']?>
</div>
</div>
<div class="col-lg-6 rightFifty">
<?php } elseif($PR['panel_type_id'] == 3){?>
<div class="rightContent" style="background-color: white; height: 100%; ">
<?php echo $PR['content'] ?>
</div>
<?php } ?>
</div>
<?php endforeach; ?>
</div>
<!--This div is not showing-->
<div class="row bottom">
<div class="col-lg-12">
<div class="marquee"><h2>This is a test</h2></div>
</div>
</div>
For this page type, row-middle should exist, and both the leftFifty/leftContent class as well as the rightFifty and rightContent class should all exist.
The only reason I'm using the If statement is to make sure that the panel_type_id ==2 content fills the left div, and same for the right div if it equals 3.
How can I restructure this to retain the html formatting?
I wanna make like system that system suggest books to user with JQuery and user like it.
First, at index.php has 2 suggested book. And there is no problem. User can click Like Button. And new book is uploaded insted of liked book. But user can not click the button. The page can not connect functions.js page.
My codes is:
At index.php
<!-- Suggest book -->
<div class="book-box" id="<?php echo $book_id;?>" style="background: #fff;box-shadow: 0 0 1px 1px rgba(0,0,0,.2); min-height: 60px;margin-bottom: 10px!important;bg-444;" data-target="<?php echo $book_id;?>">
<img src="img/<?php echo $ki_image;?>" style="width:100%; height: 150px;padding:0;" alt="">
<div class="container-fluid" style="">
<div class="row" style="">
<div class="caption mt5 p5" style="">
<div class="col-md-12 p0"><strong style="color: #1198BF; cursor: pointer;"><?php echo min_val($book_name,40);?></strong></div>
<div class="col-md-6 mt10" style="font-size: 13px;color: #777;margin-right: 30px;padding: 0;">
<p>2 dostun - 500 nəfər buradadır</p>
</div>
<div class="join " style="margin-top: 10px;float: left;">
<button name="btn_book" class="suggested_join_book" style="font-size: 12px; border-color: #ccc; outline: none; border-radius: 2px; padding: 5px 7px; box-shadow: 0 0 1px 1px rgba(0,0,0,.3); border: none;" data-id="<?php echo $book_id;?>">Abunə ol</button>
</div>
</div>
</div>
</div>
</div>
<div class="clb"></div>
<!-- Finish SuggestBook -->
functions.js is:
$(".suggested_join_book").on("click",function(){
var book_id = $(this).data("id");
$.ajax({
type: "post",
url : "join_book.php",
data: {"book_id":book_id},
success: function(veri){
// $("[data-target="+book_id+"]").addClass('animated fadeOut');
$("[data-target="+book_id+"]").css('display','none');
// $("#"+book_id).load("ajax.php?bol=new_book");
$.ajax({
type: 'post',
url: 'ajax.php?bol=new_book_2',
data: {"userID":'15'},
success: function(arr){
$(".suggest").append(arr);
}
});
}
});
});
ajax.php is:
case "new_book_2":
$userID = $_POST['userID'];
foreach (new_book_2($userID) as $nb) {
$book_name = $nb["ki_name"];
$ki_image = $nb["ki_image"];
$book_id = $nb["ki_id"];
if($ki_image == ""){$ki_image = 'noprofile.jpg';}
?>
<!-- Suggest book -->
<div class="book-box " id="<?php echo $book_id;?>" style="background: #fff;min-height: 83px;margin-bottom: 10px!important;bg-444" data-target="<?php echo $book_id;?>">
<?php
?>
<img src="img/<?php echo $ki_image;?>" style="width:100%; height: 222px;padding:0;border-top-left-radius: 4px;border-top-right-radius: 4px;" alt="">
<div class="container-fluid" style="">
<div class="row" style="">
<div class="caption mt5 p5" style="">
<div class="col-md-12 p0"><strong style="color: #1198BF; cursor: pointer;"><?php echo min_val($book_name,40);?></strong></div>
<div class="col-md-7 mt10" style="font-size: 13px;color: #777;margin-right: 8px;padding: 0;">
<p>2 dostun - 500 nəfər buradadır</p>
</div>
<button name="btn_book sonradan" class="btn btn-primary join_book" data-id="<?php echo $book_id;?>">Abunə ol</button>
</div>
</div>
</div>
</div>
<div class="clb"></div>
<!-- Finish SuggestBook -->
<?php
}
break;
May be you include functions.js before your html tags. Put your click event into the jquery's ready method:
$(document).ready(function(){
$(".suggested_join_book").on("click",function(){
var book_id = $(this).data("id");
$.ajax({
type: "post",
url : "join_book.php",
data: {"book_id":book_id},
success: function(veri){
// $("[data-target="+book_id+"]").addClass('animated fadeOut');
$("[data-target="+book_id+"]").css('display','none');
// $("#"+book_id).load("ajax.php?bol=new_book");
$.ajax({
type: 'post',
url: 'ajax.php?bol=new_book_2',
data: {"userID":'15'},
success: function(arr){
$(".suggest").append(arr);
}
});
}
});
});
});
I have a jquery mobile app that I'm using and I'm trying to get the right panel to open. Its for notifications. I have a feeling it has to do with with the ajax and it being done for multiple pages. I have many pages in the document and I have assigned unique id's for each "myContent" div and also for the function toggleDiv. For some reason when I click on the icon to open the panel it does nothing, and if i click it again it will open the panel then immediately close the panel.
Here is my code, any clues as to how this is happening?
<script type="text/javascript">
function toggleDiv(divId) {
$("#"+divId).toggle();
$(document).ready(function(){
$("#myContent").load("getnotes.php?name=<? echo $username; ?>");
});
}
</script>
<!-- BEGIN PAGE 1 -->
<div data-role="page" id="feed" data-add-back-btn="true">
<div data-role="panel" id="settingspanel" data-position="left" data-display="overlay">
<!--LEFT SIDE PANEL CONTENT HERE-->
</div>
<div data-role="header" data-position="fixed" data-theme="c" data-tap-toggle="false" data-id="foo1" style="padding-top: 5px; border-bottom: 1px solid #eccfb3; padding-bottom: 5px;">
<center><img src="images/logo_app_white.png" height="25px"></center>
<!--THIS IS THE BUTTON TO PUSH TO MAKE NOTIFICATIONS APPEAR-->
<? echo $number; ?>
</div>
<div data-role="content">
<!--THIS IS WHERE CONTENT FOR THE PAGE GOES-->
</div>
<div data-role="footer" data-position="fixed" data-theme="c" data-tap-toggle="false" data-id="foo1" style="border-top: 1px solid #eccfb3; padding-top: 5px;">
<div data-role="navbar" style="background: #ce8339;">
<!--ICONS FOR NAVIGATION BAR-->
</div><!-- /navbar -->
</div>
<!--HERE IS WHERE THE NOTIFICATIONS APPEAR-->
<div data-role="panel" id="myContent" data-position="right" data-display="overlay">
</div>
</div>
<!-- END PAGE 1 -->
Get your document ready out of the function. And the toggle() to show().
Change this
function toggleDiv(divId) {
$("#"+divId).toggle();
$(document).ready(function(){
$("#myContent").load("getnotes.php?name=<? echo $username; ?>");
});
}
To this
function toggleDiv(divId) {
$("#"+divId).show();
}
$(document).ready(function(){
$("#myContent").load("getnotes.php?name=<? echo $username; ?>");
});
DEMO