How to post many data from a view to controller? - php

I am using codeigniter.I have a table in my view. When one row is filled totally that data must be posted to my controller class. How to do this.
My view page.
<table style=" border-collapse: collapse;">
<tr>
<th>Employee</th>
<th>Start Time</th>
<th>ID</th>
<th>Mins</th>
<th>Type</th>
</tr>
<tr id="1">
<td contenteditable="true"><?php echo form_dropdown('employee', $options_category, set_value('employee'),'style="border-radius:0px; height:15px; font-size:10px; width:70px"');?></td>
<td contenteditable="true"><?php echo $date->format( 'H:i' ); ?></td>
<td contenteditable="true" ondblclick="mylist()"><?=$products['id']?></td>
<td contenteditable="true" class="nr"><?=$products['mins']?></td>
<td contenteditable="true"><?=$products['type']?></td>
</tr>
<tr id="2">
<td contenteditable="true"><?php echo form_dropdown('employee', $options_category, set_value('employee'),'style="border-radius:0px; height:15px; font-size:10px; width:70px"');?></td>
<td contenteditable="true"></td>
<td contenteditable="true" ondblclick="mylist()"><?=$products['id']?></td>
<td contenteditable="true"></td>
<td contenteditable="true"></td>
</tr>
</table>
I need to post the id that is filled totally.How to do this can someone help me code?

Related

How to do make html foreach table?

I tried to do it but the big problem is foreach here i have the foto:
Problem
Here is my table picture
Here is the code but still have problem:
<div class="row">
<table class="table table-bordered table-striped table-highlight">
<tbody>
<tr height="100">
<td rowspan="6" height="120" width="3%" style="vertical-align: middle;">
<p style="white-space: nowrap;writing-mode: vertical-lr;transform: rotate(180deg);font-weight: bold;"><font >Here is my title </font></p>
</td>
<td colspan="3">
<font>Name</font>
</td>
<td width="64">
<font>Article</font>
</td>
<td width="64">
<font>Price</font>
</td>
<td width="64">
<font>Date</font>
</td>
</tr>
<tr height="20">
<td colspan="3" rowspan="5" height="120" ></td>
<td rowspan="5" style="vertical-align: top;"></td>
<td rowspan="5" style="vertical-align: top;"></td>
<td rowspan="5" style="vertical-align: top;"></td>
</tr>
<tr height="15">
</tr>
<tr height="15">
</tr>
<tr height="15">
</tr>
<tr height="15">
</tr>
</tbody>
</table>
</div>
How can i do it so that when i use foreach it will insert new td and the vertical Here is my title will be there?
ok, so you're using php here's a very basic example on how you can do that, i'm assuming you already did query and the fetching part, and this is a guess of your data structure, you can adjust it to your liking :
<div class="row">
<table class="table table-bordered table-striped table-highlight">
<tbody>
<tr height="100">
<td rowspan="100%" height="120" width="3%" style="vertical-align: middle;">
<p style="white-space: nowrap;writing-mode: vertical-lr;transform: rotate(180deg);font-weight: bold;"><font >Here is my title </font></p>
</td>
<td colspan="3">
<font>Name</font>
</td>
<td width="64">
<font>Article</font>
</td>
<td width="64">
<font>Price</font>
</td>
<td width="64">
<font>Date</font>
</td>
</tr>
<?php
foreach($data as $key => $value){
echo '<tr height="20">';
echo '<td colspan="3">'.$value['name'].'</td>';
echo '<td width="64" style="vertical-align: top;">'.$value['article'].'</td>';
echo '<td width="64" style="vertical-align: top;">'.$value['price'].'</td>';
echo '<td width="64" style="vertical-align: top;">'.$value['date'].'</td>';
echo '</tr>';
}
?>
</tbody>
</table>
</div>
here's a fiddle : https://jsfiddle.net/kkpjx328/
I hope this helps .
PS : on your next question, please consider adding the data structure and if possible, an example or code sample of what you've tried so far so we can provide more specific answers

Styling table generated by PHP foreach with jQuery

I am trying to style a <tr id="options"> generated by a PHP foreach() with jQuery, but everything I've tried only selects the first one, leaving the others intact. What can I do this? Simple example:
CSS:
td {border:1px solid black}
TABLE:
<table>
<tr>
<td>DATE</td>
<td>EXAM TITLE</td>
<td>EXAM CODE</td>
</tr>
<tr>
<td>TODAY</td>
<td>RANDOM</td>
<td>123</td>
</tr>
<tr>
<td>BUTTON</td>
<td>BUTTON</td>
<td>BUTTON</td>
</tr>
<tr>
<td colspan=3 id="options">
</tr>
I have tried this jQuery code (among other):
$("table").find("#options").each(function(){
$(this).css("border","0px");
});
It only styles my first <td id="options">. How can I get all of them?
Sorry if it is a stupid question. Thanks for the help.
convert id to classlike:- <td class="options">..</td>
and then you can use(Use Either-one)
CSS (standered way):-
td.options {border:1px solid black}
Or jQuery(try to avoid as much as possible):-
$('.options').css("border","1px solid black"); // no need of each
Example (both at same time):-
$('.options').css("font-size","21px");
td.options {border:1px solid black}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td class="options">DATE</td>
<td class="options">EXAM TITLE</td>
<td class="options">EXAM CODE</td>
</tr>
<tr>
<td class="options">TODAY</td>
<td class="options">RANDOM</td>
<td class="options">123</td>
</tr>
<tr>
<td class="options">BUTTON</td>
<td class="options">BUTTON</td>
<td class="options">BUTTON</td>
</tr>
</table>

How to get data and set in to php var when use file_get_contents PHP?

How to get data and set in to php var when use file_get_contents PHP ?
this is code for http://www.example.com/test.php
<table align="center">
<thead style="background-color: #F0F0F0; color: #333333; text-align: center;">
<tr>
<th class="countryHeader">Country</th>
<th class="intHeader"> </th>
<th colspan="2" class="intHeader">Desktop CPM</th>
<th colspan="2" class="bannerHeader">Mobile CPM</th>
</tr>
</thead>
<tbody>
<tr class="breaker">
<td> </td>
<td>Highest</td>
<td>Unique</td>
<td>Raw</td>
<td>Unique</td>
<td>Raw</td>
</tr>
<tr class="odd rateVals">
<td class="countryName">United States</td>
<td class="cpmRaw">$2.00</td>
<td class="cpm">$3.44</td>
<td class="cpmRaw">$2.00</td>
<td class="cpmMobile">$1.63</td>
<td class="cpmMobileRaw">$0.97</td>
</tr>
<tr class="even rateVals">
<td class="countryName">Canada</td>
<td class="cpmRaw">$1.20</td>
<td class="cpm">$2.52</td>
<td class="cpmRaw">$1.20</td>
<td class="cpmMobile">$1.88</td>
<td class="cpmMobileRaw">$1.06</td>
</tr>
<tr class="odd rateVals">
<td class="countryName">United Kingdom</td>
<td class="cpmRaw">$1.60</td>
<td class="cpm">$2.10</td>
<td class="cpmRaw">$1.08</td>
<td class="cpmMobile">$1.71</td>
<td class="cpmMobileRaw">$0.94</td>
</tr>
<tr class="even rateVals">
<td class="countryName">Australia</td>
<td class="cpmRaw">$1.50</td>
<td class="cpm">$2.62</td>
<td class="cpmRaw">$1.20</td>
<td class="cpmMobile">$2.73</td>
<td class="cpmMobileRaw">$1.49</td>
</tr>
<tr class="breaker">
<td colspan="6"> </td>
</tr>
<tr class="odd rateVals">
<td class="countryName">United Arab Emirates</td>
<td class="cpmRaw">$1.48</td>
<td class="cpm">$2.49</td>
<td class="cpmRaw">$1.45</td>
<td class="cpmMobile">$2.11</td>
<td class="cpmMobileRaw">$1.42</td>
</tr>
<tr class="odd rateVals">
<td>All other countries</td>
<td>-</td>
<td colspan="2">$0.25 - $2.00</td>
<td colspan="2">$0.06 - $0.22</td>
</tr>
</tbody>
</table>
And this is code for my_code.php
<?php
$test = file_get_contents('http://www.example.com/test.php');
//echo $test;
?>
And i want to get php var from column Mobile CPM raw value like this
$United_States = "0.97";
$Canada = "1.07";
$United_Kingdom = "0.94";
$Australia = "1.49";
$United_Arab_Emirates = "1.42";
How can i do ?
If you want to parse a HTML document you should use PHP's DOMDocument. Instead of file_get_contents() you should use loadHTMLFile(). Because you are using CSS-classes you should view this post on how to find elements via class.

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>

Getting value of specific td in selected row

I have the way to get the value of the td's at the time the row is selected using
$(this).find('.servid').val()
However I cannot find the way to get this value later.
<table id="servicetable" class="scroll" style="border: 1px solid #cbcbcb;" align="center">
<tbody>
<tr class="selected">
<td>Service</td>
<td class="servid" value="4004072">72569000</td>
<td class="origin">PAC</td>
<td class="street">60 KENDAL</td>
<td class="city">SANRDINO</td>
<td class="state">CA</td>
<td class="zip">99999</td>
</tr>
<tr>
<td>TelePacific Circuit</td>
<td class="servid" value="5369592">77051900</td>
<td class="origin">TP</td>
<td class="street">819 KAISER</td>
<td class="city">AHEM</td>
<td class="state">CA</td>
<td class="zip">88888</td>
</tr>
</tbody>
</table>
I need to later, after filling out more of the form, get the val() of the selected tr -> servid td
I have tried various things but they are not working
$('#servicetable .selected > td:nth-child(2)').val();
$('#servicetable').find('.selected > td:nth-child(2)').val();
$('#servicetable').find('tr.selected').find('.servid').val();
Below goes your sollution
alert($('#servicetable tr.selected > td.servid').attr('value'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table id="servicetable" class="scroll" style="border: 1px solid #cbcbcb;" align="center">
<tbody>
<tr class="selected">
<td>Service</td>
<td class="servid" value="4004072">72569000</td>
<td class="origin">PAC</td>
<td class="street">60 KENDAL</td>
<td class="city">SANRDINO</td>
<td class="state">CA</td>
<td class="zip">99999</td>
</tr>
<tr>
<td>TelePacific Circuit</td>
<td class="servid" value="5369592">77051900</td>
<td class="origin">TP</td>
<td class="street">819 KAISER</td>
<td class="city">AHEM</td>
<td class="state">CA</td>
<td class="zip">88888</td>
</tr>
</tbody>
</table>
One more thing you can not put value like this as it will not validate as per w3c, recommanded to put data-value, if HTML5.
And in jquery also you can put like
alert($('#servicetable tr.selected > td.servid').attr('data-value'));
$('#value1').text($('#servicetable .selected > td:nth-child(2)').attr('value'));
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<table id="servicetable" class="scroll" style="border: 1px solid #cbcbcb;" align="center">
<tbody>
<tr class="selected">
<td>Service</td>
<td class="servid" value="4004072">72569000</td>
<td class="origin">PAC</td>
<td class="street">60 KENDAL</td>
<td class="city">SANRDINO</td>
<td class="state">CA</td>
<td class="zip">99999</td>
</tr>
<tr>
<td>TelePacific Circuit</td>
<td class="servid" value="5369592">77051900</td>
<td class="origin">TP</td>
<td class="street">819 KAISER</td>
<td class="city">AHEM</td>
<td class="state">CA</td>
<td class="zip">88888</td>
</tr>
</tbody>
</table>
<label id="value1"/>
IDEAL WAY
use data attribute as shown below,
<td class="servid" data-value="4004072">72569000</td>
$('#value1').text($('#servicetable .selected > td:nth- child(2)').data('value'));
It might be better if you tag the TR with the id you need and then have the "attributes" in the TDs.
You can then parse TDs based on TR
<tr class="selected" id="98989">
<td class="city">Lisbon</td>
.....
_tr = $("#servicetable .selected");
_trId=_tr.attr("id");
_trCity = _tr.find(".city").text();
.....

Categories