I send the data from the database to the screen with foreach.I do not see any results when I click the button.where do i make mistakes i ask you to help
<table class="table">
<thead class="thead-dark" align="center" >
<th >id</th>
<th >EğitimAdı</th>
<th >Adres</th>
<th >Onay </th>
</thead>
<tbody>
<form id="form1" action="" method="post">
<?php $i=1; foreach($dbb as $ac){ ; ?>
<tr align="center" >
<td > <?php echo $ac[0]; ?> </td>
<td > <?php echo $ac[1]; ?></td>
<td align="center"> <iframe width="360" height="115" src="<?php echo $ac[2]; ?>" frameborder="0" gesture="media" allow="encrypted-media" allowfullscreen ></iframe></td>
<td >
<button type="button" value="<?php echo $ac[0]; ?>" id="gonder" onclick="gonder('this.val()')">İzledim</button>
</td>
</tr>
<?php $i++; } ?>
</form> <p></p>
</tbody>
</table>
gonder.js send to the database
function gonder(deger){
$.ajax({
type:"post",
url:"isleme.php",
data:deger,
success:function(cevap) {
$("p").text(cevap);
}
})
}
isleme.php to view the screen
<?php
$b=$_POST['deger'];
echo $b;
?>
First you're missing parentheses:
onclick="gonder" has to be onclick="gonder()"
Secondly variable "deger" is empty because #id doesn't exist, try changing to:
var deger = $("#gonder").val();
I noticed you are iterating and having same id for all the elements. Ideally id should be unique in each of the document.
You can do either of the below:
prepare and have unique id for each iterative element.
Try removing id element since you are not dependent on click using id.
Please let me know, if it helps?
Related
i want 14 records to be uploaded. Before uploading i want to select corresponding check button. At a time only one record can be uploaded. So all 14 records are arranged in a table with two buttons, one for choose file and other for submit. But problem is that only very first document is uploaded, others don't get uploaded. later i knew that i must use more than one form for all submission. how can it possible?
<div class="portal-body" style="min-height: 268px;">
<table class="table striped hover bordered" id="sample_editable_4">
<thead>
<tr>
<th id="eval_style">Sl No.</th>
<th id="eval_style">Document Name</th>
<th id="eval_style">select</th>
<th id="eval_style">Choose</th>
<th id="eval_style">Submit</th>
</tr>
</thead>
<tbody>
<?php $i=1;
foreach($evidence_details->result() as $row_evidence) { ?>
<tr>
<td><?php echo $i; ?></td>
<td><?php echo $row_evidence->evidence_name; ?> </td>
<td>
<input type="checkbox" name="evidences" id="<?php echo $row_evidence->evidence_id; ?>" value="<?php echo $row_evidence->evidence_id; ?>" <?php if(in_array($row_evidence->evidence_id,$evidence)) { ?>checked="checked"<?php } ?> />
</td>
<td><input type="file" name="multiUpload" id="multiUpload" multiple /></td>
<td><button type="submit" class="btn blue" name="submitHandler" id="submitHandler" style="margin-top: 15px;margin-left: 54px;">Submit</button></td>
</tr>
<?php $i++; } ?>
</tbody>
</table>
</div>
<script type="text/javascript">
var config = {
support : "image/jpg,image/png,image/bmp,image/jpeg,image/gif,application/vnd.ms-excel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet,text/csv,application/pdf",
form: "demoFiler", // Form ID
dragArea: "dragAndDropFiles",
uploadUrl: "<?php echo base_url(); ?>home/multiple_upload"
}
$(document).ready(function()
{
initMultiUploader(config);
});
</script>
controller
function multiple_upload()
{
$application_id=$this->session->userdata('application_id');
if(!is_dir('./application/assets/uploads/'.$application_id))
{
mkdir('./application/assets/uploads/'.$application_id, 0777, TRUE);
}
if($_SERVER['REQUEST_METHOD'] == "POST"){
if(move_uploaded_file($_FILES['file']['tmp_name'], "./application/assets/uploads/".$application_id."/".$_FILES['file']['name'])){
echo($_POST['index']);
}
exit;
}
}
**multiupload.js**
function initMultiUploader(){
new multiUploader(config);
}
First of all my PHP skills are kinda limited, Hence my question to you here.
I have built a fairly complex form with multiple inputs(text boxs and drop downs) which are stored in a MYsql DB. When the form is submitted it displays on a new page as completed reports. These completed reports display one under the next every time the form is submitted. My question is, How can i get the reports displayed to show as a list of links to the individual reports rather then a list of complete reports.
I hope i've explained the situation well enough.
Code snippit from viewpage.php
<html>
<head>
<body>
<?php
mysql_connect("localhost","user","passwrd");
mysql_select_db("dtbase");
$order = "SELECT * FROM jobrequest" ;
$result = mysql_query($order);
while ($row=mysql_fetch_array($result)){
?>
<link rel="stylesheet" href="css/style.css" type="text/css" />
</head>
<body>
<div style="padding:15px 0px 0px 100px;">
<table cellpadding="0" cellspacing="0" border="0" style="vertical-align:middle;width: 1139px; background-color:#213568; height:36px;">
<tr>
<td class="topbar">Client Request Form</td>
<td style="width:900px;"></td>
<td class="topbar"><a style="color:#ffffff;" href="logout.php?logout">Logout</a></td>
</tr>
</table>
<div class="main-wrap">
<div class="content">
<table cellpadding="0" cellspacing="0" border="0" style="width: 1137px; background-color:#ffffff; height:5px;">
<tr>
<td></td>
</tr>
</table>
<table cellpadding="0" cellspacing="0" border="0" >
<tr>
<td style="vertical-align:top; width:5px;"></td>
<td style="vertical-align:top;"><?php include("includes/clientchoices.php"); ?></td>
<td style="vertical-align:top; padding:0px 5px 15px 5px;">
<table border="0" cellpadding="0" cellspacing="0">
<tr>
<td style="vertical-align:top; width:1002px;"> <h1> Dashboard</h1></td>
</tr>
<tr>
<td style="vertical-align:top; background-color:#f5f5f5;"><h2>Job Request Form</h2></td>
</tr>
<tr>
<td style="vertical-align:top; background-color:#ffffff; height:5px;"> </td>
</tr>
<tr>
<td>
<div class="form">
<table cellspacing="0" cellpadding="0" border="0" style="width:998px">
<tr>
<td style="width:1002px; border:solid 1px #000000; padding:10px 0px 10px 0px;"><center><img src="../../images/spectra_logotop.jpg" alt="Spectra" title="Spectra" width="735" height="120" style="padding:5px;"></center>
</td>
</tr>
<tr>
<td>
<div style="padding:10px 0px 10px 0px;">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headingsa">Project Leader:</td><td class="answersa"><div class= "typesectiona"><?php echo ($row['project_leader'] ); ?></div></td>
<td class="headingsb">Contact Number:</td><td class="answersb"><div class= "typesectionb"><?php echo ($row['contact_number'] ); ?></div></td>
<td class="headingsc">Company Details:</td><td class="answersc"><div class= "typesectionc"><?php echo ($row['company_details'] ); ?></div></td>
</tr>
</table>
</div>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headings5">Contact Person On Site:</td><td class="answers5"><div class= "typesection5"><?php echo ($row['contactperson_onsite'] ); ?></div></td>
<td class="headings6">Contact Details:</td><td class="answers6"><div class= "typesection6"><?php echo ($row['contact_no'] ); ?></div></td>
<td class="headings7">Date:</td><td class="answers7"><div class= "typesection7"><?php echo ($row['date'] ); ?></div></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headings1">Job/Order Number:</td><td class="answers1"><div class= "typesection1"><?php echo ($row['job_order_number'] ); ?></div></td>
<td class="headings2">Document Number:</td><td class="answers2"><div class= "typesection2"><?php echo ($row['doument_number'] ); ?></div></td>
<td class="headings3">QCP:</td><td class="answers3"><div class= "typesection3"><?php echo ($row['qcp'] ); ?></div></td>
<td class="headings4">Page No:</td><td class="answers4"><div class= "typesection4"><?php echo ($row['pageno'] ); ?></div></td>
</tr>
</table>
</td>
</tr>
<table cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="15px"></td>
<td><a class="othersubmitsLink" href="actionpdf.php">Email to Spectra</a></td>
</tr>
</table>
</div>
</td>
</tr>
</table>
</td>
</tr>
</table>
</div>
</div>
</div>
<?php
}
?>
</body>
</html>
You will need a separate PHP script for displaying a report based on a supplied ID. This separate script would look something like this:
Using mysqli
<?php
$conn = new mysqli("localhost", "user", "passwrd", "dtbase");
$jrQry = $conn->prepare("SELECT * FROM jobrequest WHERE jobrequest_id = ?");
$jrQry->bind_param('i', $_GET['jobrequest_id']);
$jrQry->execute();
$jobrequestResult = $jrQry->get_result();
$jobrequest = $jobrequestResult->fetch_assoc();
// At this point, $jobrequest will contain the jobrequest record you want to display.
?>
<!-- HTML FOR REPORT GOES HERE, USING $jobrequest VARIABLE TO SHOW THE DATA -->
Note that I have used mysqli in this example, if this is unsuitable you can use the old-style mysql commands, but for many many reasons (security chief among them) I would strongly suggest against this.
Using mysql
<?php
mysql_connect("localhost","user","passwrd");
mysql_select_db("dtbase");
$order = "SELECT * FROM jobrequest WHERE jobrequest_id = " . (int)$_GET['jobrequest_id'];
$result = mysql_query($order);
$jobrequest = mysql_fetch_array($result);
// At this point, $jobrequest will contain the jobrequest record you want to display.
?>
<!-- HTML FOR REPORT GOES HERE, USING $jobrequest VARIABLE TO SHOW THE DATA -->
Save this page as "viewjobrequest.php" and you will be able to load a given job request's report by supplying the jobrequest ID as a parameter in the URL, like so:
http://address_of_site/viewjobrequest.php?jobrequest_id=X
Now you can automatically generate a list of links to these pages by looking up your complete set of jobrequests and iterating over them, but instead on outputting a full report, just output a link:
Using mysqli
<?php
$conn = new mysqli("localhost", "user", "passwrd", "dtbase");
$jrQry = $conn->prepare("SELECT * FROM jobrequest WHERE jobrequest_id = ?");
$jrQry->bind_param('i', $_GET['jobrequest_id']);
$jrQry->execute();
$jobrequestResult = $jrQry->get_result();
?>
<ul>
<?php
while ($jobrequest = $jobrequestResult->fetch_assoc())
{
?>
<li>
<a href="viewjobrequest.php?jobrequest_id=<?php echo $jobrequest['jobrequest_id']; ?>">
View job request #<?php echo $jobrequest['jobrequest_id']; ?>
</a>
</li>
<?php
}
?>
</ul>
Using mysql
<?php
mysql_connect("localhost","user","passwrd");
mysql_select_db("dtbase");
$order = "SELECT * FROM jobrequest WHERE jobrequest_id = " . (int)$_GET['jobrequest_id'];
$result = mysql_query($order);
?>
<ul>
<?php
while ($jobrequest = mysql_fetch_assoc($result))
{
?>
<li>
<a href="viewjobrequest.php?jobrequest_id=<?php echo $jobrequest['jobrequest_id']; ?>">
View job request #<?php echo $jobrequest['jobrequest_id']; ?>
</a>
</li>
<?php
}
?>
</ul>
Note: I have deliberately omitted large portions of your HTML, you can add as much extra HTML as you need, I've just offered the bare bones to get you started.
BY looking at your code, I can say, it's not problem with PHP, it's more like HOW you are showing the result after fetching from database,
you are running loop, started from here
<?php while ($row=mysql_fetch_array($result)){ ?>
and ends here
<?php}?>
So everything inside loop or in easy words inside these brackets {} repeating again and again with new row of result fetched from database, if you take view source of viewpage.php you will see that style css file <link rel="stylesheet" href="css/style.css" type="text/css" /> repeating, Imagine if you are fetching 10 rows of result, you are also loading css file 10 times.
So the answer (most probably the solution) of your question is;
Your mysql query
<?php
mysql_connect("localhost","user","passwrd");
mysql_select_db("dtbase");
$order = "SELECT * FROM jobrequest" ;
$result = mysql_query($order);
$totalrows = mysql_num_rows($result); //Check Total Number of Rows To Check if Data Exist or Not
?>
and then in your HTML, First check if there are any rows exist in database which match your WHERE clause in mysql query.
//Set an if else statement here so incase if no data exist.
<?php if($totalrows > 0) {
//If row(s) exist run your while loop here
<?php while ($row=mysql_fetch_array($result)){ ?>
//Show the result here from database
//Close your loop
<?php } ?>
//Close your if condition
<?php } else { ?>
//Display a message here if there is no data to show
//Close your else bracket
<?php } ?>
With above explaniation I adjusted your HTML to show the result in desired way;
<table cellspacing="0" cellpadding="0" border="0" style="width:998px">
<tr>
<td style="width:1002px; border:solid 1px #000000; padding:10px 0px 10px 0px;"><center><img src="../../images/spectra_logotop.jpg" alt="Spectra" title="Spectra" width="735" height="120" style="padding:5px;"></center></td>
</tr>
<tr>
<td>
<?php if($totalrows > 0) {
<div style="padding:10px 0px 10px 0px;">
<table cellpadding="0" cellspacing="0">
<tr>
<td class="headingsa">Link to Report</td>
</tr>
<?php while ($row=mysql_fetch_array($result)){ ?>
<tr>
//You have to replace `nameoffile.php` with file in which you want to display report and correct this (as i assumed it) if it's wrong `$row['id']`
<td>Open Report</td>
</tr>
<?php } ?>
</table>
</div>
<?php } else { ?>
<div style="padding:10px 0px 10px 0px;">
<table cellpadding="0" cellspacing="0">
<tr>
<td>There is No Result To Show</td>
</tr>
</table>
</div>
<?php } ?>
</td>
</tr>
</table>
Note: MySQL will soon be deprecated, consider start using MYSQLi or PDO
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 }?>
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?
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!