display column data in each table data - php

---------------------------------------------------------------------
Quantity | Unit | Detials of Items | ISSUED DATE | RETURNED |
| | | | |
---------------------------------------------------------------------
tbl col 1 |tbl col2 | tbl col2 | tbl col 3 | tbl col4 |
---------------------------------------------------------------------
say I have a table in the database that has 4 columns
and that is the table in my website
how would i display my table column data in each table data?
any suggestion please
I only have this codes so far as I am new to php i just use macromedia for the interface
$myServer = "server";
$myUser = "user";
$myPass = "password";
$myDB = "mssqldb";
//connection to the database
$dbhandle = mssql_connect($myServer, $myUser, $myPass)
or die("Couldn't connect to SQL Server on $myServer");
//select a database to work with
$selected = mssql_select_db($myDB, $dbhandle)
or die("Couldn't open database $myDB");
//declare the SQL statement that will query the database
$query = "SELECT eidnumber ";
$query .= "FROM tablename ";
<table width="935" height="102" border="1">
<tr>
<th width="89" rowspan="2" scope="col">Quantity</th>
<th width="87" rowspan="2" scope="col">Unit</th>
<th width="137" rowspan="2" scope="col">Details of Item(s) Accounted </th>
<th width="221" rowspan="2" scope="col">ISSUED DATE </th>
<th height="51" colspan="3" scope="col">RETURNED</th>
<th width="254" rowspan="2" scope="col">
<p>REMARKS</p> </th>
</tr>
<tr>
<th width="24" height="39" scope="col">C</th>
<th width="18" scope="col">X</th>
<th width="53" scope="col">DATE</th>
</tr>
</table>
<table width="935" border="1">
<tr>
<td width="90"> </td>
<td width="86"> </td>
<td width="137"> </td>
<td width="221"> </td>
<td width="24"> </td>
<td width="17"> </td>
<td width="55"> </td>
<td width="253"> </td>
</tr>
<tr>
<td width="90"> </td>
<td width="86"> </td>
<td width="137"> </td>
<td width="221"> </td>
<td width="24"> </td>
<td width="17"> </td>
<td width="55"> </td>
<td width="253"> </td>
</tr>
<tr>
<td width="90"> </td>
<td width="86"> </td>
<td width="137"> </td>
<td width="221"> </td>
<td width="24"> </td>
<td width="17"> </td>
<td width="55"> </td>
<td width="253"> </td>
</tr>
<tr>
<td width="90"> </td>
<td width="86"> </td>
<td width="137"> </td>
<td width="221"> </td>
<td width="24"> </td>
<td width="17"> </td>
<td width="55"> </td>
<td width="253"> </td>
</tr>
<tr>
<td width="90"> </td>
<td width="86"> </td>
<td width="137"> </td>
<td width="221"> </td>
<td width="24"> </td>
<td width="17"> </td>
<td width="55"> </td>
<td width="253"> </td>
</tr>
<tr>
<td width="90"> </td>
<td width="86"> </td>
<td width="137"> </td>
<td width="221"> </td>
<td width="24"> </td>
<td width="17"> </td>
<td width="55"> </td>
<td width="253"> </td>
</tr>
<tr>
<td width="90"> </td>
<td width="86"> </td>
<td width="137"> </td>
<td width="221"> </td>
<td width="24"> </td>
<td width="17"> </td>
<td width="55"> </td>
<td width="253"> </td>
</tr>
<tr>
<td width="90"> </td>
<td width="86"> </td>
<td width="137"> </td>
<td width="221"> </td>
<td width="24"> </td>
<td width="17"> </td>
<td width="55"> </td>
<td width="253"> </td>
</tr>
<tr>
<td width="90"> </td>
<td width="86"> </td>
<td width="137"> </td>
<td width="221"> </td>
<td width="24"> </td>
<td width="17"> </td>
<td width="55"> </td>
<td width="253"> </td>
</tr>
<tr>
<td width="90"> </td>
<td width="86"> </td>
<td width="137"> </td>
<td width="221"> </td>
<td width="24"> </td>
<td width="17"> </td>
<td width="55"> </td>
<td width="253"> </td>
</tr>
<tr>
<td width="90"> </td>
<td width="86"> </td>
<td width="137"> </td>
<td width="221"> </td>
<td width="24"> </td>
<td width="17"> </td>
<td width="55"> </td>
<td width="253"> </td>
</tr>
<tr>
<td width="90"> </td>
<td width="86"> </td>
<td width="137"> </td>
<td width="221"> </td>
<td width="24"> </td>
<td width="17"> </td>
<td width="55"> </td>
<td width="253"> </td>
</tr>
<tr>
<td width="90"> </td>
<td width="86"> </td>
<td width="137"> </td>
<td width="221"> </td>
<td width="24"> </td>
<td width="17"> </td>
<td width="55"> </td>
<td width="253"> </td>
</tr>
<tr>
<td width="90"> </td>
<td width="86"> </td>
<td width="137"> </td>
<td width="221"> </td>
<td width="24"> </td>
<td width="17"> </td>
<td width="55"> </td>
<td width="253"> </td>
</tr>
<tr>
<td width="90"> </td>
<td width="86"> </td>
<td width="137"> </td>
<td width="221"> </td>
<td width="24"> </td>
<td width="17"> </td>
<td width="55"> </td>
<td width="253"> </td>
</tr>
</table>

If you're using PDO, which is a better approach:
echo "<table>";
$sql = $this->db->query("SELECT * FROM YOUR_TABLE");
while($row = $sql->fetch(PDO::FETCH_ASSOC))
{
echo "
<tr>
<td>". $row['quantity'] ."</td>
<td>". $row['unit'] ."</td>
<td>". $row['details'] ."</td>
<td>". $row['issued_date'] ."</td>
<td>". $row['returned'] ."</td>
</tr>
";
}
echo "</table>";
Or if you're mysql_ functions, which are deprecated:
echo "<table>";
$sql = mysql_query("SELECT * FROM YOUR_TABLE");
while($row = mysql_fetch_assoc($sql))
{
echo "
<tr>
<td>". $row['quantity'] ."</td>
<td>". $row['unit'] ."</td>
<td>". $row['details'] ."</td>
<td>". $row['issued_date'] ."</td>
<td>". $row['returned'] ."</td>
</tr>
";
}
echo "/<table>";

In addition to the above answer, you can also use mysqli. Here's an example:
$result = $mysqli->query($query);
while ($row = $result->fetch_object()){
echo "<tr>";
echo "<td>" . $row->quantity . "</td>"
...etc...
}

Related

HTML CSS PHP, Table design

i have a problem to create table like this image in website, can anyone help me to solve that?. blue line in picture. i just don't know how to create table like this image. especially reference no, it has custom border line.
Here is table design
you can check my code here too MY CODE
this is my code
<html xmlns="http://www.w3.org/1999/ifxhtml">
<head profile="http://www.w3.org/2005/10/profile">
<title>Glisten - A free web template</title>
</head>
<body>
<table width="800" border="1" align="center">
<tbody>
<tr>
<td colspan="2" align="center" bgcolor=""><table width="800" border="1" align="center">
<tbody>
<tr>
<td width="125">Reference No</td>
<td colspan="4"> </td>
<td colspan="2" bgcolor="#8B8A8A" align="center"></td>
</tr>
<tr>
<td align="center" bgcolor="#FF0004"><strong>NG TINEM</strong></td>
</tr>
<tr>
<td>Site ID</td>
<td colspan="3" align="center"></td>
<td width="185">BSC Name</td>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td>Site Name</td>
<td colspan="3" align="center"></td>
<td>New Site ID</td>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td>Sales Cluster</td>
<td colspan="3" align="center"></td>
<td>LAC</td>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td>Ne Type</td>
<td colspan="3" align="center"></td>
<td>Config</td>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td>Band</td>
<td colspan="3" align="center"></td>
<td>PO Number</td>
<td colspan="2" align="center"></td>
</tr>
<tr>
<td>Cell ID</td>
<td width="80" align="center"></td>
<td width="82" align="center"></td>
<td width="80" align="center"></td>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="7" > </td>
</tr>
<tr>
<td align="center">Integration Date</td>
<td align="center"></td>
<td align="center">On Air Date</td>
<td align="center"></td>
<td align="center">Acceptance Date</td>
<td colspan="2" align="center"></td>
</tr>
<tr>
</tbody>
</table>
</body></html>
First identify the total columns to be created.
Then use attribute of table like "colspan" to span the columns.
Add following style to your table (I have added class table in your second table tag):
<style type="text/css">
.table>tbody>tr>td, .table>tbody>tr>th, .table>tfoot>tr>td, .table>tfoot>tr>th, .table>thead>tr>td, .table>thead>tr>th
{
padding: 8px;
line-height: 1.42857143;
vertical-align: top;
}
table {
border-collapse: collapse;
border-spacing: 0;
-webkit-border-horizontal-spacing: 0px;
-webkit-border-vertical-spacing: 0px;
}
</style>
<table width="800" align="center">
<tbody>
<tr>
<td colspan="2" align="center" bgcolor=""><table class="table" width="800" border="1" align="center">
<tbody>
<?php
while($data = mysql_fetch_array($query)){
if($data['dt_report']=='Yes'){
$check_dt_report='checked="checked"';
}
else{
$check_dt_report='';
}if($data['kpi_stats']=='Yes'){
$check_kpi_stats='checked="checked"';
}
else{
$check_kpi_stats='';
}
if($data['clear_alarm']=='Yes'){
$check_clear_alarm='checked="checked"';
}
else{
$check_clear_alarm='';
}
if($data['configuration']=='Yes'){
$check_configuration='checked="checked"';
}
else{
$check_configuration='';
}
if($data['neighbor']=='Yes'){
$check_neighbor='checked="checked"';
}
else{
$check_neighbor='';
}
?>
<tr>
<td width="125">Reference No</td>
<td colspan="4"> </td>
<td colspan="2" bgcolor="#8B8A8A" align="center"><?php echo $data['no_ref']; ?></td>
</tr>
<tr>
<td align="center" bgcolor="#FF0004"><strong>NG TINEM</strong></td>
</tr>
<tr>
<td>Site ID</td>
<td colspan="3" align="center"><?php echo $data['site_id']; ?></td>
<td width="185">BSC Name</td>
<td colspan="2" align="center"><?php echo $data['bsc_name']; ?></td>
</tr>
<tr>
<td>Site Name</td>
<td colspan="3" align="center"><?php echo $data['site_name']; ?></td>
<td>New Site ID</td>
<td colspan="2" align="center"><?php echo $data['new_site_id']; ?></td>
</tr>
<tr>
<td>Sales Cluster</td>
<td colspan="3" align="center"><?php echo $data['sales_cluster']; ?></td>
<td>LAC</td>
<td colspan="2" align="center"><?php echo $data['lac']; ?></td>
</tr>
<tr>
<td>Ne Type</td>
<td colspan="3" align="center"><?php echo $data['ne_type']; ?></td>
<td>Config</td>
<td colspan="2" align="center"><?php echo $data['config']; ?></td>
</tr>
<tr>
<td>Band</td>
<td colspan="3" align="center"><?php echo $data['band']; ?></td>
<td>PO Number</td>
<td colspan="2" align="center"><?php echo $data['po_number']; ?></td>
</tr>
<tr>
<td>Cell ID</td>
<td width="80" align="center"><?php echo $data['cell_id1']; ?></td>
<td width="82" align="center"><?php echo $data['cell_id2']; ?></td>
<td width="80" align="center"><?php echo $data['cell_id3']; ?></td>
<td> </td>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="7" > </td>
</tr>
</tbody>
</table>

Get only the table rows from the first table - Simple HTML Dom (PHP)

<table border="3" rules="all" cellpadding="1" cellspacing="1">
<tbody>
<tr>
<td align="center">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial" color="#000000"> <b>Maandag</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>Dinsdag</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>Woensdag</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>Donderdag</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>Vrijdag</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>1</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="18" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *verlof </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_4. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O114 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V6A </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V6C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
<tr>
<td rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>2</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_3. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O114 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V4B </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V4C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_7. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V4B </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V4A </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
<tr>
<td rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>3</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_1. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V6A </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V6C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_1. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V6A </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V6C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
<tr>
<td rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>4</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
<tr>
<td rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>5</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> stip </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> Os1 </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_5. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V5B </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V5C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_5. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V5B </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V5C </font>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
<tr>
<td rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>6</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_3. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V4B </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V4C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_3. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V4B </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V4C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
<tr>
<td rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>7</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_4. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V6A </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V6C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_7. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V4B </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V4A </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_4. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V6A </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V6C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_7. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V4B </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V4A </font>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
<tr>
<td rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>8</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_5. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V5B </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V5C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_1. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V6A </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V6C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
<tr>
<td rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>9</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
</tbody>
</table>
My school supplies me with the following timetable (as seen above), but when I want to parse the table using simplehtmldom. From this table I want to collect the data so that I can use it in my App.
What query in simplehtmldom can i use to select only the first table rows?
Like this: Table->(all rows)
When I try this query: echo($html->find('table tr',0)); And I change the the zero to 2 (for example), it doesn't return the next table row of the main table. But Instead it returns the frist table row of sub table in the first table row.
Not that I can't change the way the table is presented, this is the table I have to work with.
What I get now when I execute: echo($html->find('table tr',2)); -> "Maandag"
What I would like to get: <tr><td rowspan="2" align="center" nowrap="1"><table><tbody><tr><td align="center" nowrap="1"><font size="2" face="Arial"> <b>2</b> </font> </td> </tr></tbody></table></td> <td colspan="12" rowspan="2" align="center" nowrap="1"><table><tbody><tr><td></td></tr></tbody></table></td> <td colspan="12" rowspan="2" align="center" nowrap="1"><table><tbody><tr><td width="33%" nowrap="1"><font size="2" face="Arial"> *in_3. </font> </td> <td width="33%" nowrap="1"><font size="2" face="Arial"> O114 </font> </td> <td width="33%" nowrap="1"><font size="2" face="Arial"> V4B </font> </td> </tr><tr><td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V4C </font> </td> </tr></tbody></table></td> <td colspan="12" rowspan="2" align="center" nowrap="1"><table><tbody><tr><td width="33%" nowrap="1"><font size="2" face="Arial"> *in_7. </font> </td> <td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font> </td> <td width="33%" nowrap="1"><font size="2" face="Arial"> V4B </font> </td> </tr><tr><td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V4A </font> </td> </tr></tbody></table></td> <td colspan="12" rowspan="2" align="center" nowrap="1"><table><tbody><tr><td></td></tr></tbody></table></td></tr> (the next tablerow of the first (main) table)
The way I load in the html table:
$html = file_get_html($timetableURL);
$timeTable = $html->find('table',0); //I need to do this because the page with the timetable has more html tables, I tested this and it always fetches the timetable as seen above.
A related question: PHP Simple HTML DOM Parser how to get TR only from first table
Only I want to select the second or third row of the first table for example.
echo($timeTable->find('tr',2));
It's a little bit convoluted with simple-html-dom:
// find the first table
$table = $html->find('table', 0);
// iterate all tr's
foreach($table->find('tr') as $tr){
// skip the tr's that are not top level
if($tr->parent->parent != $table) continue;
do_something_with($tr);
}
I used a while loop and the simple-html-dom nextSibling() function.
$tableCell = $row->find('td', 0);
while($tableCell){
$tableCell = $tableCell->next_sibling(); //Go to the next tableCell
}
You can use jQuery selector :first to fetch the first element from the DOM
You can do it like this:
$(function() {
var table = $('table:first');
var table_rows = table.find('tr');
alert(" There are " + table_rows.length + " rows in Table");
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table border="3" rules="all" cellpadding="1" cellspacing="1">
<tbody>
<tr>
<td align="center">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial" color="#000000"> <b>Maandag</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>Dinsdag</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>Woensdag</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>Donderdag</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>Vrijdag</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr>
<td rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>1</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="18" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *verlof </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_4. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O114 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V6A </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V6C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
<tr>
<td rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>2</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_3. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O114 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V4B </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V4C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_7. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V4B </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V4A </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
<tr>
<td rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>3</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_1. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V6A </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V6C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_1. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V6A </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V6C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
<tr>
<td rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>4</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
<tr>
<td rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>5</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> stip </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> Os1 </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_5. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V5B </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V5C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_5. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V5B </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V5C </font>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
<tr>
<td rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>6</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_3. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V4B </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V4C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_3. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V4B </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V4C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
<tr>
<td rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>7</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_4. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V6A </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V6C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_7. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V4B </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V4A </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_4. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V6A </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V6C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_7. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V4B </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V4A </font>
</td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
<tr>
<td rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>8</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_5. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V5B </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V5C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td width="33%" nowrap="1"><font size="2" face="Arial"> *in_1. </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> O112 </font>
</td>
<td width="33%" nowrap="1"><font size="2" face="Arial"> V6A </font>
</td>
</tr>
<tr>
<td colspan="3" width="33%" nowrap="1"><font size="2" face="Arial"> V6C </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
<tr>
<td rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td align="center" nowrap="1"><font size="2" face="Arial"> <b>9</b> </font>
</td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
<td colspan="12" rowspan="2" align="center" nowrap="1">
<table>
<tbody>
<tr>
<td></td>
</tr>
</tbody>
</table>
</td>
</tr>
<tr></tr>
</tbody>
</table>
Hope this helps!
Traversing your DOM Structure, and I find that the tr that you want is the 4th child tr, which directly under a tbody element under the table.
So, the query you need might be something like this
// assume table is the root/parent DOM
$tr = $table->find('tbody > tr:nth-child(4)');
var_dump($tr->html());
Sorry if the php syntax is incorrect. That is actually tested against phpquery library.

Adding next row fields to previous row in mySQL using PHP

I have a table with unix timestamp, userID, Long and lat. I would like to copy the value of Long and Lat from the following row and add them to that row. Please see below.
<table style="width: 645px;" border="0" cellspacing="0" cellpadding="0">
<colgroup>
<col width="140" />
<col width="57" />
<col span="7" width="64" />
</colgroup>
<tbody>
<tr>
<td class="xl66" width="140" height="21">Unix Time Stamp</td>
<td class="xl66" width="57"> </td>
<td class="xl66" width="64">Long</td>
<td class="xl66" width="64"> </td>
<td class="xl66" width="64">Lat</td>
<td class="xl66" width="64"> </td>
<td class="xl66" width="64"> </td>
<td class="xl66" width="64"> </td>
<td class="xl66" width="64"> </td>
</tr>
<tr>
<td class="xl67" align="right" width="140" height="20">1458119939</td>
<td class="xl77" width="57"> </td>
<td class="xl70" align="right">-26.2004</td>
<td class="xl70"> </td>
<td class="xl70" align="right">28.01277</td>
<td class="xl70"> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="xl68" align="right" width="140" height="21">1458119940</td>
<td class="xl77" width="57"> </td>
<td class="xl70" align="right">26.20654</td>
<td class="xl70"> </td>
<td class="xl70" align="right">28.04565</td>
<td class="xl70"> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="xl68" align="right" width="140" height="20">1458128756</td>
<td class="xl71" width="57"> </td>
<td class="xl71" align="right" width="64">-29.0065</td>
<td class="xl77" width="64"> </td>
<td class="xl72" align="right" width="64">29.88437</td>
<td class="xl77" width="64"> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="xl68" align="right" width="140" height="20">1458128757</td>
<td class="xl71" width="57"> </td>
<td class="xl71" align="right" width="64">-29.0067</td>
<td class="xl77" width="64"> </td>
<td class="xl72" align="right" width="64">29.88465</td>
<td class="xl77" width="64"> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="xl68" align="right" width="140" height="20">1442829381</td>
<td class="xl71" width="57"> </td>
<td class="xl71" align="right" width="64">-29.0064</td>
<td class="xl77" width="64"> </td>
<td class="xl72" align="right" width="64">29.88458</td>
<td class="xl77" width="64"> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="xl68" align="right" width="140" height="21">1442829397</td>
<td class="xl71" width="57"> </td>
<td class="xl73" align="right" width="64">-29.0062</td>
<td class="xl78" width="64"> </td>
<td class="xl74" align="right" width="64">29.88436</td>
<td class="xl77" width="64"> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="xl69" align="right" width="140" height="21">1442830988</td>
<td class="xl73" width="57"> </td>
<td class="xl75" align="right" width="64">-26.2065</td>
<td class="xl79" width="64"> </td>
<td class="xl76" align="right" width="64">28.04565</td>
<td class="xl77" width="64"> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="20"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td height="20"> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="xl65" colspan="3" height="20">Query Result needs to look like</td>
<td class="xl65"> </td>
<td class="xl65"> </td>
<td class="xl65"> </td>
<td> </td>
<td> </td>
<td> </td>
</tr>
<tr>
<td class="xl66" height="21">Unix Time Stamp</td>
<td class="xl66"> </td>
<td class="xl66">Long</td>
<td class="xl66"> </td>
<td class="xl66">Lat</td>
<td class="xl66"> </td>
<td class="xl66">LongB</td>
<td class="xl66"> </td>
<td class="xl66">LatB</td>
</tr>
<tr>
<td class="xl67" align="right" width="140" height="20">1458119939</td>
<td class="xl77" width="57"> </td>
<td class="xl70" align="right">-26.2004</td>
<td class="xl70"> </td>
<td class="xl70" align="right">28.01277</td>
<td class="xl70"> </td>
<td class="xl70" align="right">26.20654</td>
<td class="xl70"> </td>
<td class="xl70" align="right">28.04565</td>
</tr>
<tr>
<td class="xl68" align="right" width="140" height="20">1458119940</td>
<td class="xl77" width="57"> </td>
<td class="xl70" align="right">26.20654</td>
<td class="xl70"> </td>
<td class="xl70" align="right">28.04565</td>
<td class="xl70"> </td>
<td class="xl71" align="right" width="64">-29.0065</td>
<td class="xl77" width="64"> </td>
<td class="xl72" align="right" width="64">29.88437</td>
</tr>
<tr>
<td class="xl68" align="right" width="140" height="20">1458128756</td>
<td class="xl71" width="57"> </td>
<td class="xl71" align="right" width="64">-29.0065</td>
<td class="xl77" width="64"> </td>
<td class="xl72" align="right" width="64">29.88437</td>
<td class="xl77" width="64"> </td>
<td class="xl71" align="right" width="64">-29.0067</td>
<td class="xl77" width="64"> </td>
<td class="xl72" align="right" width="64">29.88465</td>
</tr>
<tr>
<td class="xl68" align="right" width="140" height="20">1458128757</td>
<td class="xl71" width="57"> </td>
<td class="xl71" align="right" width="64">-29.0067</td>
<td class="xl77" width="64"> </td>
<td class="xl72" align="right" width="64">29.88465</td>
<td class="xl77" width="64"> </td>
<td class="xl71" align="right" width="64">-29.0064</td>
<td class="xl77" width="64"> </td>
<td class="xl72" align="right" width="64">29.88458</td>
</tr>
<tr>
<td class="xl68" align="right" width="140" height="21">1442829381</td>
<td class="xl71" width="57"> </td>
<td class="xl71" align="right" width="64">-29.0064</td>
<td class="xl77" width="64"> </td>
<td class="xl72" align="right" width="64">29.88458</td>
<td class="xl77" width="64"> </td>
<td class="xl73" align="right" width="64">-29.0062</td>
<td class="xl78" width="64"> </td>
<td class="xl74" align="right" width="64">29.88436</td>
</tr>
<tr>
<td class="xl68" align="right" width="140" height="21">1442829397</td>
<td class="xl71" width="57"> </td>
<td class="xl73" align="right" width="64">-29.0062</td>
<td class="xl78" width="64"> </td>
<td class="xl74" align="right" width="64">29.88436</td>
<td class="xl78" width="64"> </td>
<td class="xl75" align="right" width="64">-26.2065</td>
<td class="xl79" width="64"> </td>
<td class="xl76" align="right" width="64">28.04565</td>
</tr>
</tbody>
</table>
Your help would be very much appreciated.
SELECT timestamp, userID, Long, Lat, Long as LongB, Lat as LatB FROM table
I think you meant column instead of row

xpath got wrong html attribute

So, I have this PHP scraper code and HTML below that I want to scrape using Xpath.
When I try to scrape every #href, it shows outerHTML 14, when it is supposes to be 14
The #href is cut in half where the space are. What causes this?
$content = $xpath->query('//a');
foreach($content as $c){
var_dump(htmlspecialchars($c->C14N())); echo '<br>';
}
The one above is the CURL code.
Here is the HTML.
<div class="outercalendar" id="maincalendar821"><table class="calendarHeader">
<tbody><tr>
<td><input type="button" onclick="AjxGetMainCalendarMonth('2', '2015', '821')" value="<"></td>
<td class="calendarHeader" colspan="5">March 2015</td>
<td><input type="button" onclick="AjxGetMainCalendarMonth('4', '2015', '821')" value=">"></td>
</tr>
</tbody></table>
<table class="calendar">
<tbody><tr>
<td class="calendarDay">S</td>
<td class="calendarDay">M</td>
<td class="calendarDay">T</td>
<td class="calendarDay">W</td>
<td class="calendarDay">T</td>
<td class="calendarDay">F</td>
<td class="calendarDay">S</td>
</tr>
<tr>
<td class="calendar">1</td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar">7</td>
</tr>
<tr>
<td class="calendar">8</td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar">14</td>
</tr>
<tr>
<td class="calendar">15</td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar">21</td>
</tr>
<tr>
<td class="calendar">22</td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar">28</td>
</tr>
<tr>
<td class="calendar">29</td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
<td class="calendar"> </td>
</tr>
</tbody></table>
</div>
The issue could be in the structure of the info stored in the tag.
I would suggest starting with a more detailed xpath:
//a/#href
so your initial code would be:
$content = $xpath->query('//a/#href');

How do I extract values from a html page stored as string using curl function

I am using PHP / curl to get a HTML into a string and then i need to extract the following data and then project a graph out of it .
The data I want looks like :
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta name="generator" content=
"HTML Tidy for Linux (vers 25 March 2009), see www.w3.org" />
<title></title>
</head>
<body>
<table>
<tbody>
<tr>
<td>
<h3>Income</h3>
</td>
</tr>
<tr>
<td>Operating income</td>
<td class="numericalColumn">22,922.00</td>
<td class="numericalColumn">21,507.30</td>
<td class="numericalColumn">17,492.60</td>
<td class="numericalColumn">13,683.90</td>
<td class="numericalColumn">10,227.12</td>
</tr>
<tr>
<td>
<h3>Expenses</h3>
</td>
</tr>
<tr>
<td>Material consumed</td>
<td class="numericalColumn">4,029.40</td>
<td class="numericalColumn">3,442.60</td>
<td class="numericalColumn">2,952.30</td>
<td class="numericalColumn">1,889.00</td>
<td class="numericalColumn">1,367.67</td>
</tr>
<tr>
<td>Manufacturing expenses </td>
<td class="numericalColumn">2,213.20</td>
<td class="numericalColumn">1,841.80</td>
<td class="numericalColumn">299.80</td>
<td class="numericalColumn">120.50</td>
<td class="numericalColumn">1,020.70</td>
</tr>
<tr>
<td>Personnel expenses</td>
<td class="numericalColumn">9,062.80</td>
<td class="numericalColumn">9,249.80</td>
<td class="numericalColumn">7,409.10</td>
<td class="numericalColumn">5,768.20</td>
<td class="numericalColumn">4,279.03</td>
</tr>
<tr>
<td>Selling expenses</td>
<td class="numericalColumn">378.10</td>
<td class="numericalColumn">308.40</td>
<td class="numericalColumn">532.10</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">171.05</td>
</tr>
<tr>
<td>Adminstrative expenses</td>
<td class="numericalColumn">1,737.00</td>
<td class="numericalColumn">1,906.00</td>
<td class="numericalColumn">2,583.70</td>
<td class="numericalColumn">2,651.70</td>
<td class="numericalColumn">904.78</td>
</tr>
<tr>
<td>Expenses capitalised</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
</tr>
<tr>
<td>Cost of sales</td>
<td class="numericalColumn">17,420.50</td>
<td class="numericalColumn">16,748.60</td>
<td class="numericalColumn">13,777.00</td>
<td class="numericalColumn">10,429.40</td>
<td class="numericalColumn">7,743.22</td>
</tr>
<tr>
<td>Operating profit</td>
<td class="numericalColumn">5,501.50</td>
<td class="numericalColumn">4,758.70</td>
<td class="numericalColumn">3,715.60</td>
<td class="numericalColumn">3,254.50</td>
<td class="numericalColumn">2,483.90</td>
</tr>
<tr>
<td>Other recurring income</td>
<td class="numericalColumn">434.20</td>
<td class="numericalColumn">468.20</td>
<td class="numericalColumn">326.90</td>
<td class="numericalColumn">288.70</td>
<td class="numericalColumn">113.59</td>
</tr>
<tr>
<td>Adjusted PBDIT</td>
<td class="numericalColumn">5,935.70</td>
<td class="numericalColumn">5,226.90</td>
<td class="numericalColumn">4,042.50</td>
<td class="numericalColumn">3,543.20</td>
<td class="numericalColumn">2,597.49</td>
</tr>
<tr>
<td>Financial expenses</td>
<td class="numericalColumn">108.40</td>
<td class="numericalColumn">196.80</td>
<td class="numericalColumn">116.80</td>
<td class="numericalColumn">7.20</td>
<td class="numericalColumn">3.13</td>
</tr>
<tr>
<td>Depreciation </td>
<td class="numericalColumn">579.60</td>
<td class="numericalColumn">533.60</td>
<td class="numericalColumn">456.00</td>
<td class="numericalColumn">359.80</td>
<td class="numericalColumn">292.26</td>
</tr>
<tr>
<td>Other write offs</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
</tr>
<tr>
<td>Adjusted PBT</td>
<td class="numericalColumn">5,247.70</td>
<td class="numericalColumn">4,496.50</td>
<td class="numericalColumn">3,469.70</td>
<td class="numericalColumn">3,176.20</td>
<td class="numericalColumn">2,302.10</td>
</tr>
<tr>
<td>Tax charges </td>
<td class="numericalColumn">790.80</td>
<td class="numericalColumn">574.10</td>
<td class="numericalColumn">406.40</td>
<td class="numericalColumn">334.10</td>
<td class="numericalColumn">286.10</td>
</tr>
<tr>
<td>Adjusted PAT</td>
<td class="numericalColumn">4,456.90</td>
<td class="numericalColumn">3,922.40</td>
<td class="numericalColumn">3,063.30</td>
<td class="numericalColumn">2,842.10</td>
<td class="numericalColumn">2,016.00</td>
</tr>
<tr>
<td>Non recurring items</td>
<td class="numericalColumn">441.10</td>
<td class="numericalColumn">-948.60</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">38.33</td>
</tr>
<tr>
<td>Other non cash adjustments</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-33.85</td>
</tr>
<tr>
<td>Reported net profit</td>
<td class="numericalColumn">4,898.00</td>
<td class="numericalColumn">2,973.80</td>
<td class="numericalColumn">3,063.30</td>
<td class="numericalColumn">2,842.10</td>
<td class="numericalColumn">2,020.48</td>
</tr>
<tr>
<td>Earnigs before appropriation</td>
<td class="numericalColumn">4,898.00</td>
<td class="numericalColumn">2,973.80</td>
<td class="numericalColumn">3,063.30</td>
<td class="numericalColumn">2,842.10</td>
<td class="numericalColumn">2,020.48</td>
</tr>
<tr>
<td>Equity dividend</td>
<td class="numericalColumn">880.90</td>
<td class="numericalColumn">586.00</td>
<td class="numericalColumn">876.50</td>
<td class="numericalColumn">873.70</td>
<td class="numericalColumn">712.88</td>
</tr>
<tr>
<td>Preference dividend</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
<td class="numericalColumn">-</td>
</tr>
<tr>
<td>Dividend tax</td>
<td class="numericalColumn">128.30</td>
<td class="numericalColumn">99.60</td>
<td class="numericalColumn">148.90</td>
<td class="numericalColumn">126.80</td>
<td class="numericalColumn">99.98</td>
</tr>
<tr>
<td>Retained earnings</td>
<td class="numericalColumn">3,888.80</td>
<td class="numericalColumn">2,288.20</td>
<td class="numericalColumn">2,037.90</td>
<td class="numericalColumn">1,841.60</td>
<td class="numericalColumn">1,207.62</td>
</tr>
</tbody>
</table>
</body>
</html>
I want to extract each value like Manufacturing Data and the values of all the years mentioned in that line. How do I go about this?
I found something like preg_match('#<tr><th>(.*)</th> <td><b>price</b></td></tr>#', $content, $match); but that doesn't get the values I want.
If i understood you question well you want something like this to be done. this was written by me so if you need clarifications i'd love to help.
cheers !
You can use libraries like PHP Simple HTML DOM Parser to extract data from HTML/XHTML.
http://simplehtmldom.sourceforge.net/manual.htm
An example:
$pageDom = str_get_html( $rawHtmlData );
foreach( $pageDom->find( 'td' ) as $tblElem )
{
if( FALSE !== stristr( $tblElem->innertext, 'Manufacturing expenses' ) )
{
// Do stuff
}
}

Categories