I am very close on this but still having a problem with the listing of events. What I am looking for is for the title, date and event to show once with a list of names who participated in that event. Now I am getting an event, date and title printed as many times as names, with only one name showing in each.
I have tried GROUP BY on several fields but nothing seems to work.
SELECT x.xdate, x.xevent, x.xname, x.xaffirm, y.activity, y.title,
y.text, y.date
FROM x LEFT JOIN y ON x.xdate = y.date
WHERE xevent='Hiking' AND xaffirm='Yes'
ORDER BY y.date DESC")
Print "<table width=500>";
while($info = mysql_fetch_array( $data ))
{
Print "<tr>";
Print
"<th style='width:225px;' bgcolor=#49A78D align=center >Title</th>
<th style='width:300px;' bgcolor=#49A78D align=center >Text</th>
<th style='width:175px;' bgcolor=#49A78D align=center >Date</th>
<th style='width:175px;' bgcolor=#49A78D align=center >Name</th>";
Print "</tr>";
Print "<tr>";
Print
"<td bgcolor=#ffffff valign=top align=center>".$info['title'] . "</td>
<td bgcolor=#ffffff valign=top align=left>".$info['text'] . "</td>
<td bgcolor=#ffffff valign=top align=left>".$info['date'] . "</td>
<td bgcolor=#ffffff valign=top align=left>".$info['name'] . "</td>";
Print "</tr>";
This is what I am getting now:undesired
This is what I would like to get: desired
What I'd probably do is to have a single variable that denotes "does the data in this row correspond to a new event, or is it additional data for the same event?"
If the date doesn't match, it's a new event; first, add a new header row, then add a new row with data for all four columns. If the date does match, then skip the header and add a row where the first three columns are empty and the fourth has the new name. (Apologies if my PHP doesn't quite compile, it's been a while.)
$lastEventDate = '';
Print "<table width=500>";
while($info = mysql_fetch_array( $data ))
{
if ($lastEventDate != $info['date'])
{
Print "<tr>";
Print
"<th style='width:225px;' bgcolor=#49A78D align=center >Title</th>
<th style='width:300px;' bgcolor=#49A78D align=center >Text</th>
<th style='width:175px;' bgcolor=#49A78D align=center >Date</th>
<th style='width:175px;' bgcolor=#49A78D align=center >Name</th>";
Print "</tr>";
}
Print "<tr>";
if ($lastEventDate == $info['date'])
{
Print "<td colspan=3 />"
}
else
{
Print
"<td bgcolor=#ffffff valign=top align=center>".$info['title'] . "</td>
<td bgcolor=#ffffff valign=top align=left>".$info['text'] . "</td>
<td bgcolor=#ffffff valign=top align=left>".$info['date'] . "</td>"
}
Print "<td bgcolor=#ffffff valign=top align=left>".$info['name'] . "</td>";
Print "</tr>";
$lastEventDate = $info['date'];
}
Also, I'm unsure whether what you actually want is separate tables; if so, then inside the first if block, you can close the first table, then open a new one.
Related
How can I display the number based on the number of data from database.
For example, the above picture, shows data extract from the database. In my database there are two data. Therefore I would like to display number 1 and 2 at the No column.
And if there is four data in the database, I would like to display number 1, 2, 3 and 4 at the No column.
Coding to display the above table
<?php
$sql= mysql_query ("SELECT * FROM employee INNER JOIN cash ON employee.emp_id = cash.emp_id WHERE cash_status='Pending'");
echo "<table id='dataTable' width='850' border='1' align='center'>";
echo "<tr>
<th height='50'>No</th>
<th height='50'>Employee Number</th>
<th height='50'>Name</th>
<th height='50'>Department</th>
<th height='50'>Date Apply</th>
<th height='50'>Date Cash To Be Use</th>
<th height='50'>Amount</th>
<th height='50'>Status</th>
<th height='50'>Cash Id</th>
<th height='50'>View</th>
</tr>";
while ($row = mysql_fetch_array($sql))
{
echo "<tr>";
echo "<td align='center' height='30'></td>";
echo "<td align='center' height='30'>" .$row['emp_id']. "</td>";
echo "<td align='center' height='30'>" .$row['emp_name']. "</td>";
echo "<td align='center' height='30'>" .$row['emp_department']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_dapply']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_duse']. "</td>";
echo "<td align='center' height='30'>RM" .$row['cash_amount']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_status']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_id']. "</td>";
echo"<td height='30'><img src='../img/view_user.png' width='20' height='20'></td>";
echo "</tr>";
}
echo "</table>";
?>
Thanks.
Try with the Below Code :
<?php
$i = 0;
$sql= mysql_query ("SELECT * FROM employee INNER JOIN cash ON employee.emp_id = cash.emp_id WHERE cash_status='Pending'");
echo "<table id='dataTable' width='850' border='1' align='center'>";
echo "<tr>
<th height='50'>No</th>
<th height='50'>Employee Number</th>
<th height='50'>Name</th>
<th height='50'>Department</th>
<th height='50'>Date Apply</th>
<th height='50'>Date Cash To Be Use</th>
<th height='50'>Amount</th>
<th height='50'>Status</th>
<th height='50'>Cash Id</th>
<th height='50'>View</th>
</tr>";
while ($row = mysql_fetch_array($sql))
{
echo "<tr>";
echo "<td align='center' height='30'>".$++i."</td>";
echo "<td align='center' height='30'>" .$row['emp_id']. "</td>";
echo "<td align='center' height='30'>" .$row['emp_name']. "</td>";
echo "<td align='center' height='30'>" .$row['emp_department']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_dapply']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_duse']. "</td>";
echo "<td align='center' height='30'>RM" .$row['cash_amount']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_status']. "</td>";
echo "<td align='center' height='30'>" .$row['cash_id']. "</td>";
echo"<td height='30'><img src='../img/view_user.png' width='20' height='20'></td>";
echo "</tr>";
}
echo "</table>";
?>
#Hardy Change .$++i. to .++$i.
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>
I have working code that brings in data from my database as follows:
require("database.php");
$result = mysqli_query($con,"SELECT * FROM menuitem");
echo "<table width='1024' border='0' cellpadding='10' cellspacing='5' align='center'>
<tr>
<th></th>
<th>Menu Items</th>
<th>Description</th>
<th>Price</th>
<th>Add to Order</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td align='center'><img src=\"" . $row['picturepath'] . "\" /></td>";
echo "<td align='center'>" . $row['name'] . "</td> <td align='center'> <input type='button' value='More Info'; onclick=\"window.location='more_info.php?';\"> </td>";
echo "<td align='center'>" . $row['price'] . "</td> <td align='center'> <input type='button' value='Add to Order' onclick=''> </td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
However, the columns that I am calling have over 20 items. I want to limit the amount of items the page displays to 4 items per page, and then create multiple pages listing the remaining items in the database.
So far I have tried adding in the if then statement, but that didn't work very well. I'm not sure if that is even the correct way to go about it.
SELECT * FROM menuitem LIMIT $startPositionVariable,$howManyItemsPerPageVariable
a separate query should determine how many total entries there are to begin with and determine how many pages accordingly.
I have some code within my php script that connects to my database, and then displays a list of food items. It works pretty well, but now I need to create a button that links to another page for each specific item in the table. I know this is wrong, but I'm trying to learn so that's why I'm here.
require("database.php");
$result = mysqli_query($con,"SELECT * FROM entrees_menu_table");
echo "<table width='1024' border='0' cellpadding='10' cellspacing='5' align='center'>
<tr>
<th></th>
<th>Menu Items</th>
<th>Description</th>
<th>Price</th>
<th>Add to Order</th>
</tr>";
while($row = mysqli_fetch_array($result)) {
echo "<tr>";
echo "<td align='center'><img src='./img/burger.png'></td>";
echo "<td align='center'>" . $row['entrees_item'] . "</td> <td align='center'> <input type='button' value='More Info' onclick='location.href('http://www.gmail.com');'> </td>";
echo "<td align='center'>" . $row['entrees_price'] . "</td> <td align='center'> <input type='button' value='Add to Order' onclick=''> </td>";
echo "</tr>";
}
echo "</table>";
mysqli_close($con);
In the above code, the MORE INFO input button needs to redirect to a new page, and display the entree_item_description from my database for each entrees_item. Would I have to completely re-do my entire code to make this happen? I'm lost so far, and was trying to test out onclick with a location, but it's not working at all.
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.