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>
Related
This question already has answers here:
PHP parse/syntax errors; and how to solve them
(20 answers)
Closed 6 years ago.
Trying to get values from mysql into <select> tag.
I have used while loop & getting data from 2 different tables.
I have tried the given code but not able to get the data.
Please Help!
<?php
$host="localhost"; // Host name
$username="root"; // Mysql username
$password=""; // Mysql password
$db_name="test"; // Database name
// Connect to server and select databse.
$conn=mysqli_connect($host,$username,$password) or die("cannot connect");
mysqli_select_db($conn,$db_name);
$result = mysqli_query($conn,"SELECT * from dummy");
$uresult=mysqli_query($conn,"SELECT name from user where role='Support'");
$uname=array();
while ($rows=mysqli_fetch_array($uresult))
{
$uname[]=$rows['name'];
}
echo "<table border='1' width='100%' >
<tr><th colspan='7' ><h2 align='center'>Details</h2></th></tr>
<tr bgcolor='grey'>
<th width='10%' class='text-center'>Emp No.</th>
<th width='15%' class='text-center'>Name</th>
<th width='30%' class='text-center'>Task</th>
<th width='20%' class='text-center'>Assigned To</th>
</tr>";
while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td align='center'>" . $row['emp_no']. "</td>";
echo "<td align='center'>" . $row['emp_name']. "</td>";
echo "<td align='center'>" . $row['task'] . "</td>";
echo "<td align='center'> <select name='select1'> <?php while ($rows=mysqli_fetch_array($uresult)) { ?><option><?php echo $rows['name'];?> </option><?php } ?> </select> </td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($conn);
?>
Error :
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING)
Error is with below line
you have php code inside the string
echo "<td align='center'> <select name='select1'> <?php while ($rows=mysqli_fetch_array($uresult)) { ?><option><?php echo $rows['name'];?> </option><?php } ?> </select> </td>";
No need to fetch it over again. You've already done that here:
$uname = array();
while ($rows = mysqli_fetch_array($uresult)) {
$uname[] = $rows['name'];
}
So inside the other while block, just use that names that already gathered:
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td align='center'>" . $row['emp_no']. "</td>";
echo "<td align='center'>" . $row['emp_name']. "</td>";
echo "<td align='center'>" . $row['task'] . "</td>";
echo "
<td align='center'>
<select name='select1'>
";
foreach($uname as $names) {
echo '<option>' . $names . '</option>';
}
echo "
</select>
</td>";
echo "</tr>";
}
Or just create an HTML string of <options> with the $uname, then just echo it inside the while:
$uname = '';
while ($rows = mysqli_fetch_array($uresult)) {
$uname .= '<option>' . $rows['name'] . '</option>';
}
Then on the while block:
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td align='center'>" . $row['emp_no']. "</td>";
echo "<td align='center'>" . $row['emp_name']. "</td>";
echo "<td align='center'>" . $row['task'] . "</td>";
echo "
<td align='center'>
<select name='select1'>
";
echo $uname; // collection of HTML string options
echo "
</select>
</td>";
echo "</tr>";
}
Try like this, embedding php in html
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td align='center'><?php echo $row['emp_no'] ?></td>
<td align='center'><?php echo $row['emp_name'] ?></td>
<td align='center'><?php echo $row['task'] ?></td>
<td align='center'> <select name='select1'>
<?php while ($rows=mysqli_fetch_array($uresult)) { ?>
<option><?php echo $rows['name'];?> </option><?php } ?>
</select> </td>
</tr>";
<?php
}
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>
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.