<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
Related
I am planning to make a schedule for the bus however, I've encounter some problems that I do not know how to resolve.
Desired output
What I got:
View:
foreach($wkdayBus as $row){
$time = $row->busTime;
$busstop = $row->busStop;
echo "<tr><th>".$busstop."</th>";
echo "<td>".$time."</td></tr>";
}
Model
function getWeekdayBusSchedule() {
$query=$this->db->query("SELECT busStop,busTime from busschedule inner join bustime on busschedule.busScheduleID=bustime.busScheduleID WHERE dayType = 'Weekday';");
$results = array();
foreach ($query->result() as $result) {
$results[] = $result;
}
return $results;
}
You are parsing the time in the false dimension. Your table should look like this:
<tr>
<th>Bust Stop 1</th>
<th>Bust Stop 2</th>
</tr>
<tr>
<td>Bus Stop 1 time 1</td>
<td>Bus Stop 2 time 1</td>
</tr>
<tr>
<td>Bus Stop 1 time 2</td>
<td>Bus Stop 2 time 2</td>
</tr>
...
Currently it look something like this:
<tr>
<th>Bust Stop 1</th>
<td>Bust Stop 1 time 1</td>
</tr>
<tr>
<th>Bust Stop 1</th>
<td>Bust Stop 1 time 2</td>
</tr>
<tr>
<th>Bust Stop 1</th>
<td>Bust Stop 1 time 3</td>
</tr>
<tr>
<th>Bust Stop 2</th>
<td>Bust Stop 2 time 1</td>
</tr>
<tr>
<th>Bust Stop 2</th>
<td>Bust Stop 2 time 2</td>
</tr>
<tr>
<th>Bust Stop 2</th>
<td>Bust Stop 2 time 3</td>
</tr>
Also I recommend you to use the PHP date function to format your time properly.
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.
I am trying to show mysql_fetch_array() results in a table.
I want to show guests name,their country and their agreed time who are traveling on a same date.
Following code works fine. The code fetches the row values and prints it.
$select_guests = mysql_query('SELECT name FROM van_sharing WHERE date = "'.$serch_text.'"') or die(mysql_error()); // query for getting guests for the same date
while($row = mysql_fetch_array($select_guests, MYSQL_ASSOC)) { //visitor / guest loop starts here
echo $row['name'].'<br/>';
}
$select_country = mysql_query('SELECT country FROM van_sharing WHERE date = "'.$serch_text.'"') or die(mysql_error()); // query for getting guests for the same date
while($row = mysql_fetch_array($select_country, MYSQL_ASSOC)) { //country of visitor / guest loop starts here
echo $row['country'].'<br/>';
}
$select_agreed_time = mysql_query('SELECT agreed_time FROM van_sharing WHERE date = "'.$serch_text.'"') or die(mysql_error()); // query for getting guests for the same date
while($row = mysql_fetch_array($select_agreed_time, MYSQL_ASSOC)) { //visitor / guest agreed time loop starts here
echo $row['agreed_time'].'<br/>';
}
if there are 5 guests for a same date I am getting all of their names one below another when I execute the above code. Same I am getting there countries and agreed time too.
Now I want to show those results in a HTML table.
I tried several line of code but nothing works.
My HTML table should be as following:
<table class="table-fill">
<thead>
<tr>
<th class="text-left">Name</th>
<th class="text-left">From</th>
<th class="text-left">Agreed Time</th>
</tr>
</thead>
<tbody class="table-hover">
<tr>
<td class="text-left">Name 1</td>
<td class="text-left">Country 1</td>
<td class="text-left">Ag Time 1</td>
</tr>
<tr>
<td class="text-left">Name 2</td>
<td class="text-left">Country 2</td>
<td class="text-left">Ag Time 2</td>
</tr>
<tr>
<td class="text-left">Name 3</td>
<td class="text-left">Country 3</td>
<td class="text-left">Ag Time 3</td>
</tr>
<tr>
<td class="text-left">Name 4</td>
<td class="text-left">Country 4</td>
<td class="text-left">Ag Time 4</td>
</tr>
<tr>
<td class="text-left">Name 5</td>
<td class="text-left">Country 5</td>
<td class="text-left">Ag Time 5</td>
</tr>
</tbody>
</table>
How can create that table td s according to my mysql_fetch_array() ?
The above table structure is for 5 guests found or resulted by mysql_fetch_array()
First of all I think you dont need 3 different queries for your solution..
<table class="table-fill">
<thead>
<tr>
<th class="text-left">Name</th>
<th class="text-left">From</th>
<th class="text-left">Agreed Time</th>
</tr>
</thead>
<?php
$result = mysql_query('SELECT name,country,agreed_time FROM van_sharing WHERE date = "'.$serch_text.'"') or die(mysql_error());
while($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
?>
<tr>
<td>
<?php echo $row['name']; ?>
</td>
<td>
<?php echo $row['country'];?>
</td>
<td>
<?php echo $row['agreed_time']; ?>
</td>
</tr>
<?php
}
?>
</table>
Firstly, you should use mysqli.
Secondly, shouldn't be sending so many queries to the database for information you can get in one query;
$select_guests = $mysqli->query('SELECT * FROM van_sharing WHERE date = "'.$serch_text.'"') or die(mysql_error());
Next, you want to fetch the number of rows.
$rows = $mysqli
You should also look into the PHP for function;
for ($i = 1; $i < $rows; $i++) {
$thisRow = $select_guests->fetch_row()
echo
' <tr>
<td class="text-left">'.$select_guests['name'].'</td>
<td class="text-left">'.$select_guests['country'].'</td>
<td class="text-left">'.$select_guests['time'].'</td>
</tr>
'; //This last line is to insert a line break and indent (for tidy HTML)
}
Give this a go, hopefully I've helped you.
I haven't completely solved it for you though, in order to change over to mysqli, you will need to make a few small changes which you can find in the mysqli link I sent you. The benefits are worth it.
$select_all = mysql_query('SELECT * FROM van_sharing WHERE date = "'.$serch_text.'"') or die(mysql_error()); // query for getting all details for the same date
while($row = mysql_fetch_array($select_all , MYSQL_ASSOC)) {//loop starts here
<tr>
<td>
<?php echo $row['name']; ?>
</td>
<td>
<?php echo $row['country'];?>
</td>
<td>
<?php echo $row['agreed_time']; ?>
</td>
</tr>
}
i have a agent table
& where all agent details hai been display.
So along with the details i want to show count the agent name has been displayed in the table in same table.
i tried this query
Select count(name) from agent;
but it shows whole table count.
i want result to be this:
<table border="1">
<tr>
<td>name</td>
<td>count</td>
</tr>
<tr>
<td>bhaskar</td>
<td>1</td>
</tr>
<tr>
<td>amit</td>
<td>4</td>
</tr>
<tr>
<td>sushant</td>
<td>8</td>
</tr>
</table>
2/5
Saurabh 4/5
bt wat i m getting is this:
<table border="1">
<tr>
<td>name</td>
<td>count</td>
</tr>
<tr>
<td>bhaskar</td>
<td>13</td>
</tr>
<tr>
<td>amit</td>
<td>13</td>
</tr>
<tr>
<td>sushant</td>
<td>13</td>
</tr>
</table>
so how to show particular name count in table row in php page??
Try this
select count(name)as count,name from agent group by name
Update code
<?php $query=mysql_query("SELECT count(name) as count,phone,email,t_id,name FROM transfer WHERE agent_id='$id' group by name ORDER BY t_id DESC"); while($row=mysql_fetch_array($query)) {
echo $row['name'];
echo $row['count'];
}
?>
I've been using this PLUGIN for representing my data from mysql database.
I am using this script EXAMPLE for server side processing.
Now this script is working perfectly why you have one table. But problem is occurring when I have multitable query.
For example I have:
$sWhere = "a.ID=b.ID AND b.Name=c.Name";
This is only where variable. If you go to the link that I gave you can see the php script that is used to fetch data. When I put more then one table I get unique table error. And the search functions can't work.
Can someone show me how to use this script to be able to have multiple tables included in one query.
If you need more source let me know.
EDIT:
My HTML:
<table id="table_my" width="100%" border="1" cellspacing="2" cellpadding="5" class="chart_1">
<thead>
<tr class="even">
<th>A</th>
<th>B</th>
<th>C</th>
<th>D</th>
<th>E</th>
<th>F</th>
<th>G</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
There should be a change in the HTML Markup, when that multitable query executes. Why don't you compare both and check for the difference in the HTML Markup?
The markup for DataTable jQuery plugin should be this way:
<table>
<thead>
<tr>
<th>Column Name</th>
<th>Column Name</th>
<th>Column Name</th>
</tr>
</thead>
<tbody>
<tr>
<td>Row Value</td>
<td>Row Value</td>
<td>Row Value</td>
</tr>
<tr>
<td>Row Value</td>
<td>Row Value</td>
<td>Row Value</td>
</tr>
<tr>
<td>Row Value</td>
<td>Row Value</td>
<td>Row Value</td>
</tr>
<tr>
<td>Row Value</td>
<td>Row Value</td>
<td>Row Value</td>
</tr>
</tbody>
</table>
Also remember, it doesn't work with more than one tbody or thead tag and tables without these tags. Also, if you have used colspan and rowspan attributes, it doesn't work.
from www.facebook.com/Heanock Z behere Ethiopia
*
Answer for the above problem
*
i just use like i am using in php or other language and i have two tables to be joined
tbl_employees
**
emp_id
** int(11) auto_increment primary key,
emp_name varchar(50),
sex enum('female','male'),
emp_dept varchar(50),
emp_salary double,
job int(11) = is foreign key that i will share from the second table
tbl_job
**
job_id
** int(11) primary key,
job_name varchar(50),
job_cat varchar950)
lastly here is my code in php mysql plus datatable
Emp ID
Emp Name
Sex
Department
Salary
Job
Edit
Delete
$stmt = $db_con->prepare("SELECT emp_id,emp_name,sex,emp_dept,emp_salary,job_name FROM tbl_employees,tbl_job where job=job_id ORDER BY emp_id DESC");
$stmt->execute();
while($row=$stmt->fetch(PDO::FETCH_ASSOC))
{
?>
<tr>
<td><?php echo $row['emp_id']; ?></td>
<td><?php echo $row['emp_name']; ?></td>
<td><?php echo $row['sex']; ?></td>
<td><?php echo $row['emp_dept']; ?></td>
<td><?php echo $row['emp_salary']; ?></td>
<td><?php echo $row['job_name']; ?></td>
if you have any question related with above problem write me # heanocklove#gmail.com or My facebook Page listed Above
Thanks very much