jQuery with php variable - php

i'm having troubles getting this code to work.
I wanna try and get the info from the database( which works) and put it inside some buttons, and then, when clicking each button i wanna make another 2 divs visible from the same table.
The problem is that only the first button has the fade animation but when clicking the next ones nothing happens. I don't really know how to make each and every one of the buttons have the fade thing effect.
Please help !
$outputList .= '
<div align="center">
<table width="750" border="0">
<tr>
<td><table width="300" border="0">
< tr>
<td width="300" valign="top" id="parent" heith="25px">' . $titlu . '
</tr>
</table>
</td>
<td><table width="750" border="0">
<tr class="dar" width="300" height="auto" id="descript" border="0">
<td>' . $descriere. '</td>
</tr>
<tr>
<td class="dac" width="750" height="700" id="video">Video<img src="images.png" width="430" height="157" /></td>
</tr>
</table>
</td>
</tr>
</table>
</div>';
}
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js">
</script>
<script language="javascript" type="text/javascript">
$(document).ready(function() {
$(".button").click(function () {
if ($(this).next().is(":hidden")) {
$(this).next().slideDown("fast");
} else {
$(this).next().hide();
}
});
});
</script>
<div>
<?php echo "$outputList"; ?>
</div>

Related

Automatize PHP include [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
i am looking for a way to automatize my php script, it should search for php files in a folder called SUBPAGES and include the php files with the Help of a Dropdown like my example but without recoding it everytime i add a new file.
It should find the files stored in the SUBPAGES folder by itself and include the selected file automatized.
Can any one please help me in solving it.
<html>
<body topmargin="0" leftmargin="0" rightmargin="0" bottommargin="0">
<div align="center">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="100%">
<tr>
<td align="center">
<table border="0" cellspacing="0" cellpadding="0" width="" height="">
<tr>
<td width="300" height="50" bgcolor="#F2F2F2">
<p align="center">
<form name="form">
<p align="center">
<select name="link" SIZE="1" onChange="window.location.href = document.form.link.options[document.form.link.selectedIndex].value;">
<option value="#" style="display:none">Choose</option>
<option value="index.php?id=page1"> Seite1 </option>
<option value="index.php?id=page2"> Seite2 </option>
</select></p>
</form>
</td>
</tr>
<tr>
<td height="20" bgcolor="#999999"> </td>
</tr>
<tr>
<td height="350">
<?php
error_reporting(0);
switch($_GET['id']) {
default:
include('Subpages/page1.php');
break; case "page2":
include('Subpages/page2.php');
}
?>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</body>
</html>
Simple way. firstly check the type of security, after include
$page = 'Subpages/page'.settype($_GET['id'],'integer').'.php' ;
$defaultpage = 'Subpages/page1.php' ;
if (file_exists($page)) {
include($page);
}else{
include($defaultpage);
}
It's more easy with jquery and the load function. You only need to read the value of the selected option and load the file that you need
<div align="center">
<table border="0" width="100%" cellspacing="0" cellpadding="0" height="100%">
<tr>
<td align="center">
<table border="0" cellspacing="0" cellpadding="0" width="" height="">
<tr>
<td width="300" height="50" bgcolor="#F2F2F2">
<p align="center">
<form name="form">
<p align="center">
<select name="link" SIZE="1">
<option value="#" style="display:none">Choose</option>
<option value="page1"> Seite1 </option>
<option value="page2"> Seite2 </option>
</select>
</p>
</form>
</td>
</tr>
<tr>
<td height="20" bgcolor="#999999"> </td>
</tr>
<tr>
<td height="350" id="result"></td>
</tr>
</table>
</td>
</tr>
</table>
</div>
<script src="//code.jquery.com/jquery-1.11.3.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script>
$('select').on('change', function() {
$( "#result" ).load( "Subpages/" + $(this).val() + ".php" );
});
</script>
</body>

Can't submit data in textarea

This is my code, I'm trying to get data inside #download div and submit it to other file test2.php
Don't worry it is just table inside #download
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<form action="test2.php" method="post">
<textarea style="" id="file" name="file"></textarea>
<input type="submit">
</form>
<script>
$(document).ready(function(e) {
var html=$('#download').html();
$('#file').val(html);
});
</script>
<div id="download">
<div id="content">
<table border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td colspan="7" id="info"></td>
</tr>
<tr>
<td colspan="7" id="info_space"></td>
</tr>
<tr>
<td valign="top" class="sirinaStupca"><!-- 1. STUPAC -->
</tr>
</table>
</div>
</div>
Other file just needs to echo it, for testing purpose, but it throws me an error: Error 404
Unable to resolve the request "test2.php". When I put normal text or css() instead of table it is working. I can't figure it out why.
if(isset($_POST["file"]))
{
echo $_POST["file"];
}

Only first row from sql query is displaying

My trying to show product desc in pop up. Mean when i click on product link then one pop up will open and show product desc. but here something is wrong. every product link showing first product desc. My code is Below. Please help me out.
Javascript:
<script language="JavaScript">
function displayPopup(alert_MSG)
{
var theDetail = document.getElementById('flyBox');
theDetail.style.display="block";
}
function closePopup(alert_MSG)
{
var theDetail = document.getElementById('flyBox');
if (theDetail.style.display=="block")
{
theDetail.style.display="none";
}
}
</script>
HTML:
View larger
<div id="flyBox" style="display:none;">
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="borderWindow">
<div class="container">
<div id="closeButton"><img src="http://i1122.photobucket.com/albums/l523/Long_Islander/flyBoxClose.png" width="28" height="28" alt="Close Button" border="0" /></div>
<div class="content">
<table width="600" border="0" cellspacing="20" cellpadding="0">
<tr>
<td>
<div id="myMessageBox" name="myMessageBox">
<table width="100%" border="0" cellspacing="2" cellpadding="0">
<tr>
<td class="colheadingL"><font color="white">Description</font></td>
</tr>
<tr>
<td ><?php echo $img; ?></td>
<td>Book Name:</td>
<td ><?php echo $row['pname']; ?></td>
<td class="text1">MRP:</td>
<td><?php echo $row['price'];?> </td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</div>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
But pop up is open click on hyperlink. but problem is showing only 1'st record in all product
You don't have loop any in your template script, that is why you see just one record vizualized.
I don't know exactly how your code is organized outside of the snippet you have posted, but assuming your data rows are in $rows array variable, the code will look something like that:
<? foreach($rows as $row) { ?>
<tr>
<td ><?php echo $img; ?></td>
<td>Book Name:</td>
<td ><?php echo $row['pname']; ?></td>
<td class="text1">MRP:</td>
<td><?php echo $row['price'];?> </td>
</tr>
<? } ?>
Try to make IDs of each DIV as Unique.
Below is the sample code, try to use it as per your requirement
<script language="JavaScript">
function displayPopup(id)
{
var theDetail = document.getElementById(id);
theDetail.style.display="block";
}
function closePopup(id)
{
var theDetail = document.getElementById(id);
if (theDetail.style.display=="block")
{
theDetail.style.display="none";
}
}
</script>
<?php for($i=0;$i<4;$i++){?>
<div>
View larger
<div id="flyBox_<?php echo $i;?>" style="display:none;">
<div id="closeButton"><img src="http://i1122.photobucket.com/albums/l523/Long_Islander/flyBoxClose.png" width="28" height="28" alt="Close Button" border="0" /></div>
<table width="100%" height="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<?php echo "Div ".$i. " Content comes here";?>
</td>
</tr>
</table>
</div>
</div>
<?php }?>

how to update all the input form data based from session in one hit submit?

I have this shopping cart page, wherein, it displays the products + price and their quantities
now my problem is, I dunno how to make the total number of items and price updated, once I input a different number of quantity and hit update button
here's my function that "lists" the products based from the $_SESSION data
public function getCartListings(){
if (is_array($_SESSION['cart'])){
foreach($_SESSION['cart'] as $id => $qty){
$query = "SELECT * FROM gg_t_wsproducts WHERE ProductID = $id";
$result = mysql_query($query);
if (!$result){
echo "Couldn't execute query: ".mysql_error();
exit;
}
$product = $this->getProduct($id);
echo '<div class="cart-content">
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr>
<td width="20%" align="center" style="vertical-align:top !important;">
<img src="images/shopping-cart/thumb-image.png" />
</td>
<td width="80%" style="vertical-align:top !important;">
<table width="100%" cellpadding="0" cellspacing="0" border="0" style="border-bottom:2px solid #c6c6c6; padding-bottom:10px">
<tbody>
<tr>
<td width="60%"><b style="font-size:18px">'.$product["ProductName"].'</b></td>
<td width="20%">Qty <input id="proditem" name="'.$id.'" type="text" style="width:20px; margin:0 0 0 4px;" value="'.$qty.'"></td>
<td width="20%"><span style="font-size:24px; font-weight:bold;">$'.number_format($product['ProductOverridePrice'],2).'</span></td>
</tr>
</tbody>
</table>
<table width="100%" cellpadding="0" cellspacing="0" border="0">
<tbody>
<tr>
<td width="50%" valign="bottom" align="left"><br>
<span style="font-size:18px; font-weight:bold;">$'.number_format($product['ProductOverridePrice'],2).'</span><br>
<img src="images/shopping-cart/star.png" /> <img src="images/shopping-cart/star.png" /> <img src="images/shopping-cart/star.png" /> <img src="images/shopping-cart/star.png" /> <img src="images/shopping-cart/star.png" /><br>
<span style="font-size:12px; color:#828282;">14 reviews</span>
</td>
<td width="50%" valign="bottom" align="right">
<a class="removefromcart" name="'.$id.'" id="'.$qty.'" href="#"><img src="images/shopping-cart/remove-item-btn.png" border="0" /></a>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
</tbody>
</table>
</div>';
}//end foreach
}
}
As you can see above, the items are coming from the foreach loop
here's the front-end code that display the actual items
<div id="catalog-wrapper">
<form action="#" method="POST" id="updatecart">
<h1 class="cart-header">ITEMS IN YOUR CART <span style="float:right"><input type="image" name="updatecart" src="images/shopping-cart/update-cart-btn.png" border="0" /> <img style="float:right;" src="images/shopping-cart/continue-shopping-btn.png" border="0" /></span></h1>
<?php $myCart->getCartListings(); ?>
</form>
</div>
and now, here's the "useless" jquery code i have
$('input[name="updatecart"]').click(function(){
var pid = $('input#proditem').attr('id');
var qty2 = $('input[type="text"]').each(function(idx,elem){
});
$.ajax({
type: "POST",
url: "classes/ajax.cartupdate.php",
data: "pid="+pid+"&qty2="+qty2,
success: function(data){
alert(data);
location.reload();
}
});
return false;
});
the ajax PHP code should have been something like this...but am still having a problem with those codes above..not really sure what to do
if ($qty2){
$cart->updateCart($qty2);
$_SESSION['total_items'] = $cart->totalItems($_SESSION['cart']);
$_SESSION['total_price'] = $cart->totalPrice($_SESSION['cart']);
echo "cartUpdated!";
}
Why you are getting multiple variables? Just get one array and explode it on server side with PHP. I mean, create a javascript array and include every input value in it and then send it to PHP. But in your code there will be two array, no problem. It would like this:
pid="1,2,3,4,5,6,7"+&qtty="0,1,1,0,1,1,0"
Get this values with PHP and explode them to "," and do whatever you want with for loop. By the way, if you will reload the page after sending, then why you are using the ajax method?

put link on table row or any other way to put link

i have one php code for button creation
for($i=1;$i<=$n;$i++)
{
$row=mysql_fetch_array($result);
if($row['btn_color']==1)
$btbg="side-button5.png";
if($row['btn_color']==2)
$btbg="side-button6.png";
if($row['btn_color']==3)
$btbg="side-button7.png";
if($row['btn_color']==4)
?>
<br>
<table width="200" height="50" border="0" cellpadding="0" cellspacing="0">
<tr>
<td background="images/<?php echo $btbg ; ?>" style="background-repeat:no-repeat"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td height="66">
<div align="center" class="buttonside">
<p>
<a class="buttonside" href="vpa.php?pgid=<?php echo $row['page_id']; ?>">
<?php echo $row['btn_text']?></p>
</a>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
<?php
}
?>
this code is working fine but the link is on text, i want to put link on full button(background)
Thanks
To make the button 'linkable', you'll need to wrap the <a> tag around it.
However, you're going to need to change your HTML markup structure - you can't wrap an anchor around a table cell!

Categories