hide jQuery table row - php

I've got a search done with jQuery..
<script type="text/javascript" src="ajax.js"></script>
<div style="width:400px; margin:auto;">
<form action="clientes.php" method="post">
<legend>Procurar cliente</legend>
<input type="text" id="nome" name="nome" value="<?php echo $nome; ?>" style="width: 280px; height: 23px;" /><input type="button" name="btnPesquisar" value="Pesquisar" onclick="getDados();"/></form>
</div>
<div id="resultado"></div>
and getDados returns the results from another page, which is:
<?php
header('Content-Type: text/html; charset=utf-8');
include "conexao.php";
if ($_GET['nome']) {
$nome = $_GET['nome'];
$result = mysql_query("SELECT * FROM cliente WHERE nome LIKE '%".$nome."%' OR cpf LIKE '%".$nome."%' ORDER BY nome ASC") or die('Invalid query: ' . mysql_error());
$num_rows = mysql_num_rows($result);
}
if ($num_rows != 0) {
?>
<head><script type="text/javascript" src="http://code.jquery.com/jquery-1.10.2.js"> </script></head>
<script type="text/javascript">
$(document).ready(function() {
$('.hideme td').hide();
});
</script>
<table border=4 width="800px" align="center">
<tr><th>Cliente</th> <th>CPF</th> <th>Telefone</th> <th> Aniversário </th><th> Endereço </th></tr>
<?php
$i = "1";
while ($row = mysql_fetch_assoc($result)) {
?>
<TR>
<td width="220px" align="center"> <?php echo $row['nome']; ?> </td>
<td width="80px" align="center"> <?php echo $row['cpf']; ?> </td>
<td width="120px" align="center"><?php echo $row['telefone'] ?> </td>
<td width="120px" align="center"><?php echo $row['dataNascimento']; ?></a></td>
<td width="270px" align="center"><?php echo $row['endereco']; ?></td>
</TR>
<tr class="hideme"><td><form id="nomepost<?php echo $i; ?>" action="agrupaclienteteste.php" method="post">
<input type="hidden" name="nome" value="<?php echo $row['nome']; ?>"></form></td</tr>
<?php
$i++;
}
}
else{
if ($nome) { echo "Não há dados cadastrados em nosso sistema."; }
}
?>
Now.. the thing is, if I run the page of the results by itself.. lets say
result.php?nome=I
it hides the tr class=hideme...
if I access the search page and search for nome = I, it shows the results but it doesn't hide the tr class=hideme ...
Can anyone help me?

Why don't just use style="display:none;" as attribute value, since you are trying to hide onload itself

Related

set two different type checkbox color in the form using php codeigniter

<table class="table table-hover">
<tr>
<th>Sl.No</th>
<th> All </th>
<th>Regno.</th>
<th>Name</th>
<!--<?php echo "Core Subjects" ?> -->
<?php
foreach($getsubc as $rowc)
{
?>
<td align="center">
<?php echo $rowc['subcode']; ?>
<input type="checkbox" id="check-all" onClick="toggle(this,<?php echo $rowc['markid']; ?>)" value="<?php echo $rowc['markid']; ?>" checked="checked" data-checkbox-class="icheckbox_square-green">
</td>
</div>
<?php
}
?>
<!-- Elective subjects -->
<?php
foreach($getsube as $rowe)
{
?>
<td align="center">
<?php echo $rowe['subcode']; ?>
<input type="checkbox" id="check-all2" onClick="toggle(this,<?php echo $rowe['markid']; ?>)" value="<?php echo $rowe['markid']; ?>" data-checkbox-class="icheckbox_square-blue">
</td>
<?php
}?>
</tr>
<?php
$sno=1;
foreach($getstud as $row)
{
echo '<tr>'; ?>
<?php
echo '<td>'.$sno++.'</td>';
echo '<td><input type="checkbox" value="' . $row['regno'] . '" name="regno[]"></td>';
echo '<td>'.$row['regno'].'</td>';
echo '<td>'.$row['name'].'</td>';
?>
<?php ?>
<?php foreach($getsubc as $row1)
{?>
<td align="center"> <input type="checkbox" data-checkbox-class="icheckbox_square-green" name="friend_id[]"
value="<?php echo $row1['markid'];?>" >
</td>
</td>
</div>
</td>
</div>
</div>
<?php
} ?>
<?php
foreach($getsube as $row2)
{
?>
<td align="center"> <input type="checkbox" data-checkbox-class="icheckbox_square-blue" name="friend_id[]" value="<?php echo $row2['markid']; ?>" /> </td>
<?php
}
echo '</tr>';
}
?>
</table>
<script src="<?= base_url('assets/plugins/iCheck/icheck.min.js') ?>"></script>
$('input:checkbox').iCheck({
increaseArea: '25%' // optional
});
</script>
<script language="JavaScript">
function toggle(source, markid) {
checkboxes = document.getElementsByName(markid);
for(var i=0, n=checkboxes.length;i<n;i++) {
checkboxes[i].checked = source.checked;
}
}
</script>
i changes the code accordingly your solution . but not working both color and select_all method . whats wrong with this code
i changes the code accordingly your solution . but not working both color and select_all method . whats wrong with this code
i changes the code accordingly your solution . but not working both color and select_all method . whats wrong with this code
First, change your iCheck initialization to this:
$('input:checkbox').iCheck({
increaseArea: '25%' // optional
});
Then do this on first set:
<td align="center">
<?php echo $row1['subcode']; ?>
<input type="checkbox" id="check-all" onClick="toggle(this,<?php echo $row1['markid']; ?>)" value="<?php echo $row1['markid']; ?>" checked="checked" data-checkbox-class="icheckbox_square-green">
</td>
And then on your second set:
<td align="center">
<?php echo $row2['subcode']; ?>
<input type="checkbox" id="check-all2" onClick="toggle(this,<?php echo $row2['markid']; ?>)" value="<?php echo $row2['markid']; ?>" data-checkbox-class="icheckbox_square-blue">
</td>
Notice the use of data-checkbox-class attribute on each of the input:checkbox tags. Which you can apply the same on the ones within data tables.

How do I echo more than one product dynamically on the same invoice page

I am trying to echo more than one item on an invoice for the same customer. I am able to echo them from the database, but instead of each item being echoed on the same invoice (on different rows), it echoes the full invoice 2 times (or more depending on how many items are on the invoice) with each item on each invoice. Below is my code (I have not yet cleaned the code up. I am leaving that step once the code works).
<?php include "database_connection.php" ?>
<!DOCTYPE html>
<html lang="en">
<head>
<title>DPB quote</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="robots" content="noindex, nofollow">
<link rel="stylesheet" href="css/bootstrap.min.css"><!--erase this link once the app is completed-->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel='stylesheet' type='text/css' href='css/style2.css' />
<link rel='stylesheet' type='text/css' href='css/print.css' media="print" />
<script type='text/javascript' src='js/jquery-1.3.2.min.js'></script>
<script type='text/javascript' src='js/example.js'></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="js/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/jquery.dataTables.min.js"></script>
<script src="js/dataTables.bootstrap.min.js"></script>
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.16/css/jquery.dataTables.min.css"><!--search pagination and delete reference link-->
<script type="text/javascript" src="https://cdn.datatables.net/1.10.16/js/jquery.dataTables.min.js"></script><!--search pagination and delete reference link-->
</head>
<body>
<?php
$statement = $connect->prepare("
SELECT * FROM tbl_order
WHERE order_id = :order_id
LIMIT 1
");
$statement->execute(
array(
':order_id' => $_GET["id"]
)
);
$result = $statement->fetchAll();
foreach($result as $row)
{
?>
<script>
$(document).ready(function(){
$('#order_no').val("<?php echo $row["order_no"]; ?>");
$('#order_date').val("<?php echo $row["order_date"]; ?>");
$('#order_receiver_name').val("<?php echo $row["order_receiver_name"]; ?>");
$('#address_line_1').val("<?php echo $row["address_line_1"]; ?>");
$('#address_line_2').val("<?php echo $row["address_line_2"]; ?>");
$('#city').val("<?php echo $row["city"]; ?>");
$('#state').val("<?php echo $row["state"]; ?>");
$('#zip_code').val("<?php echo $row["zip_code"]; ?>");
$('#phone_number').val("<?php echo $row["phone_number"]; ?>");
$('#email').val("<?php echo $row["email"]; ?>");
$('#notes').val("<?php echo $row["notes"]; ?>");
});
</script>
<form method="post" id="invoice_form">
<div class="container">
<?php
$statement = $connect->prepare("
SELECT * FROM tbl_order_item
WHERE order_id = :order_id
");
$statement->execute(
array(
':order_id' => $_GET["id"]
)
);
$item_result = $statement->fetchAll();
$m = 0;
foreach($item_result as $sub_row)
{
$m = $m + 1;
?>
<!--QUOTATION APP 2 STARTS HERE-->
<div id="page-wrap">
<textarea id="header">Quotation</textarea>
<div id="identity">
<textarea id="address">Discount Plastic Bags
7750
Suite
Irving
Phone: </textarea>
<div id="logo">
<div id="logohelp">
(max width: 540px, max height: 300px)
</div>
<img id="image" src="images/dpblogo3.png" alt="logo" />
</div>
</div>
<div style="clear:both"></div>
<div id="customer">
<!--<form id="quote_date" class="" action="index.php" method="post">-->
<tr>
<td><textarea placeholder="Enter Customer Information" id="address" name="company_info"></textarea></td>
</tr>
<table id="meta">
<tr>
<td class="meta-head">Invoice #</td>
<td><textarea>000123</textarea></td>
</tr>
<tr>
<td class="meta-head">Date</td>
<td><textarea placeholder="enter quotation date" name="quote_date"></textarea></td>
</tr>
<tr>
<td class="meta-head">Amount Due</td>
<td><textarea placeholder="enter amount due" name="amount_due"></textarea></td>
</tr>
</table>
</div>
<table id="items">
<tr>
<th>SKU</th>
<th>Description</th>
<th>Quantity</th>
<th>Unit Cost</th>
<th>Price</th>
</tr>
<tr class="item-row">
<!--<td><span id="sr_no"><?php //echo $m; ?></span></td>-->
<td><input type="text" name="sku[]" id="sku<?php echo $m; ?>" class="item-name" value="<?php echo $sub_row["sku"]; ?>" /></td>
<td><input type="text" name="item_name[]" id="item_name<?php echo $m; ?>" class="description" value="<?php echo $sub_row["item_name"]; ?>" /></td>
<td><input type="text" name="order_item_quantity[]" id="order_item_quantity<?php echo $m; ?>" data-srno="<?php echo $m; ?>" class="qty" value = "<?php echo $sub_row["order_item_quantity"]; ?>" /></td>
<td><input type="text" name="order_item_price[]" id="order_item_price<?php echo $m; ?>" data-srno="<?php echo $m; ?>" class="cost" value="<?php echo $sub_row["order_item_price"]; ?>" /></td>
<td><input type="text" name="order_item_final_amount[]" id="order_item_final_amount<?php echo $m; ?>" data-srno="<?php echo $m; ?>" readonly class="price" value="<?php echo $sub_row["order_item_final_amount"]; ?>" /></td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Subtotal</td>
<td class="total-value"><textarea id="subtotal" name="subtotal"></textarea></td>
</tr>
<tr>
<td colspan="2" class="blank"></td>
<td colspan="2" class="total-line">Total</td>
<td class="total-value"><textarea name="total" id="total"></textarea></td>
</tr>
<tr>
<td colspan="2" class="blank"> </td>
<td colspan="2" class="total-line">Amount Paid</td>
<td class="total-value"><textarea id="paid">$0.00</textarea></td>
</tr>
<tr>
<td colspan="2" class="blank"> </td>
<td colspan="2" class="total-line balance">Balance Due</td>
<td class="total-value balance"><textarea name="balance_due" class="due"> </textarea></td>
</tr>
</table>
<div id="terms">
<h5>Notes</h5>
<textarea name="notes" placeholder="enter quotation notes" rows="12" style="font-size: 15pt"></textarea>
</div>
</div>
</form>
</body>
</html>
<?php
}
}
?>
I would do something like this. This is not tested and just an example of how I do it. There are a few other ways but this works best for me
// other needed code above
$results = sqlsrv_query($link, $query);
//query returns one value for these
echo "<table>";
echo "<tr> ";
echo "<td>".$name."</td>";
echo "<td>".$store."</td>";
echo "</tr>";
//start your multiple items row
while($row=sqlsrv_fetch_array($results))
{
$items = $row['items'];
echo "<tr> ";
echo "<td>".$items."</td> ";
echo "</tr>";
}
echo "<tr> ";
echo "<td>".$cost."</td>";
echo "<td>".$other."</td>";
echo "</tr>";
echo "</table> ";
//other code for the rest of the page below
Result would be:
Bob Bob's Store
ITEM
ITEM
ITEM
$50.00 other

downloading Mp3 file form mysql DB and Increasing number of downloads per click

I want to desing an e-music php web base application and i want to achive the forllowing:
1. on cliking on the download button the file should be downloaded
2. The number of downloads of that file should be incremented by 1
The following code show list of music i.e new releases and top downloads
<?php
$hostname_conn = "localhost";
$database_conn = "e-music";
$username_conn = "root";
$password_conn = "";
$conn = mysqli_connect($hostname_conn, $username_conn, $password_conn, $database_conn) or trigger_error(mysqli_error());
$sql="SELECT * from music INNER JOIN artist on music.a_id=artist.a_id INNER JOIN category on music.cat_id=category.cat_id order by upload_date Desc limit 0,3";
$Result= mysqli_query($conn,$sql) or die('Cannot Retrive Record' . mysqli_error());
$sql1="SELECT * from music INNER JOIN artist on music.a_id=artist.a_id INNER JOIN category on music.cat_id=category.cat_id order by downloads Desc limit 0,3";
$Result1= mysqli_query($conn,$sql1) or die('Cannot Retrive Record' . mysqli_error());
?>
<table align="center" class="table table-striped table-hover ">
<thead>
<tr>
<th colspan="3" align="center"> <h3>New Releases </h3></th>
</tr>
</thead>
<tbody>
<?php while ($row=mysqli_fetch_assoc($Result)) { ?>
<tr>
<td class="col-md-6"> <div class="col-md-2"><img src="uploads/<?php echo $row['artist_image']; ?>" class="img-responsive ims" alt="Image" >
</div>
<label> Artist: <?php echo $row['artist_name'] ?></label> <br/>
<label> Title: <?php echo $row['m_title'] ?></label> <br/>
<label>Category: Wakoin <?php echo $row['cat_name'] ?></label>
</td>
<td>
<a class="btn btn-xs btn-primary" href="download.php?did=<?php echo $row['mid'];?>"> Downloader</a>
</td>
<td class="col-md-2">
Format:<?php echo $row['m_format']; ?>
</td>
<td class="col-md-2">
File Size: <?php echo round($row['size']/1048576,2); ?> MB
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<table align="center" class="table table-striped table-hover">
<thead>
<tr>
<th colspan="3" align="center"> <h3>Top Downloads </h3></th>
</tr>
</thead>
<tbody>
<?php while ($row=mysqli_fetch_assoc($Result1)) { ?>
<tr>
<td class="col-md-6"> <div class="col-md-2"><img src="uploads/<?php echo $row['artist_image']; ?>" class="img-responsive ims" alt="Image" >
</div>
<label> Artist: <?php echo $row['artist_name'] ?></label> <br/>
<label> Title: <?php echo $row['m_title'] ?></label> <br/>
<label>Category: Wakoin <?php echo $row['cat_name'] ?></label>
</td>
<td class="col-md-2">
<a class="btn btn-xs btn-primary" href="download.php?did=<?php echo $row['mid'];?>"> Downloader</a>
</td>
<td class="col-md-2">
Format: <?php echo $row['m_format']; ?>
</td>
<td>
File Size :<?php echo round($row['size']/1048576,2); ?> MB
</td>
</tr>
<?php
}
?>
</tbody>
</table>
The code i tried for the downloads on cliking the "downloader" Button which redirects to download.php file is below:
$hostname_conn = "localhost";
$database_conn = "e-music";
$username_conn = "root";
$password_conn = "";
$conn = mysqli_connect($hostname_conn, $username_conn, $password_conn, $database_conn) or trigger_error(mysqli_error());
$did=$_GET['did'];
$sql="SELECT target from music where mid='$did'";
$Result= mysqli_query($conn,$sql) or die('Cannot Retrive Record' . mysqli_error());
$row = mysqli_fetch_assoc($Result);
// the target filed contains the directory and file name of the file to be downloaded e.g uploads/Akon_Sorry Blame.mp3
echo "<a href=". $row['target'] ." > download</a>";
$sql1="update music set download=download+1 where mid='$did";
$Result= mysqli_query($conn,$sql1) or die('Cannot Increment number of downloads' . mysqli_error());
After research on my project i am able to solve my problem using ajax. Here is the code i used to achieve my objectives
//index page
<!DOCTYPE html>
<html>
<head>
<title>E-music</title>
<link href="includes/Style.css" rel="stylesheet" type="text/css"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="bootstrap-3.3.7-dist/css/bootstrap.min.css" rel="stylesheet" type="text/css"/>
<script src="jQuery/jquery-1.11.1.min.js" type="text/javascript"></script>
<script src="bootstrap-3.3.7-dist/js/bootstrap.min.js" type="text/javascript"></script>
<script src="bootstrap-3.3.7-dist/js/site.js" type="text/javascript"></script>
<?php
require_once("includes/connection.php");
$sql="SELECT * from music INNER JOIN artist on music.a_id=artist.a_id INNER JOIN category on music.cat_id=category.cat_id order by upload_date Desc limit 0,3";
$Result= mysqli_query($conn,$sql) or die('Cannot Retrive Record' . mysqli_error());
$sql1="SELECT * from music INNER JOIN artist on music.a_id=artist.a_id INNER JOIN category on music.cat_id=category.cat_id order by downloads Desc limit 0,3";
$Result1= mysqli_query($conn,$sql1) or die('Cannot Retrive Record' . mysqli_error());
?>
<div id="nav">
Search For Music Audio
<p>Wakokin Hausa Na Gargajiya
</p>
</div>
<div id="section">
<table align="center" class="table table-striped table-hover ">
<thead>
<tr>
<th colspan="3" align="center"> <h3>New Releases </h3></th>
</tr>
</thead>
<tbody>
<?php while ($row=mysqli_fetch_assoc($Result)) { ?>
<tr>
<td class="col-md-6"> <div class="col-md-2"><img src="uploads/<?php echo $row['artist_image']; ?>" class="img-responsive ims" alt="Image" >
</div>
<label> Artist: <?php echo $row['artist_name'] ?></label> <br/>
<label> Title: <?php echo $row['m_title'] ?></label> <br/>
<label>Category: Wakoin <?php echo $row['cat_name'] ?></label>
</td>
<td>
<a href="<?php echo $row['target'] ?>" d="<?php echo $row['mid'] ?>" class="dload btn btn-xs btn-primary" download>Download</a>
</td>
<td class="col-md-2">
Format:<?php echo $row['m_format']; ?> <br>
Total Download: <?php echo $row['downloads']; ?>
</td>
<td class="col-md-2">
File Size: <?php echo round($row['size']/1048576,2); ?> MB
</td>
</tr>
<?php
}
?>
</tbody>
</table>
<table align="center" class="table table-striped table-hover">
<thead>
<tr>
<th colspan="3" align="center"> <h3>Top Downloads </h3></th>
</tr>
</thead>
<tbody>
<?php while ($row=mysqli_fetch_assoc($Result1)) { ?>
<tr>
<td class="col-md-6"> <div class="col-md-2"><img src="uploads/<?php echo $row['artist_image']; ?>" class="img-responsive ims" alt="Image" >
</div>
<label> Artist: <?php echo $row['artist_name'] ?></label> <br/>
<label> Title: <?php echo $row['m_title'] ?></label> <br/>
<label>Category: Wakoin <?php echo $row['cat_name'] ?></label>
</td>
<td class="col-md-2">
<a href="<?php echo $row['target'] ?>" d="<?php echo $row['mid'] ?>" class="dload btn btn-xs btn-primary" download>Download</a>
</td>
<td class="col-md-2">
Format: <?php echo $row['m_format']; ?>
Total Download: <?php echo $row['downloads']; ?>
</td>
<td>
File Size :<?php echo round($row['size']/1048576,2); ?> MB
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
//Site.js an ajax file to handle download incrementation
$(function() {
$(".dload").click(function(){
var id = $(this).attr("d");
$.ajax({
type: "POST",
url: "count.php",
data: {id:id},
success: function(info)
{
},
error: function(){
}
});
});
});
//conut.php to handle the databae update
<?php
require_once("includes/connection.php");
$id = $_POST["id"];
$Result= mysqli_query($conn,"SELECT downloads as total FROM music WHERE mid='$id'");
$Res = mysqli_fetch_assoc($Result);
$re = $Res['total'] + 1;
$updateCount = mysqli_query($conn, "UPDATE music SET downloads= '$re' WHERE mid=$id ");
?>

Call php function when click a button

I have a code :
<?php
getPriceListHeader();
function getPriceListDetail($PriceListCode)
{
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$query = "SELECT * FROM pricelisdetail where pricelist_code='".$PriceListCode."'";
$results = $readConnection->fetchAll($query);
echo "<table id='tbdata'>
<thead>
<tr>
<th>Price List Code</th>
<th>Price List Name</th>
<th>Effective From</th>
<th>Effective To</th>
</tr>
</thead>
<tbody> ";
foreach ($results as $row)
{
echo "<tr>";
echo "<td> ".$row[entity_id];
echo "<td> ".$row[sku];
echo "<td> ".$row[sku];
echo "<td> ".$row[sku];
};
echo " </tbody>
</table> ";
}
function getPriceListHeader()
{
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$query = 'SELECT * FROM pricelistheader';
$results = $readConnection->fetchAll($query);
echo "
<h2>Price List</h2>
<div>
<h3>Please select Price List</h3>
<div>
<select class='element select large' id='pricelist' name='element_2'>";
foreach ($results as $row)
{
echo '<option value="' . $row[entity_id]. '">' . $row[sku] . '</option>';
}
echo "</select>
</div>
<input type='button' class='button' name='insert' value='Get Data' onclick='getPriceListDetail(pricelist.value)'/>
";
getPriceListDetail('');
}
?>
I have a dropdown list, a button, a table
When I select a value from dropdown list, then I click button , table will be filled data again. There are 2 method, getPriceListHeader(): load data header when load the page, getPriceListDetail : load data detail when click a button. I try to put event getPriceListDetail(value) to button, but when I click, nothing happens
Please help me how to do this.
Yes, you can call php via ajax request to server like this (very simple):
Note that the following code uses jQuery
jQuery.ajax({
type: "POST",
url: 'my_php_function.php',
dataType: 'name_the_data_type',
success: function (data) {
// here you will get the response your function
}
});
and my_php_function.php like this:
<?php
// here is your php code or function
?>
from the source How can I call PHP functions by JavaScript?
You can't attach PHP function to HTML. PHP is server-side language, so after it's displayed in users browser you can't refer to PHP again, unless you reload page.
There are 3 options I think you can do:
Reload page after changing select page and using GET prepare new data.
Send all data to user browser and than show only part of it related to selected option.
Use AJAX and ask server for new data in background.
Finally, I found out the way.It works for me. Now, I do not understand the code , I am trying to read and get it clearly.
Thanks all for your comments.
$to="";
$from="";
$show_order_statuses = 0;
$orserstatus = "";
$result_order = 0;
//var_dump($results);
//return;
if(!empty($_REQUEST['filter_type']))
{
$orders_row = array();
$filter_type = $_REQUEST['filter_type'];
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$query = " SELECT * FROM pricelistitem where pricelist_code='".$filter_type."' ";
// $query = 'SELECT * FROM pricelistheader1';
$results = $readConnection->fetchAll($query);
foreach ($results as $rowid)
{
$result_order=10;
$orders_row[]=array($rowid['pricelist_code'],$rowid['product_code'],number_format( $rowid['unitprice'],2),$rowid['UOM']);
// $orders_row[]=array(1,1,1,1,1);
}
}
?>
<div id="anchor-content" class="middle">
<div id="page:main-container">
<div class="content-header">
<table cellspacing="0">
<tbody>
<tr>
<td style="width:50%;"><h3 class="icon-head head-report-sales-sales"><?php echo $this->__("Price List");?></h3></td>
<td class="form-buttons"><button style="" onclick="filterFormSubmit.submit()" class="scalable " type="button" id="id_<?php echo Mage::getSingleton('core/session')->getFormKey() ?>"><span>Show Report</span></button></td>
</tr>
</tbody>
</table>
</div>
<div>
<div class="entry-edit">
<form method="get" action="<?php echo Mage::helper('core/url')->getCurrentUrl();?>" id="filter_form">
<?php /*?><input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" /><?php */?>
<div class="entry-edit-head">
<h4 class="icon-head head-edit-form fieldset-legend">Filter</h4>
<div class="form-buttons"></div>
</div>
<div id="sales_report_base_fieldset" class="fieldset">
<div class="hor-scroll">
<table cellspacing="0" class="form-list">
<tbody>
<tr>
<td class="label"><label for="sales_report_filter_type">Filter By <span class="required">*</span></label></td>
<td class="value">
<select class="required-entry select" name="filter_type" id="sales_report_filter_type" onchange="myFunction();">
<?php
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$query = " SELECT * FROM pricelistheader ";
$results = $readConnection->fetchAll($query);
$so=1;
foreach ($results as $row)
{
$selected='';
if ($filter_type==$row[pricelist_code])
$selected= ' selected=selected';
else
$selected='';
echo '<option value="' . $row[pricelist_code]. '" '.$selected.' >' . $row[pricelist_name].' '. $row[pricelist_code] . '</option>';
}
?>
</select>
</tr>
<tr>
<td class="label"><label for="effect_from">Effect From </label></td>
<td class="value">
<?php
foreach ($results as $row)
{
if ($filter_type==$row[pricelist_code])
echo $row[pricelist_fromdate];
}
?>
</td>
</tr>
<tr>
<td class="label"><label for="effect_from">Effect To </label></td>
<td class="value">
<?php
foreach ($results as $row)
{
if ($filter_type==$row[pricelist_code])
echo $row[pricelist_todate];
}
?>
</td>
</tr>
</tbody>
<script>
function myFunction() {
// document.getElementById("tbdata").deleteRow(1);
var rowCount = tbdata.rows.length;
for (var i = rowCount - 1; i > 0; i--) {
tbdata.deleteRow(i);
}
srt.value=pricelist.options[pricelist.selectedIndex].value;
";
//$('#tbdata').empty();
}
</script>
</table>
</div>
</div>
</form>
</div>
<script type="text/javascript">
//<![CDATA[
var filterFormSubmit = new varienForm('filter_form');
//]]>
</script>
<script type="text/javascript"> new FormElementDependenceController({"sales_report_order_statuses":{"sales_report_show_order_statuses":"1"}}); </script>
<style type="text/css">
.no-display{display:none;}
</style>
</div>
<div>
<?php if($result_order>0){?>
<table cellspacing="0" class="actions">
<tbody>
<tr>
<td class="pager"> </td>
<td class="export a-right">
<form method="post" action="<?php echo $this->getUrl('*/*/exportCsv')?>" id="csv_form_customer">
<input name="form_key_customer" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
</form>
<script type="text/javascript">
//<![CDATA[
var csvFormSubmitcustomer = new varienForm('csv_form_customer');
//]]>
</script>
</td>
<td class="filter-actions a-right">
<img class="v-middle" alt="" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);?>skin/adminhtml/default/default/images/icon_export.gif"> Export to:
<select style="width:8em;" id="sales_order_grid_export_customer" name="sales_order_grid_export_customer">
<option value="<?php echo $this->getUrl('*/*/exportCsv')?>">CSV</option>
</select>
<button onclick="csvFormSubmitcustomer.submit()" class="scalable task" type="button"><span>Export</span></button>
</td>
</tr>
</tbody>
</table>
<?php } ?>
<div id="id_customer<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" class="print_customer<?php echo Mage::getSingleton('core/session')->getFormKey() ?>">
<div class="grid">
<div class="hor-scroll">
<table cellspacing="0" id="id_customer<?php echo Mage::getSingleton('core/session')->getFormKey() ?>_table" class="data">
<colgroup>
<col>
<col>
</colgroup>
<thead>
<tr class="headings">
<th class=" no-link"><span class="nobr">Price List Code</span></th>
<th class=" no-link"><span class="nobr">Cust Code</span></th>
<th class=" no-link"><span class="nobr">Cust Name</span></th>
</tr>
</thead>
<tbody id="">
<?php
$resource = Mage::getSingleton('core/resource');
$readConnection = $resource->getConnection('core_read');
$query = " SELECT * FROM " . $resource->getTableName('catalog/product');;
$customercount=0;
$customerresults = $readConnection->fetchAll($query);
$customerresults = Mage::getModel('customer/customer')
->getCollection()
->addAttributeToSelect('*')
->addAttributeToFilter('erp_pricelistcode_1', $filter_type)
// ->addFieldToSelect (array('created_at','customer_id','increment_id','updated_at','status','entity_id','state'))
;
// ->addAttributeToFilter('erp_pricelistcode_1','00')->load();
$so=1;
foreach ($customerresults as $row) {
$customercount++;
}
// var_dump(#$customerresults);
if($customercount>0){
foreach($customerresults as $singlerows){
$cot=0;
{
echo "<tr>";
{
$cot++;
?>
<td>
<?php
echo $singlerows->getData('erp_pricelistcode_1');
?>
</td>
<td>
<?php
echo $singlerows->getFirstname();
?>
</td>
<td>
<?php
echo $singlerows->getName();
?>
</td>
<?php
}
echo "</tr>";
}
}
}else{
?>
<tr class="even">
<td colspan="13" class="empty-text a-center">No records found.</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
<div>
<?php if($result_order>0){?>
<table cellspacing="0" class="actions">
<tbody>
<tr>
<td class="pager"> </td>
<td class="export a-right">
<form method="post" action="<?php echo $this->getUrl('*/*/exportCsv')?>" id="csv_form">
<input name="form_key" type="hidden" value="<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" />
</form>
<script type="text/javascript">
//<![CDATA[
var csvFormSubmit = new varienForm('csv_form');
//]]>
</script>
</td>
<td class="filter-actions a-right">
<img class="v-middle" alt="" src="<?php echo Mage::getBaseUrl(Mage_Core_Model_Store::URL_TYPE_WEB);?>skin/adminhtml/default/default/images/icon_export.gif"> Export to:
<select style="width:8em;" id="sales_order_grid_export" name="sales_order_grid_export">
<option value="<?php echo $this->getUrl('*/*/exportCsv')?>">CSV</option>
</select>
<button onclick="csvFormSubmit.submit()" class="scalable task" type="button"><span>Export</span></button>
</td>
</tr>
</tbody>
</table>
<?php } ?>
<div id="id_<?php echo Mage::getSingleton('core/session')->getFormKey() ?>" class="print_<?php echo Mage::getSingleton('core/session')->getFormKey() ?>">
<div class="grid">
<div class="hor-scroll">
<table cellspacing="0" id="id_<?php echo Mage::getSingleton('core/session')->getFormKey() ?>_table" class="data">
<colgroup>
<col>
<col>
<col>
<col>
</colgroup>
<thead>
<tr class="headings">
<th class=" no-link"><span class="nobr">Price List Code</span></th>
<th class=" no-link"><span class="nobr">Product Code</span></th>
<th class=" no-link"><span class="nobr">Unit Price</span></th>
<th class=" no-link"><span class="nobr">UOM</span></th>
</tr>
</thead>
<tbody id="">
<?php
$cot=0;
if(count($orders_row)>0){
foreach($orders_row as $singlerows){
$cot=0;
if(!empty($singlerows)){
echo "<tr>";
foreach($singlerows as $value){
$cot++;
?>
<td>
<?php
if ($cot==3 )
echo "<div style='float:right;width:30%;'>";
echo $value;
echo "</div>";
?>
</td>
<?php
}
echo "</tr>";
}
}
}else{
?>
<tr class="even">
<td colspan="13" class="empty-text a-center">No records found.</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>

php mysql edit function error submit button show error

I have a bug in my system...when I clicked useraccounts to display the information of the users in the system it says: Notice: Undefined index: Username in C:\xampp\htdocs\GuidanceRecord\useraccounts.php on line 75
I know the problem is quite easy but I can't see what the problem is...
My useraccounts.php is:
<?php
$records = mysql_connect('localhost', 'root', '') or die(mysql_error());
mysql_select_db('records', $records);
$sql = 'SELECT * FROM login';
$result = mysql_query($sql, $records);
echo "<table border='1' width='100%'>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td width='20%'><img src='image/loginimage2.jpg'></img>";
echo "</td>";
echo $row['Username'];
echo "<td width='15%'><a href='#'>Guidance<br>Administrator</a>";
echo "</td>";
echo "<td>";
echo "<a href='edituser.php?no={$row['ID']}'><input type='button' name='edit' value='Edit' class='btn btn-success'></a>";
echo "</td>";
}
echo "<td>";
echo "</td>";
echo "</tr>";
echo "</table>";
?>
I also have this edituser page named edituser.php...
<?php
ob_start();
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title>UCC Guidance Record System</title>
<link rel="stylesheet" type="text/css" media="all" href="css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" media="all" href="css/bootstrap-responsive.min.css">
<link rel="stylesheet" type="text/css" media="all" href="css/global.css">
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript"src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/textbox.js"></script>
</head>
<body>
<?php
$records = mysql_connect("localhost","root","");
mysql_select_db("records",$records);
if(!isset($_POST['savechanges']))
{
$sql = "SELECT * FROM login WHERE ID = $_GET[no]";
$result = mysql_query($sql);
$login = mysql_fetch_array($result);
}
?>
<div class="container">
<br>
<div class="navbar">
<div class="navbar-inner">
<div class="container">
<ul class="nav">
<li>View Records</li>
<li>Add Records</li>
<li class="active">User Accounts</li>
</ul>
<span class="span6">
</span>
<ul class="nav">
<li>Logout</li>
</ul>
</div>
</div>
</div>
<div class="row">
<span class="span12">
<img src="image/UCC Guidance Record System2.png" width="100%" height="210px"></img>
</span>
<span class="span2">
</span>
<span class="span8">
<br><br>
<table border="0" width="100%" height="100%">
<tr>
<td width="33%">
<form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>">
</td>
<td width="33%">
</td>
<td width="33%">
</td>
</tr>
<tr>
<td width="33%">
User Accounts
</td>
<td width="33%">
</td>
<td width="33%">
</td>
</tr>
<tr>
<td width="33%">
Username:
</td>
<td width="33%">
Password:
</td>
<td width="33%">
</td>
</tr>
<tr>
<td width="33%">
<input type="hidden" name="ID" value="<?php echo $login['ID']; ?>" />
<input type="text" name="Username" title="Username" style="color:#888;" value="<?php echo $login['Username']; ?>" onfocus="inputFocus(this)" onblur="inputBlur(this)" />
</td>
<td width="33%">
<input type="Password" name="Password" title="Password" style="color:#888;" value="<?php echo $login['Password']; ?>" onfocus="inputFocus(this)" onblur="inputBlur(this)" />
</td>
<td width="33%">
</td>
</tr>
<tr>
<td width="33%">
</td>
<td width="33%">
</td>
<td width="33%">
<input type="submit" name="savechanges" class="btn btn-primary" value="Save Changes">
</form>
</td>
</tr>
</table>
</span>
</div>
<div class="container">
<ul class="pager container-fluid">
<li class="pull-left">Previous</li>
<li class="pull-right">Next</li>
</ul>
</div>
</div>
<center><small class="muted">UCC Guidance Record System<br>
Developed by Christian Baltazar and Jocella Barruga.<br>
Copyright 2014.</small></center>
<?php
if(isset($_POST['savechanges']))
{
$id = $_POST['ID'];
$Username = $_POST['Username'];
$Password = $_POST['Password'];
$update = "UPDATE students ".
"SET Username = '$Username' ".
", Password = '$Password' ".
"WHERE ID = $id" ;
mysql_query($update) or die(mysql_error());
echo "User has been modified!";
header("Location: http://localhost/GuidanceRecord/Useraccounts.php");
exit() ;
}
?>
</body>
</html>
I also have a database named "records" a table named "login" and columns named "ID", "Username", and "Password"...
I'm a newbie in php...hope you understand...
Thanks in advance for the answer... :))
Try this
$row = mysql_fetch_array($result,MYSQL_ASSOC)
instead of
$row = mysql_fetch_array($result)
and also mysql is deprecated and very vulnerable to sql injection use PDO or Mysqli instead.
Are you sure your column name in database is called 'Username'? It might be 'username', as you know PHP is character sensitive.
Try running print_r to see what are you getting from database:
echo '<pre>'; print_r($row); echo '</pre>';
At the point where you output the id in the ancor link try to replce the 'ID' with 0 it specifies the columns number you wanna display out.

Categories