I have 3 tables, one contains document list (id, document, url), one contains onboarding status (user_id, document_id, status) and one contains user list (id, name).
In my controller, I have declared the variables calling each one of the repositories created with Doctrine.
$this->data['document_collection'] = $this->em->getRepository('Entities\Documents')->findAll();
$current_user = $this->session->user_id;
$this->data['onboarding_data'] = $this->em->getRepository('Entities\Onboarding')->findAll();
Then on my views page, I want to show a loop where the documents name and url list from the document list table which I did just fine like this:
<tbody>
<?php
foreach($document_collection as $onboarding):
?>
<tr>
<td>
<?php
echo $onboarding->getDocument();
?>
</td>
<td align="center">
<?php
echo anchor($onboarding->getUrl(), "Download");
?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
I want to add another including checkboxes in my loop that will show checked if my $current_user matches the user_id of the onboarding status table for the corresponding document that is showing.
Example:
Related
Working on 2 tables (Homework & Deliveries). I am able to fetch the value of "homework_code" from Deliveries Table. Now same field is there in the Homework table as well without primary key.
I am trying to fetch the value of "title" field from a table "homework". both tables has common value of student_id. The code is :
<?php
$invoices = $this->db->get_where('deliveries', array('student_id' => $row['student_id']))->result_array();
foreach($invoices as $row2): ?>
<tr>
<td>
<?php echo $row2['homework_code'];?>
</td>
<td>
<?php echo $this->db->get_where('homework' , array('homework_code'=>'class_id'))->row()->title; ?> <?php echo $row2['title'];?>
</td>
</tr>
<?php endforeach;?>
From the Your Question above, if Your Database Structure is like that then use:-
Homework Table :-
title
student_id
Deliveries Table :-
homework_code
student_id
then Change this:-
<td>
<?php echo $this->db->get_where('homework' , array('homework_code'=>'class_id'))->row()->title; ?> <?php echo $row2['title'];?>
</td>
to this way:-
<td>
<?php
$student_id = $row2['student_id'];
$homework = $this->db->get_where('homework',array('student_id'=>$student_id))->result_array();
echo $homework['title'];
?>
</td>
Based by your code above, you can use Controller like this
public function get()
{
$data = $this->db->get_where('deliveries', array('student_id' => $row['student_id']))->result_array();
$fetch['fetchdata'] = $this->db->get_where('homework', array($data[0]['homework_code'] => 'class_id'))->result_array();
$this->load->view('yourview', $fetch);
}
and get the out put by putting this on View :
<?= $fetchdata[0][title] ?>
However the result_array() function will producing array for the result even it was only one though
I'm working on page which consists from database of products.
On the front page you can see every product but with only limited information.
I would like to create secondary page by clicking on Learn more of a product with all information.
Really something widely used in eshops where there is no need to create new page for every product but rather one template which will get information from PHP.
The problem is that I don't know how is this principle working.
I don't even know how it is called so I can search for some tutorial.
Maybe fetching array through products' ID?
For showing products I use:
`
<?php
$db = new PDO("mysql:host=localhost;dbname=cars", "root", "");
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
//Query
$cars = $db->prepare("SELECT car_id, name, price, availability, description FROM cars
");
$cars->execute();
$cars = $cars->fetchAll(PDO::FETCH_ASSOC);
?>
`
And then:
<?php foreach($cars as $car): ?>
<td>
<div><img src="<?php echo $car['image'];?>"
</div>
</td>
<td>
<a href="#">
<div id="textTable"><strong><?php echo $car['name'];?></strong></a>
Learn More..
</div>
</td>
<td>
<?php echo $car['availability'];?>
</td>
<td>
<strong><?php echo $car['price'];?>€</strong>
</td>
</tr>
<?php endforeach;?>
You can send you send your product id like this
View
And fetch each record from product id in database with only one php page
This code is for mfetch record in you second page.
$id = $_GET['product_id'];
$cars = $db->prepare("SELECT car_id, name, price, availability, description FROM cars WHERE cae_id='$id'");
$cars->execute();
$cars = $cars->fetchAll(PDO::FETCH_ASSOC);
One possible solution :
Learn More..
(I removed the id="learnMore" because an id must appear only once in an HTML page)
Hi guys im having a difficulty with this scenario:
I want to get the product information using modals, i got this following code:
//Model.php
public function getProduct($product_id){
$this->db->select('product_id,product_name,product_price,product_qty');
$this->db->from('tbl_products');
$this->db->where('product_id',$product_id);
$query = $this->db->get();
return $query->result();
}
//Controller.php
public function view_product(){
$product_id = $this->input->post('product_id');
$this->load->view('header');
$this->data["post"] = $this->Model->ProductList();
$this->load->view('product_page',$this->data);
$this->data["post"] = $this->Model->getProduct($product_id);
$this->load->view('modal/update_product',$this->data);
}
//update_product.php (modal) my View
lets just go straight into the form
<form action="" method="post">
<?php foreach($posts as $post){ ?>
<input type = "hidden" name = "product_id" value = "<?php echo $post->product_id;?>"/>
<input type = "text" name = "product_name" value = "<?php echo $post->product_name;?>"/>
<input type = "text" name = "product_price" value = "<?php echo $post->product_price;?>"/>
<input type = "text" name = "product_qty" value = "<?php echo $post->product_qty;?>"/>
<button type="submit">Update</button>
<?php } ?>
</form>
I got a table already: i can see all products, in my product_page.php
Here is the tables face looks like:
ID Name Price Quantity Option
1 Shoes 150.00 1 Update
2 Liquor 67.50 5 Update
3 Paint 1000.00 5 Update
Once I click the Update button, the update_product.php(a modal) will pop up and get the result of 1 of the product, if I press the first Update only the information for Shoes will be inside the modal, at first i tried it, I get all the information of all the products which makes my modal redundant and looping due to foreach, then I tried getting the information from the table ID itself, and no product pops out, how can I see only 1 product using modal? thank you very much maam and sirs. Please I really need youre help :(
Although I'm not really clear what you're asking, Here is an answer to you question. Your controller code doesn't seem to be making any sense.If you want to display all your products in on page and then you want to edit/update a product when clicked on corresponding update link, here is what you can do.
Use single controller method for list and update
//Controller.php
public function view_product(){
$product_id = (isset($this->input->post('product_id')) ? $this->input->post('product_id'): False ;
if($product_id == False){
$this->data["post"] = $this->Model->ProductList();
$this->load->view('product_page',$this->data);
} else{
$this->data["post"] = $this->Model->getProduct($product_id);
$this->load->view('modal/update_product',$this->data);
}
}
This is simple modification to your code to make it work correctly, but since this code cannot handle form submission of the update form (unless you're pointing update form to a different controller), you will have to add some other code to this controller and your code will get messy in no time. My personal suggestion to you is this,
Use different controllers for list view and update
//Controller.php
public function view_product(){
$this->data["post"] = $this->Model->ProductList();
$this->load->view('product_page',$this->data);
}
public function update_product($product_id){
if($this->input>post('submit')){ // 'submit'should be replaced with the name attribute of your submit button
//call your model and handle the update form submission here
}
$this->data["post"] = $this->Model->getProduct($product_id);
$this->load->view('product_page',$this->data);
}
now, update option of your product_page.php should point to 'update_product' controller method with corresponding product id e.g. {base_url}/controller_class_name/update_product/1
I think your product_page.php has some code like this to loop through all the products and display products in a table, now when you click update link it will point to update_product controller and it will handle the update process.
<table>
<thead>
<tr>
<th>ID</th>
<th>Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Option</th>
</tr>
</thead>
<tbody>
<?php if(!$products){ ?>
<tr>
<td colspan="5">No result</td>
</tr>
<?php } ?>
<?php if($products){ ?>
<?php foreach ($products as $product) { ?>
<tr>
<td><?php echo $product->id; ?></td>
<td><?php echo $product->name; ?></td>
<td><?php echo $product->price; ?></td>
<td><?php echo $product->quantity; ?></td>
<td>
<a href="<?php echo base_url(); ?>controller_class_name/update_product/<?php echo $product->id; ?>" >Update</a>
</td>
</tr>
<?php } } ?>
</tbody>
</table>
You won't be needing a foreach loop inside your update_product.php because you're updating only one product at once.
Hope this is the answer you're looking for, if not please comment and I will edit the answer accordingly.
I am trying to display a list of all entries in the table people. I have the list of entries generating correctly as a html table but I want to ad a row at the top of the table with the table field names. I could do this manually but figure there must be a way to do it dynamically in case I add or remove fields later on.
here is the controller function
public function peopleDisplay() {
$this->set('people', $this->people->find('all'));
}
Are the field names already in the array that generates? If so how do I reference them? If not how do I get them to be?
Here is the view so far
<table>
<tr>
***were I want the row of field names to go***
</tr>
<?php foreach($people as $people): ?>
<tr>
<td>
<?php echo $people['people']['id'] ?>
</td>
<td>
<?php echo $people['people']['firstName'] ?>
</td>
<td>
<?php echo $people['people']['secondName'] ?>
</td>
</tr>
<?php endforeach; ?>
</table>
The column names are the keys in your array. For instance, 'id', 'firstName', and 'secondName' are the column names.
Another way to approach would be to get the column names as a separate array in your controller and then output them in your view.
$people = $this->People->find('all');
$colNames = array_keys($this->People->getColumnTypes());
$this->set(compact('colNames', 'people'));
Then in your view:
foreach($colNames as $col){ //Output column names }
foreach($people as $person){ //Output people }
I have a table with the following fields:
email - name - username - userid
currently the data in this table is pulled into a html table.
In a seperate table i have all the user's data / information.
What i would like to do is click on a name from the first table (consisting of email - name - username)
And have that users information shown on its own like a report generation.
Both the tables have the same unique userid's applied so could someone enlighten me as to the best way to do this?
Thanks.
Surround the name with an anchor tag that has the id as some parameter.
I'd do it with 2 templates where one lists all the users (userList.php) and the other one shows detailed information about a user (userInformation.php).
userList.php:
<table>
<tr>
<th>
<a href="userInformation.php?id=<?php echo $user->id;?>">
<?php echo $user->username;?>
</a>
</th>
<td><?php echo $user->email;?></td>
<td><?php echo $user->propN;?></td>
</tr>
...
...
</table>
userInformation.php:
<?php
$userId = $_POST['id'];
$user = someFunctionForGettingTheUserPerhaps($userId);
?>
<table>
<tr>
<th><?php echo $user->username;?></th>
<td><?php echo $user->email;?></td>
<td><?php echo $user->password;?></td>
<td><?php echo $user->name;?></td>
<td><?php echo $user->propN;?></td>
...
...
</tr>
</table>
EDIT: Replaced '.' with '->' since the latter is the property accessor notation in PHP.
Set the onclick attribute of each table row to
echo('<tr onclick="location.href=\'userdet.php?id='.$row['userid'].'\'">
Where userdet.php is a page that puts the information you want into a HTML table.
edit
You could also try putting the data in like this http://www.jsfiddle.net/dduncan/UuA9E/
although that could get slow if you have a massive users table. (click the table row)