I have 4 tables for student attendance.
Students (sid, name, regno)
classes (classid, startdate, enddate)
Student to Classes (sid, classid)
class attendance (classid, sid, attendance, date)
I want to display attendance data of a class as:
<table>
<tr>
<th>RegNo</th>
<th>Name</th>
<th>Date 1</th>
<th>Date 2</th>
<th>so on</th>
</tr>
<tr>
<td>1</td>
<td>ABC</td>
<td>Present</td>
<td>Absent</td>
<td>So on</td>
</tr>
</table>
Date range is from classes table. I want to query the tables with date range as well as for all record of a class.
Kindly help me with the query. Thanks in advance.
Related
I need to modify my WooCommerce orders page but I don't have the experience for this. At the moment (like in normal case) my orders page looks like this:
Yesterday I've added a second id attribute to each order where I can set a custom customer id (user_id in Wordpress). This field is named "second_customer".
I'm doing this because I want to show the order taken by customer one to an other customer too in case the "second_customer" has his user_id as value.
Now I need to modify the orders.php and modify it so that the orders gets loaded to for the "second_customer" on his account and the normal way too. So my question is: How can I get exacly the row like in the picture (the order) for the user id defined in my custom attribute?
As your question:
How can I get exacly the row like in the picture
use the table HTML elements like will result like the screen shoot above with 5 headings rows with table headings- and table rows- :
<table style="width:100%">
<tr>
<th>Product Id</th>
<th>Date</th>
<th>Status</th>
<th>Address</th>
<th>Name</th>
</tr>
<tr>
<td>#356</td>
<td>30 September</td>
<td>Customer</td>
<td>10 Address st, China</td>
<td>John Doe</td>
</tr>
<tr>
<td>#357</td>
<td>30 September</td>
<td>Customer</td>
<td>32 Address st, Porland</td>
<td>Sarah smith</td>
</tr>
<tr>
<td>#358</td>
<td>29 September</td>
<td>Customer</td>
<td>55 Address st, New York</td>
<td>Ben Barber</td>
</tr>
</table>
How can i create database tables using controllers in laravel. Is there any way?
Actually I want to create a table using another table column values.
Eg:
I have two tables called table1 and table2.
<table>
<thead>
<td>id</td>
<td>name</td>
</thead>
<tr>
<td>1</td>
<td>raj</td>
</tr>
<tr>
<td>2</td>
<td>john</td>
</tr>
<tr>
<td>3</td>
<td>sam</td>
</tr>
</table>
and I want the names as field names in table2
<table>
<thead>
<td>raj</td>
<td>john</td>
<td>sam</td>
</thead>
</table>
And I want to create table2 using controller
Why do you want to do that!? I see no reasons!
Anyway you can use raw query in controller :
DB::raw(' CREATE TABLE . .. ');
I retrieve data from DB and I need to insert all of them in a table.
I have some constant headers and some that depends on the query results.
Below you can see a table; how i want it to look like:
I did prepare the HTML structure:
<table class="table-fill">
<thead>
<tr>
<th>ID</th>
<th>CODE</th>
<th colspan=2>TREND A</th>
<th colspan=2>TREND B</th>
<th colspan=2>TREND C</th>
</tr>
<tr>
<th></th>
<th></th>
<th>Items</th>
<th>Revenue</th>
<th>Items</th>
<th>Revenue</th>
<th>Items</th>
<th>Revenue</th>
</tr>
</thead>
<tbody class="table-hover">
<tr>
<td>1</td>
<td>A</td>
<td>10</td>
<tD>150</td>
<td>5</td>
<tD>200</td>
<td>8</td>
<tD>120</td>
</tr>
</tbody>
No problem so far. The hard part is to use actual data from DB and insert them to the table.
Headers "trend a", "trend b" etc are not constants. The below tables will be displayed on different countries. Some countries have specific trend names. Let's say England has "Trend A", "Trend B" and "Trend D". Italy has only "Trend A" etc.
Is it possible to write php code and in some way auto generate the table headers based on the query results?
And then split the results by trend so that correct values will go to correct trend?
I know how to do a simple table like:
$sql_r = "SELECT o.id, o.code, tl.name, ts.items, ts.revenue
FROM overview o, trend_stats ts, trend_lang tl
WHERE o.id_shop = '1'
AND o.id = ts.id
AND ts.id_trend = tl.id_trend";
$data_to_output = Db::getInstance()->ExecuteS($sql_r);
foreach ($data_to_output as $data) {
echo '
<tr>
<td>'.$data['id'].'</td>
<td>'.$data['code'].'</td>
<td>'.$data['trend'].'</td>
<td>'.$data['items'].'</td>
<td>'.$data['revenue'].'</td>
</tr>
';
}
But I'm not sure how to split and structure them the way I want them to be. If there's any tutorial or anything online related to what I'm asking I'm happy to check it out. Thank you
I don't think you can do that other than rewrite your headers. The fact that you want to retrieve your informations from your database tells that you'll have to work with any kind of loop. So you first have to display your headers and then display your informations. The only way is to store somewhere in your loop the value that will change your headers when it changes, and add another line of header when the value actually changes. You can do that with just a simple if condition.
<table border='1' cellspacing='0' cellpading='0'>
<tr>
<th>Month</th>
<th>Date</th>
</tr>
<tr>
<th>1st month</th>
<th>2/12/2014</th>
</tr>
<tr>
<th>2nd month</th>
<th>2/1/2015</th>
</tr>
<tr>
<th>3rd month</th>
<th>2/2/2015</th>
</tr>
<tr>
<th>4th month</th>
<th>2/3/2015</th>
</tr>
<tr>
<th>5th month</th>
<th>2/4/2015</th>
</tr>
<tr>
<th>6th month</th>
<th>2/5/2015</th>
</tr>
<table>
I have user below query which add next month only i'm expection how to increment one value in mysql ?
INSERT INTO tbl_book(book_date) VALUES (now( ) + INTERVAL 1 MONTH)
i'm expecting single query to below table
Plan A: Write a Stored Procedure with a loop and a counter.
Plan B: Create a table of integers, SELECT from table, stop at 6, and use the integer in the date arithmetic:
INSERT INTO tbl_book (book_date)
SELECT CURDATE() + INTERVAL n MONTH
FROM integers
WHERE n BETWEEN 1 AND 6;
Use the dateadd function of mysql.
DATE_ADD(date,INTERVAL expr type)
You would want the Interval to be "MONTH"
INSERT INTO tbl_book(book_date) VALUES (date_add(now( ), INTERVAL 1 Month);
You can find more details at http://www.techonthenet.com/mysql/functions/date_add.php
I have a table with a first column called: "Fruit", and a last column called: "Total"
And any columns in between are dynamically created by the number of students.
Below is what I'm looking to dynamically make, from what the database shows so far.
<table border="1">
<tr>
<th>Fruit</th>
<th>Sally</th>
<th>John</th>
<th>Total</th>
</tr>
<tr>
<td>apples</td>
<td>5</td>
<td>3</td>
<td>8</td>
</tr>
<tr>
<td>bananas</td>
<td>3</td>
<td>5</td>
<td>8</td>
</tr>
<tr>
<td>Oranges</td>
<td>3</td>
<td>3</td>
<td>6</td>
</tr>
<tr>
<td></td>
<td>11</td>
<td>11</td>
<td>22</td>
</tr>
</table>
Here's the difficulties I run into. The fruit names, students, and fruit consumed are pulled from the database.
And I don't know how many fruit rows nor student columns there will be.
This is as far as I got:
<table>
<tr>
<th>Fruit</th>
<?php $sqlS = db("SELECT s.*, sf.consumed FROM `tbl_students` s, `tbl_students_fruit` sf WHERE s.studentid = f.studentid ORDER BY s.studentname ASC");
while($student = mysql_fetch_array($sqlS)){ ?>
<th><?php echo $student['studentname'];?></th>
<?php } ?>
<th>Total</th>
</tr>
<?php $sqlF = db("SELECT * FROM `tbl_fruit` ORDER BY fruitname ASC");
while($fruit = mysql_fetch_array($sqlF)){ ?>
<tr>
<td><?php echo $fruit['fruitname'];?></th>
<td></td>
<td></td>
</tr>
<? } ?>
</table>
As you can see, I'm creating the Fruit rows, and Student columns. But it's incomplete. I've only created the column headers, and not the columns below the headers. From this point I am stuck on the guts of the table.
I am sure arrays are the way to go with this monstrosity. But the only way my feeble brain can make this work is to have more queries, which I'm sure is a very wrong way to do this.
If there were 3 students or 15 students, I can make them appear in the table th columns, but not in rows in their columns.
How does one traverse dynamic columns this way?
And if my demo above is confusing, I don't blame you!
well, I am assuming that your db structure is as follows:
[tbl_students]
studentid, studentname
[tbl_fruit]
fruitid, fruitname
[tbl_students_fruit]
id, fruitid, studentid, consumed
http://pastebin.com/CxPUeXR0
I haven't tested it, so good luck