can u see the output in this screenshot. now what is the problem is.
In left table i have two rows that is dynamic. Right side am getting output.
If I click first row of left table i should display output of that row in right side. That is working.
Same If I click second row of left table I should display second row output only but its displaying first row and second row output. Its not hiding the first row output.
It displaying each and every row multiple times for every click
Please help me out friends am new to jquery so i don't know how to solve this.
My Code - index.php
<head>
<script type="text/javascript">
$('#table_struct tr').click(function() {
var $this = $(this);
var offset = $this.offset();
var height = $this.height();
var order_id = $this.data('order_id');
$.get('getuser.php?order_id=' + order_id, function(table) {
$('.menu').append(table);
$('.menu').css({
right: offset.right,
top: offset.top+height
});
});
});
</script>
</head>
<body>
<?php
session_start();
include "db.php";
$query = "select * from purna_orders";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
if($num_rows >= 1)
{
echo "<div id='showmenu' class='scroll'>";
echo "<table id='table_struct' cellspacing='0' cellpadding='1' border='1' width='400' height='30'>
<tr class='tr_class' bgcolor='white'>
<td align='center' style='font-weight:bold'> Select </td>
<td align='center' style='font-weight:bold'> Order Id </td>
<td align='center' style='font-weight:bold'> Customer Name </td>
<td align='center' style='font-weight:bold'> Price </td>
<td align='center' style='font-weight:bold'> Pincode </td>
<td align='center' style='font-weight:bold'> COD </td>
<td align='center' style='font-weight:bold'> Status </td>
</tr>";
while($row = mysql_fetch_array($result))
{
$order_id = $row['order_id'];
$_SESSION['order_id'] = $order_id;
echo "<tr height='20' data-order_id='".$row['order_id']."'>
<td align='center'><input type='checkbox' class='case' name='case' value='1'></td>
<td align='center'>".$row['order_id']."</td>
<td align='center'>".$row['customer_name']."</td>
<td align='center'>".$row['order_value']."</td>
<td align='center'>".$row['bill_to_pincode']."</td>
<td align='center'></td>
<td align='center'>Ready To Ship</td>";
echo "</tr>";
}
echo "</table>";
echo "</div>";
}
if(!mysql_close($con))
{
echo "failed to close";
}
?>
</body>
getuser.php
<?php
include "db.php";
$order_id = intval($_GET['order_id']);
$sql="SELECT * FROM purna_order_items WHERE order_id = '".$order_id."'";
$result = mysql_query($sql);
echo "<div style=margin-top:0px; margin-bottom:0px;'>";
echo "<table border='1' style='background-color:white; font-style:bold;'>
<tr>
<td align='center'><b>Increment Id</b></td>
<td align='center'><b>Po Order Id</b></td>
<td align='center'><b>Item Sku</b></td>
<td align='center'><b>Item Name</b></td>
<td align='center'><b>Item Price</b></td>
<td align='center'><b>Item Quantity</b></td>
<td align='center'><b>Item Weight</b></td>
</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td align='center'>" . $row['order_id'] . "</td>";
echo "<td align='center'>" . $row['po_id'] . "</td>";
echo "<td align='center'>" . $row['sku'] . "</td>";
echo "<td align='center'>" . $row['item_name'] . "</td>";
echo "<td align='center'>" . $row['item_price'] . "</td>";
echo "<td align='center'>" . $row['item_quantity'] . "</td>";
echo "<td align='center'>" . $row['weight'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "</div>";
mysql_close($con);
?>
So you can first remove the existing output on the click event and then the new record will be append.
<script type="text/javascript">
$('#table_struct tr').click(function() {
var $this = $(this);
var offset = $this.offset();
var height = $this.height();
var order_id = $this.data('order_id');
$.get('getuser.php?order_id=' + order_id, function(table) {
$('.menu').empty(); // First remove the existing record from DOM
$('.menu').append(table);
$('.menu').css({
right: offset.right,
top: offset.top+height
});
});
});
</script>
Related
when i click first row of left table am getting output in right side. Same when i click second row of first table, second row output should only come but first row output ans second row output both are displaying first row output not getting hide.
Can you pls anyone help me out to solve this issue.
php code:
<?php
session_start();
include "db.php";
$query = "select * from purna_orders";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
if($num_rows >= 1)
{
echo "<div id='showmenu' class='scroll'>";
echo "<table id='table_struct' cellspacing='0' cellpadding='1' border='1' width='400' height='30'>
<tr class='tr_class' bgcolor='white'>
<td align='center' style='font-weight:bold'> Select </td>
<td align='center' style='font-weight:bold'> order_id </td>
<td align='center' style='font-weight:bold'> customer_name </td>
<td align='center' style='font-weight:bold'> price </td>
<td align='center' style='font-weight:bold'> payment mode </td>
</tr>";
while($row = mysql_fetch_array($result))
{
$order_id = $row['order_id'];
$_SESSION['order_id'] = $order_id;
echo "<tr height='20' data-order_id='".$row['order_id']."'>
<td align='center'><input type='checkbox' class='case' name='case' value='1'></td>
<td align='center'>".$row['order_id']."</td>
<td align='center'>".$row['customer_name']."</td>
<td align='center'>".$row['order_value']."</td>
<td align='center'>".$row['bill_to_pincode']."</td>";
echo "</tr>";
}
echo "</table>";
echo "</div>";
}
if(!mysql_close($con))
{
echo "failed to close";
}
?>
Ajax Code:
<script type="text/javascript">
$('#table_struct tr').click(function() {
var $this = $(this);
var offset = $this.offset();
var height = $this.height();
var order_id = $this.data('order_id');
$.get('getuser.php?order_id=' + order_id, function(table) {
$('.menu').append(table);
$('.menu').css({
right: offset.right,
top: offset.top+height
});
});
});
</script>
getuser.php
<?php
include "db.php";
$order_id = intval($_GET['order_id']);
$sql="SELECT * FROM purna_order_items WHERE order_id = '".$order_id."'";
$result = mysql_query($sql);
echo "<div style=margin-top:-398px; margin-bottom:0px;'>";
echo "<table border='1' style='background-color:white; font-style:bold;'>
<tr>
<td align='center'><b>Increment Id</b></td>
<td align='center'><b>Po Order Id</b></td>
<td align='center'><b>Item Sku</b></td>
<td align='center'><b>Item Name</b></td>
<td align='center'><b>Item Price</b></td>
<td align='center'><b>Item Quantity</b></td>
<td align='center'><b>Item Weight</b></td>
</tr>";
while($row = mysql_fetch_array($result)) {
echo "<tr>";
echo "<td align='center'>" . $row['order_id'] . "</td>";
echo "<td align='center'>" . $row['po_id'] . "</td>";
echo "<td align='center'>" . $row['sku'] . "</td>";
echo "<td align='center'>" . $row['item_name'] . "</td>";
echo "<td align='center'>" . $row['item_price'] . "</td>";
echo "<td align='center'>" . $row['item_qunatity'] . "</td>";
echo "<td align='center'>" . $row['weight'] . "</td>";
echo "</tr>";
}
echo "</table>";
echo "</div>";
mysql_close($con);
?>
output screenshot:
Your code does not have sufficient information, but try with this one, if it helps -
<script type="text/javascript">
$('#table_struct tr').click(function() {
var $this = $(this);
var offset = $this.offset();
var height = $this.height();
var order_id = $this.data('order_id');
$.get('getuser.php?order_id=' + order_id, function(table) {
$('.menu', $this).append(table);
$('.menu', $this).css({
right: offset.right,
top: offset.top+height
});
});
});
</script>
After resolving an Undefined offset error, the error message is no more, but the results now displayed are only one record instead of the expected number of records, for instance 3.
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
$time = $row['vluchttijd'];
if (!function_exists('timeInWords')) {
function timeInWords($time) {
list($hours, $minutes) = explode(':', $time);
return (int)$hours . " hrs " . (int)$minutes . " min";
} $result = mysql_query($sql);
{
I can remove everything from $time down and then it returns all of the expected records.
As requested all of the code. I should preface this that I am still very very new to the world of PHP, so please go easy on me:
<?php
include('../datalogin.php'); // include your code to connect to DB.
mysql_query("SET CHARACTER SET 'utf8';");//GET and POST
mysql_query("SET NAMES 'utf8';");//POST
/* Get data. */
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
die("Invalid ID specified.");
}
$rID = (int)$_GET['id'];
$sql = "a bunch of SQL code removed to save space
WHERE vg.reisID = '$rID'
ORDER BY vg.vertrekdatum2 ASC";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
$time = $row['vluchttijd'];
if (!function_exists('timeInWords')) {
function timeInWords($time) {
list($hours, $minutes) = explode(':', $time);
return (int)$hours . " hrs " . (int)$minutes . " min";
} $result = mysql_query($sql);
{
echo "<table border='0' width='640'>";
echo "<tbody>";
echo "<tr>";
echo "<td colspan='3'><strong>" .date('d-M-Y H:i', strtotime($row['vertrekdatum2'])). "
</strong></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='3'><span class='c_vertrek'>(D)
".htmlspecialchars($row['luchthavennaam'])."</span></td>";
echo "</tr>";
echo "<tr>";
echo "<td width='18%'><strong>Duration:</strong></td>";
echo "<td width='41%'>".timeInWords($time)."</td>";
echo "<td rowspan='4' width='41%' align='center' valign='middle'><img
src='../logos/".$row['logo']."'</td>";
echo "</tr>";
echo "<tr>";
echo "<td><strong>Equipment:</strong></td>";
echo "<td>".$row['toestel']." ".$row['erlr']."</td>";
echo "</tr>";
echo "<tr>";
echo "<td><strong>Class:</strong></td>";
echo "<td>".$row['reisklass']."</td>";
echo "</tr>";
echo "<tr>";
echo "<td><strong>Miles:</strong></td>";
echo "<td>".$row['afstand']." miles</td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='3'></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='3' height='12'></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='3'><strong>".date('d-M-Y H:i', strtotime($row['aankomstdatum2']))."
</strong></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='3'><span class='c_aankomst'>(A)
".htmlspecialchars($row['aankomstnaam'])."</span></td>";
echo "</tr>";
echo "<tr>";
echo "<td></td>";
echo "<td></td>";
echo "<td></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='3' height='1' bgcolor='#585858'></td>";
echo "</tr>";
echo "<tr>";
echo "<td></td>";
echo "<td></td>";
echo "<td></td>";
echo "</tr>";
echo "<tr>";
echo "<td></td>";
echo "<td></td>";
echo "<td></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='3'></td>";
echo "</tr>";
echo "<tr>";
echo "<td colspan='3'></td>";
echo "</tr>";
}
}
}
echo "</table>";
?>
This should do it, you called the mysql_query with the same query over again, so that would give you the same result all the time.
I cleaned the start of you while loop, so it only fetches the data from your result object and prints it. Your time function does not need to be inside the loop so I moved it outside.
I also cleaned the loop from some echo's
<?php
include('../datalogin.php'); // include your code to connect to DB.
function timeInWords($time) {
list($hours, $minutes) = explode(':', $time);
return (int)$hours . " hrs " . (int)$minutes . " min";
}
mysql_query("SET CHARACTER SET 'utf8';");//GET and POST
mysql_query("SET NAMES 'utf8';");//POST
/* Get data. */
if (!isset($_GET['id']) || !is_numeric($_GET['id'])) {
die("Invalid ID specified.");
}
$rID = (int)$_GET['id'];
$sql = "a bunch of SQL code removed to save space
WHERE vg.reisID = '$rID'
ORDER BY vg.vertrekdatum2 ASC";
$result = mysql_query($sql);
while($row = mysql_fetch_assoc($result))
{
$time = $row['vluchttijd'];
echo "<table border='0' width='640'>
<tbody>
<tr>
<td colspan='3'><strong>" .date('d-M-Y H:i', strtotime($row['vertrekdatum2']))."
</strong></td>
</tr>
<tr>
<td colspan='3'><span class='c_vertrek'>(D)
".htmlspecialchars($row['luchthavennaam'])."</span></td>
</tr>
<tr>
<td width='18%'><strong>Duration:</strong></td>
<td width='41%'>".timeInWords($time)."</td>
<td rowspan='4' width='41%' align='center' valign='middle'><img
src='../logos/".$row['logo']."'</td>
</tr>
<tr>
<td><strong>Equipment:</strong></td>
<td>".$row['toestel']." ".$row['erlr']."</td>
</tr>
<tr>
<td><strong>Class:</strong></td>
<td>".$row['reisklass']."</td>
</tr>
<tr>
<td><strong>Miles:</strong></td>
<td>".$row['afstand']." miles</td>
</tr>
<tr>
<td colspan='3'></td>
</tr>
<tr>
<td colspan='3' height='12'></td>
</tr>
<tr>
<td colspan='3'><strong>".date('d-M-Y H:i', strtotime($row['aankomstdatum2']))."
</strong></td>
</tr>
<tr>
<td colspan='3'><span class='c_aankomst'>(A)
".htmlspecialchars($row['aankomstnaam'])."</span></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan='3' height='1' bgcolor='#585858'></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td colspan='3'></td>
</tr>
<tr>
<td colspan='3'></td>
</tr>";
}
echo "</table>";
?>
T have one page on which results are get created dynamically. And I
want to display popup window on clicking image named view.jpg. The
image is hyperlink. So please tell me how should i do it. I am showing
my code as follows.
code :
echo "<table width='' height='' border='1' align='center'>
<tr><td>Title</td>
<td >Type</td>
<td >Date</td>
<td>Expiry Date</td>";
if($typeofuser=='admin' || $typeofuser=='Accountant' || $typeofuser=='secretary')
{
echo "<td>View</td>
<td>Edit</td>
<td>Delete</td>";
}
echo "</tr>";
$qry2 = mysqli_query($con,"SELECT nId,nTitle,nDescription,nDate,nExpiryDate FROM tblnoticemanager where Society_id = '$socId' and category='General'") or die(mysqli_error($con));
while($NoticeData = mysqli_fetch_array($qry2))
{
echo "<tr>";
echo "<td align='center' class='tdletter' style='text-transform:capitalize;'>" .$NoticeData['nTitle']. "</td>";
echo "<td align='center' class='tdletter' ><div class='overflowDiv'>" . $NoticeData['nDescription']."</div></td>";
echo "<td align='center' class='tdletter'>" . $NoticeData['nDate'] ."</td>";
echo "<td align='center' class='tdletter'>" . $NoticeData['nExpiryDate'] ."</td>";
if($typeofuser=='admin' || $typeofuser=='Accountant' || $typeofuser=='secretary')
{
echo "<td align='center' class='tdletter'><div><a href='?id=".urlencode(base64_encode($NoticeData['nId']))."'><img src='images/view.png' width='30' height='30' align='center' /></a></div></td>";
echo "<td align='center' class='tdletter'><div><a href='?id=".urlencode(base64_encode($NoticeData['nId']))."' ><img src='images/edit.jpg' width='30' height='30' align='center'/></a></div></td>";
echo "<td align='center' class='tdletter'><span id='".$NoticeData['nId']."' class='trash'><img src='images/delete1.jpg' width='30' height='30' align='center' /></span></td>";
}
echo "</tr>";
}
echo "</table>";
You can use attribute selector [attribute='value']
$("[src='images/view.png']").click(function(){
alert("clicked");
});
I am having some minor errors and was wondering if anyone could help!
I am creating a attendance system for a college.
This Scenario:
Student logs in successfully and then wants to view his/her attendance for a particular course.
Problem: I want it to show me both checked and uncheked data from mysql, it currently shows an empty checkbox (when its meant to be checked) also at the moment it is showing numerous duplicated data, is it possible i could limit that, say for example show one record per week , it shows all data and duplicates it.
<?php
$q3= "SELECT attendance.week_number_id, attendance.week_number, courses.course_id, students.student_id, course_attendance.present, course_attendance.notes
FROM courses, course_attendance, attendance, students
WHERE course_attendance.student_id= ".$_SESSION['student_id']." AND course_attendance.course_id= courses.course_id AND course_attendance.week_id= attendance.week_number_id AND courses.course_id='101'
";
$result = mysql_query($q3) or die(mysql_error());
echo "<table border='1' align='center'><tr> <th><strong>Week Number</strong></th> <th><strong>Present</strong></th> <th><strong>Notes</strong></th> </tr> ";
while($row = mysql_fetch_assoc($result))
{
extract($row);
echo
"</td><td width='200' align='center'>" .$row['week_number'].
"</td><td width='400' align='center'><input type='checkbox' name='present'" .$row['present'].
"</td><td width='400' align='center'>" .$row['notes'].
"</td><tr>";
}
echo "</table>";
?>
Note: I am connected successfully to database, mysql is up and running, i am using sessions, currently it does show data for the student but does not show the existing checked or uncheked value, the checkbox is empty.
Can anyone help
In your code, you're not properly defining the checkbox to be checked. Make a code that adds checked="true" if the 'present' field is 1.
<?php
$q3 = " SELECT attendance.week_number_id, attendance.week_number, courses.course_id, students.student_id, course_attendance.present, course_attendance.notes
FROM courses, course_attendance, attendance, students
WHERE course_attendance.student_id= ".$_SESSION['student_id']." AND course_attendance.course_id= courses.course_id AND course_attendance.week_id= attendance.week_number_id AND courses.course_id='101'";
$result = mysql_query($q3) or die(mysql_error());
echo "
<table border='1' align='center'>
<tr>
<th><strong>Week Number</strong></th>
<th><strong>Present</strong></th>
<th><strong>Notes</strong></th>
</tr>
";
while($row = mysql_fetch_assoc($result)) {
$checked = '';
if($row['present'] == 1) {
$checked = ' checked="true"';
}
echo "
<tr>
<td width='200' align='center'>" . $row['week_number'] . "</td>
<td width='400' align='center'>
<input type='checkbox' name='present'" .$checked . "/>
</td>
<td width='400' align='center'>" . $row['notes'] . "</td>
</tr>
";
}
echo "</table>";
?>
Your
echo
"</td><td width='200' align='center'>" .$row['week_number'].
"</td><td width='400' align='center'><input type='checkbox' name='present'" .$row['present'].
"</td><td width='400' align='center'>" .$row['notes'].
"</td><tr>";
statement should be
$present = "";
if(.$row['present']==1)
{
$present = "checked =checked/>";
}
else
{
$present = "/>";
}
echo
"" .$row['week_number'].
"" .$row['notes'].
"";
Hope this helps you. Thanks
$checked = '';
if($present == 1) {
$checked = 'checked="checked"';
}
echo "</td><td width='200' align='center'>" .$row['week_number'].
"</td><td width='400' align='center'><input type='checkbox' name='present'" .$checked . "/>" .
"</td><td width='400' align='center'>" .$row['notes'].
"</td><tr>";
}
echo "</table>";
Try.
I have multiple books that people can order. All those books are stored in a MySQL database.
People can enter value's (INT) into a textfield. Example: Book One value = [5].
But when I enter submit it will only show the last entered value of that textfield.
How can I arrange, that if people only enter value's in some textfields and then hit submit they see what product they ordered and the value with it. Thanks :)
My code
<table width="990">
<form name="form" action="<?php $_SERVER['PHP_SELF']; ?>" method="post">
<tr>
<td width="93" class="main">Bestelnummer</td>
<td width="550" class="main">Titel</td>
<td width="100" class="main">Categorie</td>
<td width="150" class="main">Type Onderwijs</td>
<td width="80" class="main">Groep</td>
<td width="50" class="main">Prijs</td>
<td width="40" class="main">Aantal</td>
</tr>
<?php
// Laat Resultaten zien
$s = "SELECT * FROM producten ORDER BY id ASC";
$sql = (mysql_query($s))or die ("FOUT: " . mysql_error());
while($row = mysql_fetch_array($sql))
{
$id = $row['id'];
echo "<tr>";
echo "<td width='93'>" .$row['bestelnummer']. "</td>";
echo "<td width='550'><a href='".$row['link']."' target='_blank' title='".$row['titel']."' >" .$row['titel']. "</a></td>";
echo "<td width='100'>" .$row['categorie']. "</td>";
if ($row['onderwijs'] == "BO") { echo "<td width='150'>Basis Onderwijs</td>"; } elseif ($row['onderwijs'] == "VO") { echo "<td width='150'>Voortgezet Onderwijs</td>"; } else { }
echo "<td width='80'>" . $row['groep'] . "</td>";
if ($row['prijs'] == 0) { echo "<td width='50'><i>gratis</i></td>"; } else { echo "<td width='50'>€ " .$row['prijs']. "</td>"; }
echo "<td width='40'><input type='text' name='nummer".$id."' title='nummer".$id."' class='aantal' maxlength='4' /></td>";
echo "</tr>";
}
?>
<tr>
<td><input type="submit" name="submit" value="Plaats bestelling" class="verzend"/></td>
</tr>
</form>
</table>
<?php if (isset($_POST['submit']))
{
if (empty($_POST['aantal']))
{
echo "L33g";
}
else
{
$_POST['nummer".$id."'];
}
}?>
You would be better off using an array so use
<input type='text' name='nummer[".$id."]' title='nummer".$id."' class='aantal' maxlength='4' />
Then replace
$_POST['nummer".$id."'];
with
foreach($_POST['nummer'] as $value) {
echo $value;
}