How to put multiple tables in the DataTable jQuery plugin - php

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

Related

How do I only retrieve data from the first table when web-scraping?

I only know the basics of scraping webpages using php simple html dom. The webpage has several tables on it, all with the same classes - so nothing unique to each table.
<table class="table">
<tr>
<td>item 1</td>
<td>item 2</td>
<td>item 3</td>
</tr>
</table>
<table class="table">
<tr>
<td>item 4</td>
<td>item 5</td>
<td>item 6</td>
</tr>
</table>
<table class="table">
<tr>
<td>item 7</td>
<td>item 8</td>
<td>item 9</td>
</tr>
</table>
The code I have is working, however it's returning data from ALL tables, and I only want data from the first table. I'm using the following to find the rows of data :
$d1s = $dom->find('table.table tr');
I'm assuming it's a simple error I've made. Can anyone help ?

How to show mysql multi row / mysql_fetch_array results in a table?

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>
}

how to show the count of particular name? & show it page using php sql?

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'];
}
?>

Pass the values between two tables

I develop a transaction function here. But I have a trouble with javascript. As you can see below, there are two table, where the first one is for display the item and the second table is for purchasing. What i want to do is, the row for an item in first table is clickable. When the row is clicked, the item that have been choose come out in the second table. And at the second table cell for discount can be editable and the total price is changing by the discount. Can anyone help me to pass the value between these two tables?
<fieldset>
<legend>Item Show</legend>
<table border="1">
<tr>
<td>Item Name</td>
<td>Item Code</td>
<td>Manufacturer</td>
<td>Price</td>
<td>Stock</td>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
?>
<tr>
<td><?php echo $row['item_name']; ?></td>
<td><?php echo $row['item_code']; ?></td>
<td><?php echo $row['item_manufacturer']; ?></td>
<td><?php echo $row['sell_price']; ?></td>
<td><?php echo $row['stock']; ?></td>
</tr>
<?php
}
?>
</table>
</fieldset>
<fieldset>
<legend>Item Sale</legend>
<table border="1">
<tr>
<td>Item name</td>
<td>Item Code</td>
<td>Stock</td>
<td>Price</td>
<td>Quantity</td>
<td>Discount</td>
<td>Total Price</td>
</tr>
</table>
</fieldset>
Here are the steps that you should follow.
give a common class to all your like
use jQuery events like
$(".clickable").on('click',function(e,this){
//a.use "this" here to extract values that you want to pass to other table
//b.append <tr><td></td>....</tr> with this.values to your table
})
If you can do the above - - things will go fine

PHP table creation with arrays

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

Categories