Codeigniter populating drop down from database - codeigniter-form-helper

Hello friends i am having a problem with codeigniter drop down list....
it is working finely but there is a problem which i m unable to solve...
coming direct to code here is my *mode*l ..
function getBatchId(){
$batchId = $this->db->get('batch');
$batchList = array();
if($batchId->num_rows() >0){
foreach ($batchId->result_array() as $tablerow) {
$batchList[] = $tablerow['code'];
}
return $batchList;
}else {return false;}
my controller
$this->load->model('AdmissonModel');
$content = array(
'progid' => $this->AdmissonModel->getProgrameCode(),
'batch' => $this->AdmissonModel->getBatchId(),
'depid' => $this->AdmissonModel->getDepId()
);
$this->load->view('Admissions/admForm_view',$content);
and my view
<tr>
<td>BATCH</td>
<td><?php echo form_dropdown('Batch',$batch); ?></td>
</tr>
the result produced is like this
<select name="Batch">
<option value="0">BCS12</option>
<option value="1">BCS14</option>
<option value="2">IMS01</option>
<option value="3">INU01</option>
<option value="4">INU02</option>
<option value="5">INU03</option>
</select>
now the problem is that i want the values also like BCS12,BCS14,IMS01 etc not 0,1,2,3...but the values are 0,1,2,3,4.....can any 1 help me plz...thanks alot in advance

in your model update this function to
function getBatchId(){
$batchId = $this->db->get('batch');
$batchList = array();
if($batchId->num_rows() >0){
foreach ($batchId->result_array() as $tablerow) {
$batchList[$tablerow['code']] = $tablerow['code'];
}
return $batchList;
}else {return false;}

Related

Filter Select Symfony Dom Crawler

I have html like this :
<select name="MySelect" id="MySelectID">
<option value="0">One</option>
<option value="1">Two</option>
<option value="2">Three</option>
</select>
And i want to get all the option inner text One, Two, and Three
How to do this using Symfony Dom Crawler ?
You can easy use the tag names for the path like $crawler->filter('select > option').
$crawler = new \Symfony\Component\DomCrawler\Crawler('
<select name="MySelect" id="MySelectID">
<option value="0">One</option>
<option value="1">Two</option>
<option value="2">Three</option>
</select>
');
$result = [];
foreach ($crawler->filter('select > option') as $domElement) {
$result[] = $domElement->textContent;
}
// $result is ['One', 'Two', 'Three']

How to put just distinct values into select control MVC ASP.NET?

This is my index view. I tried with ViewBag but it doesn't work, maybe because I want to get values from foreign key. I am new to ASP.NET.
<form id="forma" action="/InspekcijskeKontrole/VratiKontrole" method="get">
<div class="form-group">
<label for="Select1">Odaberite inspekcijsko tijelo:</label>
<select name="Select1" id="Select1" class="form-control" onchange="sacuvaj()">
<option value="-1">Selektujte inspekcijsko tijelo:</option>
#foreach (var i in ViewBag.Select1) {
<option value="#i.Value">#i.Text</option>
}
</select><br />
<label for="Select2">Odaberite vremenski period kontrole:</label>
<select name="Select2" id="Select2" class="form-control" onchange="sacuvaj1()">
<option value="-1">Selektujte vremenski period kontrole:</option>
#foreach(var i in Model)
{
<option value="#i.DatumInspekcijskeKontrole.ToString("dd.MM.yyyy")">#i.DatumInspekcijskeKontrole.ToString("dd.MM.yyyy")</option>
}
</select>
</div>
This is my controller
public ActionResult VratiKontrole(int Select1, string Select2)
{
IEnumerable<string> tijelaNaziv = db.InspekcijskaKontrolas.OrderBy(i => i.InspekcijskoTijelo.NazivInspekcijskogTijela).Select(i => i.InspekcijskoTijelo.NazivInspekcijskogTijela).Distinct();
ViewBag.Select1 = new SelectList(tijelaNaziv);
IQueryable<InspekcijskaKontrola> listaKontrola = db.InspekcijskaKontrolas.Select(i => i);
if (!string.IsNullOrEmpty(Select1.ToString())&&!string.IsNullOrEmpty(Select2.ToString()))
{
string[] parts = Select2.Split('.');
DateTime datum = new DateTime(int.Parse(parts[2]), int.Parse(parts[1]), int.Parse(parts[0]));
listaKontrola = listaKontrola.Where(l => l.InspekcijskoTijeloId == Select1).Where(l => l.DatumInspekcijskeKontrole == datum).Select(l => l);
}
return View(listaKontrola.ToList());
}
(Posted on behalf of the OP).
This is solved. I just put into view:
#foreach (var i in Model.Select(i=>i.InspekcijskoTijelo).Distinct()) {
<option value="#i.InspekcijskoTijeloId">#i.NazivInspekcijskogTijela</option>
}

check wordpress select box value

How to check if a select box has a value or not in wordpress by php?
I want to check if a select box has a value and if it has then check the value against $post array generated by for-each loop.
Is there any built in wordpress function?
Thanks.
We can use php function in wordpress actions for example:
<select name="select_value">
<option value="">Default value (key thing is leaving value="")</option>
<option value="volvo">Volvo</option>
<option value="saab">Saab</option>
<option value="mercedes">Mercedes</option>
<option value="audi">Audi</option>
</select>
//check in the action or filter for the drop-down value:
if($_POST['select_value'] != '') {
//do something
echo $_POST['select_value'];
} else {
//if not post any value
}
This function may be helpful for you:
selected( $selected, $current, $echo);
$selected (required) = One of the values to compare.
Default: None
$current (optional) = The other value to compare if not just true.
Default: true
$echo(boolean) (optional) = Whether to echo or just return the string.
Default: true
Ref.link: https://codex.wordpress.org/Function_Reference/selected may be helpful for you.

get values of all selected checkboxes symfony2

<th scope="col">{{ d.id }} <input type="checkbox" value="{{ d.id }}" name="checkboxD" class="checker"></th>
how to get list of values from the selected checkbox ??
my controller action
public function traiterAction() {
$IDs = array();
if ( $this->getRequest()->isMethod('POST') ) {
$IDs = $this->getRequest()->get('checkboxD');
}
return $this->render('#EgovPoste/test.html.twig',array('ids'=>$IDs));
}
You need to change the name to checkboxD[] .
I hope that will help you

search form - 2 values in 1 option

So I have this code into a search form:
<select name="rentbuy">
<option value="buy">Buy</option>
<option value="rent">Rent</option>
<option value="rent/week">Rent/week</option>
</select>
This is what I want to do:
<select name="rentbuy">
<option value="buy">Buy</option>
<option value="rent rent/week">Rent</option>
</select>
So when someone chooses "Rent" I want the form to get both values "rent" and "rent/week".
Thanks.
Use multiple attribute on select element :
<select name="rentbuy" multiple="multiple">
<option value="buy">Buy</option>
<option value="rent" selected="selected">Rent</option>
<option value="rent/week" selected="selected">Rent/week</option>
</select>
Here is a jsfiddle : http://jsfiddle.net/v2wHS/
I have this code into the theme, maybe helps with something:
$search_buyorrent = "";
if (get_option('wp_search_bor') == "Yes") {
if (isset($_COOKIE['rentbuy']) && $_COOKIE['rentbuy'] != '') {
$search_buyorrent = $_COOKIE['rentbuy'];
} else {
if (isset($_POST['rentbuy'])) {
$search_buyorrent = trim($_POST['rentbuy']);
}
}
} else {
$search_buyorrent = '';
}
And another snippet here:
if ($search_buyorrent == "buy" || $search_buyorrent == "") {
$query ="SELECT p.* FROM $wpdb->posts p, $wpdb->postmeta p1
WHERE p.ID = p1.post_id AND p1.meta_key='price_value' AND convert(p1.meta_value, signed) BETWEEN '$search_pricemin_buy' AND '$search_pricemax_buy'";
$spm = getIds( $query );
$_ids = ( !empty($spm) ? ( !empty($_ids) ? array_intersect( $_ids, $spm) : "" ) : "" );
}

Resources