The following is a foreach loop that will show a group of buttons coming from DB.
#foreach($acc as $accs)
<div class="col-xs-1">
{{$accs->first_name}}
</div>
#endforeach
As I click on one of the buttons, I want to show a new view with all same buttons but ONLY the selected button highlighted (e.g. class="btn btn-warning"). If I add the below code in the new view, all buttons will be highlighted, not only the selected one.
Any idea how can this be done?
#foreach($acc as $accs)
<div class="col-xs-1">
{{$accs->first_name}}
</div>
#endforeach
You should add a new property for that button like $is_highlighed in the controller send to the view and in view make an if statement for finding this button
you have two way for this goal
add a new field in DB like is_highlighed (Boolean)
or
you can add a property in the controller
for example, you get a collection from DB by the model and have some values like id, text, color and etc
and you want to make highlighted blue button so in the controller, you check the color and if button color is the blue that adds an is_highlighed = true
Related
I have one page which has two tabs, each one has it's pagination.
It works correctly only when I click on tab, but when I click on previous or back page, it keeps returning to the first tab.
this is my code on controller:
$entries = Entry::paginate(5,['*'],'entries')
->appends(request()->except('entries'));
$company_responses= CompanyResponse::paginate(5,['*'],'company_responses')
->appends(request()->except('company_responses'));
on view
{{$entries->appends(request()->except('entries'))->links()}}
{{$company_responses->appends(request()->except('company_responses'))->links()}}
tabs links
<div class="tab">
<button class="tablinks" onclick="openTab(event,'tab1')">الملاحظات</button>
<button class="tablinks" onclick="openTab(event,'tab2')">القيود</button>
</div>
I don't know what I need to do to make it works on previous or back.
As suggested by Crisha:
Create a separate query for each tab and paginate the results
$tab1 = Model::where('column', 'value')->paginate(10);
$tab2 = Model::where('column', 'value')->paginate(15);
I think you should be able to use this:
{{ $tab1->fragment('tab_id')->links() }}
{{ $tab2->fragment('tab_id')->links() }}
That should then add the tab # to the pagination links, you might need to add tab1 & tab2 where is has tab_id - as this is untested.
I have looked everywhere for this question, perhaps I'm just not phrasing it correctly.
I have a page displaying various products, the table is called items. There in my fields I have all the information and images to display on the page, this works fine. Now I want to be able to press a button to add the item to cart, I have the code below where I access the data.
<div class="col-md-5">
<h2 style="font-size:25px;"> <?=$items['title'];?></h2>
<img src="<?=$items['image'];?> "width='300' height='500'/>
<p style="font-size:20px;" class = "lprice">GBP <?= $items['price'];?></p>
</div>
Now that I have done that, my question is how can I add a button for every time a result is displayed and have that button linked with that item, I appreciate this may no be as straight forward as I am phrasing this, but just looking for some help.
Thanks
You can do it in two ways, either way, you need a primary key (eg: id) in your items table which will hold a unique number for each of your items.
After that, you print your id along with everything else inside a button or inside an a tag. Like
<div class="col-md-5">
<h2 style="font-size:25px;"> <?=$items['title'];?></h2>
<img src="<?=$items['image'];?> "width='300' height='500'/>
<p style="font-size:20px;" class = "lprice">GBP <?= $items['price'];?></p>
<a class="btn btn-primary" href="add_to_cart.php?id=<?=$items['id'];?>">Add to Cart</a>
</div>
Now inside your add_to_cart.php file, you can receive the id of the products like this $product_id = $_GET['id'];
Once you have the id of the product, you can process the rest on the add_to_cart.php file and redirect the user back to the previous page with a success or error message.
This way, we passed the id using a URL parameter. The second way is to pass the id using a form. I just wanted to let you that this method exists. I hope this helps. If you have any doubt, feel free to ask in the comment section.
When I click on an update button, the model-pop-up appears with the same value for all countries. It's always showing India.
I want the country name here:
<input type="text" value='. $row['country_name'] .'>
You are printing out a modal for each row you have in the database and they all have the same id "myModal", that's the last thing you want to do.
Instead what you need is to have the modal html printed out once and pass the name of the country to it when the user presses the update button using a javascript function.
You need to give a class to td
example
<td class='country'>
you need to give class to the button
<button class="update">Update</button>
remove the modal popup code on each echo place it in the footer
give a common id to textbox in the popup
$(".update").change(function(){
$('#myModal').modal('show');
var value= $(this).closest("tr").find(".country").text();
$("countryUpdate").val(value);
});
I have two forms that I'm calling from elements from the same controller, the second one is wrapped in an HTML table, I want to know how can I position my submit button at the bottom, after my table, because right now it's in the middle of the first form and the table.
I tried to assign the element in my controller and echo it in the view but it's still at the same position.
You can try something like that:
1 - for each form give a name like $this->setName('name1'); for example
2 - remove the submit button of your forms
3 - create a button in your view where you want:
<INPUT type="button" value="Validate" onClick="subForm()">
4 - In js create subForm() function:
<script>
function subForm(){
document.forms['name_of_your_form'].submit();
}
</script>
Of course, you can switch to the parameter name of the form you want to send.
I am newbie in CodeIgniter. I have a table where data is showing. In each row there is an edit button. When the edit button is clicked, a modal popup will pop up and then you are able to edit it. What my problem is, is that I don't know how to attach a link of my controller behind the image so that I can send the row id to the controller. I link my image(Edit) to the modalpopup in the href .. so how can I perform both the operations at the same time ..
This is my link in form view. As you can see, in the href tag, I link to myModal where the edit form is displayed, but I want that edit form to display against the row. So I have to link it to the controller, which I don't know how to do.
Is there a way to attach links to an image or there is another way ?
<a data-toggle="modal" href="#myModal">
<img src="images/32/edit.png" alt="Edit"></a></td>
<div class="modal hide" id="myModal">
//here all the form fields are displaying
Follow these steps
Create a link like this
<a data-toggle="modal" href="<?php echo site_url('controllername/methodname/'.$id);?>">
<img src="images/32/edit.png" alt="Edit">
</a>
Now see controller class's method will be called on click. the id should be provided via loop.
Controller method
function methodname(){
$id = $this->uri->segment(3);
$this->load->model('modelname');
$data['result'] = $this->modelname->getResord($id);
$this->load->view('editform',$data);
}
And model method should fetch data with where condition
function modelmethod($id)
{
return $this->db->where('id',$id)->get('tablename')->row();
}