I have a little problem with my PHP while loop. I am looping out all the available membership packages (and it's details) from my database.
My code is like this:
<?php
while($mp = mysql_fetch_assoc($s)):
?>
<tr class="hover">
<td class="name" width="30%"><?php echo $mp['membershipname']; ?></td>
<td class="price" width="30%">$<span><?php echo $mp['ap_price']; ?></span>/<span><?php echo $mp['duration']; ?></span> days.</td>
<?php if($userdata['membership']>$mp['membershipid']): ?>
<td width="40%" class="purchase"></td>
<?php else: ?>
<td width="40%" class="purchase" >
Pricing
</tr>
<?php endif; ?>
<div style='display:none'>
<div id='inline_content' style='padding:10px; background:#fff;'>
<div style="text-align:center;font-weight:bold">Please select your payment method:</div>
<div style="text-align:center">
<br />
<?php
if($sdata['allow_paypal'] == 1 && $mp['pp_price']>0 && $userdata['paypal']!=""): ?>
<form action="https://www.paypal.com/cgi-bin/webscr" method="post" style="float:left;" >
<input type="submit" name="submit" class="click cblue" value="PayPal - $<?php echo $mp['pp_price']; ?>">
</form>
<?php endif;
if($sdata['allow_alertpay'] == 1 && $mp['ap_price']>0 && $userdata['alertpay']!=""):
//Do not change any input fields, OTHER than return URL (if needed)
?>
<form method="post" name="ap" action="https://www.alertpay.com/PayProcess.aspx" style="float:right;" >
<input type="submit" name="submit" class="click cgreen" value="AlertPay - $<?php echo $mp['ap_price']; ?>" />
</form>
<?php
endif; ?>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$("#upg<?php echo $mp['id']; ?>").colorbox({inline:true, width:"30%",href:"#inline_content"});
});
</script>
<?php endwhile; ?>
As you can see in the above code, I am doing a while loop.
My problem is that the $mp['pp/ap_price'] inside the #inline_content is not looping. It only take the price from the first row. Although, it is looping in the table.
What's the issue here? I tried to do another loop inside the #inline_content, but it didn't work.
HTML IDs should be unique to one DOM element.
You have a DOM element #inline_content for every record in your database query result. Then, when you try to use Javascript to display them all, only one is displayed because they all have the same ID.
HTML and Javascript are not aware of your PHP loop.
Consider using a class attribute instead of an id attribute.
Related
Data disappear when i reload/refresh the form.
My query for getting data..
public function view_detail()
{
$qry=$this->conn->prepare("SELECT * FROM student_detail WHERE Student_Cnic=:search OR Student_Name=:search");
$qry->bindParam(':search',$this->stsearch);
$qry->execute();
return $qry;
}
The form from where i am sending data
<form action="view.php" method="post" id="view_form">
<br>
<label for="">View By Name or CNIC</label>
<input type="text" class="form-control" name="stu-view" id="stu-view" placeholder="Student Name or CNIC"><br>
<input type="submit" name="view-detail" id="view-detail" class="btn btn-success" value="Enroll"><br>
</form>
The form where i am populating data
<?php
include 'header.php';
include 'config.php';
include 'classes.php';
$database=new Database();
$db=$database->getConnection();
$gtstu=new stu_sys($db);
if(isset($_POST['stu-view']))
{
$_SESSION['stusearch'] = $_POST['stu-view'];
if(isset($_SESSION['stusearch'])){
$gtstu->stsearch = $_SESSION['stusearch'];
}
}
$fth = $gtstu->view_detail();
?>
<div class="row">
<div class="col-lg-12">
<div class="col-lg-2"></div>
<div class="col-lg-8" style="margin-top: 10%;">
<table class="table table-responsive table-bordered">
<th>Image</th>
<th>Name</th>
<th>Cnic</th>
<th>Department</th>
<th>View Detail</th>
<?php while($row = $fth->fetch(PDO::FETCH_OBJ)):?>
<tr>
<td><img src="images/<?php echo $row->Student_Image; ?>" alt=""/></td>
<td><?php echo $row->Student_Name ?></td>
<td><?php echo $row->Student_Cnic ?></td>
<td><?php echo $row->Deprt ?></td>
<td>View More Detail</td>
</tr>
<?php endwhile;?>
</table>
Back TO Dashboard
</div>
<div class="col-lg-2"></div>
</div>
</div>
<?php
include 'footer.php'
?>
i don't know why the form goes empty, mean when i reload the page the data wiped..
Any help will be appreciated.
The form where the data is being populated will never work for one simple reason: You're not including session_start(); at the top of your code. So on page refresh, the sessions are destroyed.
My mistake: I forgot to add session_start() on top of page.
if(isset($_POST['stu-view']))
{
$_SESSION['stusearch'] = $_POST['stu-view'];
}
// Move this out
if(isset($_SESSION['stusearch'])){
$gtstu->stsearch = $_SESSION['stusearch'];
}
I would assume that you are not resending the data in the form. So you are not getting the data from session because you only look at session if the data is sent,
Assuming you are talking about the form you are "sending data from", you should add a value attribute to the textbox (stu-view) and populate it with the submitted search value i.e. add:
value="<?php echo $_SESSION['stusearch']; ?>"
I need to apply WHERE status!='disable' in my php code at $result after I click on the checkbox and then on uncheck of the checkbox it should be removed again and both enable and disable datas from MySql should be shown in the php, is that possible without using AJAX codes, if it is then how can I do that. Can anyone find where am I going wrong
Checkbox, code given below:
<h4 id="CATEGORIESfilters">Availability</h4>
<table border="0" cellspacing="0" id="Availabilitytable">
<tr>
<td>
<input type="checkbox" name="Availability" id="Availabilitycheckboxexcludeoutofstock" >
</td>
<td>
<label for="Availabilitycheckboxexcludeoutofstock">Exclude Out Of Stock</label>
<td>
</tr>
</table>
Php Code is given below:
<?php
include "db_connection.php";
if(isset($_REQUEST['Availability']))
{
$availability="WHERE status!='disable'";
}
else
{
$availability="";
}
$result = mysql_query("SELECT * FROM burger $availability ORDER BY product_no_id DESC");
while($data=mysql_fetch_array($result)):
if($data['status']=="enable")
{
?>
<div class="productwrap">
<div id="Instockwrap">
In Stock
</div>
</div>
<?php
}
else
{
?>
<div class="productwrap">
<div id="Outofstockwrap">
Out Of Stock
</div>
</div>
<?php
}
endwhile;
?>
you can add a class to the out of stock items and hide them via jquery if checkbox is checked, so you dont have to reload the page on checkbox changes
I'm running into a strange scenario involving a widget and the lay-out. I've created a layout that overrides the original column 2 lay-out. It calls a widget in the file and in that widget display a table on the side-bar of some information that I would like to show the user. The layout sidetable.php looks like this
<?php $this->beginContent('//layouts/main'); ?>
<div class="row-fluid">
<div class="span3">
<?php
$this->widget('ListSummaryWidget', array('totaldue'=>$totaldue));
?>
<table class="table">
</table>
</div><!-- sidebar span3 -->
<div class="span9">
<div class="main">
<?php echo $content; ?>
</div><!-- content -->
</div>
</div>
<?php $this->endContent(); ?>
Now all this works - displaying a datatable on the left hand column of the screen. However, something strange happens. Whenever I git rid of
<table class="table">
</table>
The whole view breaks - showing a ridiculous structure/layout that doesn't look much at all like the original. This is confusing/intriguing. In my widget I declare the exact same table and yet it does not seem to matter that I declare this table. Here is the code for my widget's view
<table class="table list_summary table-bordered">
<form action="<?php echo Yii::app()->createUrl('recipient/processpayment', array('id'=>$id)) ?>" method="post" >
<tr class="primary"><td> <h4>List Summary </h4> </td></tr>
<tr ><td>
<?php echo $numpeople; ?> Recipient(s)
</td></tr>
<tr ><td>
Total Due: <?php echo $totaldue ?> Rwf
</td></tr>
<tr> <td>
<h4> Mobile Money Accounts: </h4>
<?php
/*
foreach($accounts as $account)
{
echo $account->name; ?>: <?php echo $account->balance; ?> Rwf<br> <?php
}
*/
?>
</td> </tr>
<tr> <td>
<button class="btn btn-block btn-primary " type="submit">Pay Now</button> </td> </tr>
</td></tr>
</form>
Could anyone explain why this is happening? Though it's not the worst thing in the world - I'm really intrigued as to why I'm required to have some html when I have the same html in the widget's view.
Resolved:
I didn't end the table in my widget. I should have added at the end
</table>
i'm working on a form in php mysql. so in my page there is a form and below that i shown the data of that form in table format.now i want to print only the table structure thats why i just made a PRINT button as:
<span style="float:right;">PRINT</span>
but it will print the whole page with form field and table and i just want the tableto print.
Here is the design of my whole page with form and table:
<html>
<head></head>
<body>
<div class="container">
<form class="form-horizontal" action="" method="post" name="userform1" id="company-form" enctype="multipart/form-data">
<?php if($_GET[id]){?>
<fieldset>
<legend>Add Company</legend>
<div class="control-group">
<label class="control-label">Company Name</label>
<div class="controls">
<input type="text" name="company" id="company" value="<?php echo $selup['company']?>">
</div>
</div>
<div class="control-group">another field</div>
<div class="control-group">another field</div>
<div class="control-group">
<div class="controls">
<button type="submit" class="btn" name="submit" id="submit" value="Submit">Submit</button>
</div>
</div>
<table class="table table-bordered">
<tbody>
<tr>
<td>S.No.</td>
<td>Company Name</td>
<td>Type</td>
<td>Action</td>
</tr>
<?php
// to print the records
$select = "select * from company where type='Miscellaneous'";
$query1 = mysql_query($select);
while($value = mysql_fetch_array($query1)){ ?>
<tr>
<td><?php echo $value[id];?></td>
<td><?php echo $value[company ];?></td>
<td><?php echo $value[type];?></td>
<!--<td> </td>-->
<?php /*?><td><?php echo $value[amount];?></td>
<td><?php echo $value[date];?></td><?php */?>
<td><i class="icon-edit"></i>
<i class="icon-trash"></i></td>
</tr><?php }?>
</tbody>
</table>
</fieldset>
<form>
</div>
</body>
so i just want to print the table not whole page.
Use css to hide elements you don't want to print:
#media print {
.control-group {
display: none;
}
}
function printContent(el){
var restorepage = document.body.innerHTML;
var printcontent = document.getElementById(el).innerHTML;
document.body.innerHTML = printcontent;
window.print();
document.body.innerHTML = restorepage;
}
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>My page</h1>
<div id="div1">DIV 1 content...</div>
<button onclick="printContent('div1')">Print Content</button>
<div id="div2">DIV 2 content...</div>
<button onclick="printContent('div2')">Print Content</button>
<p id="p1">Paragraph 1 content...</p>
<button onclick="printContent('p1')">Print Content</button>
</body>
</html>
You could make a print-css (which does the same as #media print, but I think it is cleaner, and you can disable the css include via javascript, if you need it):
<link rel="stylesheet" type="text/css" href="print.css" media="print" />
In that css, you hide all elements which should not get printed, for example:
.wrapper, .header {display: none;}
One posible solution, perhaps not the best option:
1. Open a new window with JS
2. Copy the whole table into the new window (with jQuery for example)
3. Print the new window
4. Close the window
Sure it has a blink effect but It will work.
i have this code:
<body>
<div class="header">
<?php if (isset($_SESSION['user_id']) && !isset($menu)) { ?>
<div class="menu_holder">
<ul>
<li>
<a href="<?php echo ADDRESS; ?>menu.php" class="green_link">
<img src="<?php echo IMAGES; ?>template/menu.gif" width="51" height="20" border="0" />
</a>
</li>
</ul>
</div>
<?php } ?>
<?php
if (!isset($plainHeader))
{
$plainHeader = " ";
?>
<img src="<?php echo IMAGES; ?>template/logo.gif" width="160" height="94" />
<?php
}
?>
</div>
<br/>
<?php $id_to = $user['profile_id_contact']; ?>
<div class="main_content">
<center>
<div class="innerContainer">
<span class="headings2">FREE CHAT CONTACTS</span>
<form id="message_area" style="display:none" method="post" action="<?php echo ADDRESS; ?>messageSent.php?id=<?php echo $id_to ?>">
<?php
if (count($users) > 0)
{
foreach ($users as $user)
{
//some php here
?>
<a href="#" class="charcoal_link" style="line-height: 20px;" onclick="showMessageArea(this); return false;" >
<?php echo $uniqueCode1?><span class="pink_text"><?php echo $uniqueCode2?></span><?php echo $uniqueCode3?>
</a>
<textarea name="message" rows="10" cols="20"></textarea>
<input name="Submit" type="submit" value="Send"></input>
<?php
}
}
?>
</form>
</div>
</center>
</div>
</body>
as my code is now the form tag is in the wrong place because my tag links does not show.
where must i put my form tag so that when i click on any of the uniquecode links i pass the correct $id_to in the action??? when i move the form tag after the my links show but regardless of which link i click on it passes the first link's $id_to with the action. i have also tried to pass $id_to as a hidden field which i had after the sumbit but still it passes the first link's id
please help? i have been struggeling with this for some time now...i cannot redirect the page via JS becuase this site is for a MOBILE aka mobi site
please help? im desperate
thank you
if i move the form tag and have it like this:
messageSent.php?id=">
and i view the page source $id_to contains correct id but as sson as i go to sentMessage.php the id in the url is incorrect
To pass a id to the next page in a link you need to add "?id='.$id.'" at the end of the url.
e.g.
<a href="<?php echo ADDRESS; ?>menu.php?id=5" class="charcoal_link" style="line-height: 20px;">
To make sure that each link is different you can right click and copy the url to double check.