Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
customer table
enter image description here
siteproducts table
enter image description here
I want to display the records of currently logged in users product deatils
ex: customer no 15 is logged in then records should displayed only of him
Model
public function customerparcelstatus()
{
$this->db->select('*');
$this->db->from('siteproducts');
$this->db->join('customer', 'siteproducts.customer_id=customer.customer_id');
//$this->db->order_by('customer.customer_id');
return $this->db->get()->result_array();
}
Controller
public function custparcelstatus()
{
$this->load->model('orbitcustomer_model');
$data['parcellistview'] = $this->orbitcustomer_model->customerparcelstatus();
$this->load->view('customer/customer_dashboard', $data);
}
view
<tbody>
<?php if (!empty($parcellistview)) { foreach($parcellistview as $user) {?>
<tr>
<td><?php echo $user['customer_id']; ?></td>
<td><?php echo $user['customer_code']; ?></td>
<td><?php echo $user['product_code']; ?></td>
<td><?php echo $user['received_date']; ?></td>
<td><?php echo $user['received_from']; ?></td>
<td><?php echo $user['tracking_ref_no']; ?></td>
<td><?php echo $user['parcel_status']; ?></td>
<td><?php echo $user['parcel_note']; ?></td>
</tr>
<?php } } else { ?>
<tr>
<td>Norecords Found</td>
</tr>
<?php } ?>
You need to retrieve records only related to currently logged in customer by using where clause on query like below.
$this->db->where('customer_id', $customer); //currently logged in user
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 1 year ago.
Improve this question
<div id="report-tbl-holder">
<table id="report-tbl" class="table table-stripped table-bordered">
<thead>
<tr>
<th>#</th>
<th>Date/Time</th>
<th>Person's Code/Name</th>
<th>Establishment's/Barangay Code/Name</th>
<th>Temperature</th>
</tr>
</thead>
<tbody>
<?php
$i = 1;
$where = ($eid > 0 && is_numeric($eid)) ? " and e.id = {$eid} " : "";
$tracks = $conn->query("SELECT t.*,Concat(p.firstname,' ',p.middlename,' ',p.lastname)as pname,p.code as pcode, e.name as ename,e.code as ecode from tracks t inner join people p on p.id=t.person_id inner join establishment e on. e.id = t.establishment_id where date_format(t.date_added,'%Y-%m-%d') BETWEEN '{$date_start}' and '{$date_end}' $where order by date(t.date_added) asc");
while($row=$tracks->fetch_assoc()):
?>
<tr>
<td class="text-center"><?php echo $i++; ?></td>
<td><?php echo date("M d, Y h:i A",strtotime($row['date_added'])) ?></td>
<td><?php echo $row['pcode'] . ' - ' . (ucwords($row['pname'])) ?></td>
<td><?php echo $row['ecode'] . ' - ' . (ucwords($row['ename'])) ?></td>
</tr>
<?php endwhile; ?>
</tbody>
</table>
I created a row in my database named "temperature" and wanted to include it in a table on the webpage I have created but I don't know how to call the contents of the newly added row (temperature) to display. It did add a new row because I added "Temperature" in the table header but I don't know how to properly call the values for temperature from the database.
I think that there's a confusion... Here "Temperature" is not a row, but a column.
You can try to add the following code line inside your loop :
<td><?php echo $row['body_temp'] ?></td>
You can simply get the data from database in same manner as you are getting in last table columns . you have to give just newly added column name into $rows array.
<tr>
<td class="text-center"><?php echo $i++; ?></td>
<td><?php echo date("M d, Y h:i A",strtotime($row['date_added'])) ?></td>
<td><?php echo $row['pcode'] . ' - ' . (ucwords($row['pname'])) ?></td>
<td><?php echo $row['ecode'] . ' - ' . (ucwords($row['ename'])) ?></td>
<td><?=$row['body_temp'] ?></td>
</tr>
I have a table that is displaying data to the user and each row in the table has a unique id, in the table I am generating a button for each row to get more information on the content in the row. However, i need to generate a unique href for each button based on the Unique ID of the data in the row. The way I have done it it correctly goes to the link in the href but without passing the Unique ID.
<tbody>
<?php while($row = $query->fetch()) { ?>
<tr>
<td><?php echo $row['car_id']; ?></td>
<td><?php echo $row['car_make']; ?></td>
<td><?php echo $row['car_model']; ?></td>
<td><?php echo $row['number_available']; ?></td>
<td><?php echo $row['rent_cost_per_day']; ?></td>
<td><a class="btn btn-default" href="cars.php?"<?php $row['car_id']; ?>>View</a></td>
</tr>
<?php } ?>
</tbody>
Any help?
This is because you put the php after you closed the href quotes. You also have not put an echo function for the php, and have not put a get variable. You have:
href="cars.php?"<?php $row['car_id']; ?>
What you want to have is:
href="cars.php?id=<? echo $row['car_id']; ?>"
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I would like to generate an HTML table with dynamic content in PHP, and add an onclick event on a cell of each row, to trigger an action depending on that row.
How to achieve that ?
Here is my example :
I have a table which prints data from a database. Table is made of 3 columns. Columns 1 and 2 hold name and surname and column 3 refers to a comment. Third column says "Comment exists" or "No comments", depending on whether a related comment exists or not.
The goal is to pop up a small window when user clicks on the third column, to show the given comment.
Here is an example of a table, and what I have tried so far :
<table border=1>
<tr>
<th>ID</th>
<th>Vardas</th>
<th></th>
</tr>
<?php while($row = mysql_fetch_array($res)) : ?>
<tr>
<td><?php echo $row['id'] ?></td>
<td><?php echo $row['vardas'] ?></td>
<td><?php echo $row['gedimas'] ?></td>
</tr>
<?php endwhile; ?>
</table>
How do I add on click event for the $row['gedimas'] line, to display a full comment from database ?
You can place an "onclick" event directly in PHP :
<td <?php echo "onclick='displayComment(".$id.")'" ?> >
About the general structure of opening a window, you can build the table pretty easily, and then have another page for displaying the comment if there is.
Code for the table :
<table>
<tr>
<th>Name</th>
<th>Surname</th>
<th>Has comment ?</th>
</tr>
<?php
for( $i = 0; $i<count($database_data); $i++){
$item = $database_data[$i];
?><tr>
<td><?php echo $item[0] ?></td>
<td><?php echo $item[1] ?></td>
<td <?php
echo "onclick='displayComment("
echo $item[0].", ".$item[1]
echo ")'"?>
><?php echo $item[2] ? "Comment exists" : "No comments" ?></td>
</tr>
}
Then you would need to include a javascript file with the following code :
function displayComment(name, surname) {
window.open(
"display_comment.php?name="+encodeURI(name)+"&surname="+encodeURI(surname),
"_blank",
"height=200, width=300"
}
And lastly, you would need your display_comment.phppage, whose essence would be :
// get comment from database using data in $_GET["name"] and $_GET["surname"]
Comment from <?php echo $_GET["name"]." ".$_GET["surname"] ?> :
<br>
<?php echo $comment_retrieved_from_database ?>
Alternative
An alternative would be to only record the id of the comment in the HTML code, and then add the onclick events in javascript.
The php code for the cell would be as follows :
<td <?php echo "data-comment-id='$id'" ?> >
And you would add the onclick events in javascript that way :
var tableCells = document.querySelectorAll("td[data-comment-id]");
for(var i=0; i<tableCells.length; i++){
var cell = tableCells[i];
var commentId = cell.getAttribute("data-comment-id");
cell.addEventListener("click", function(){openPopup(commentId);});
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
<?php
foreach($ticket as $t)
{
?>
<tr>
<td><?php echo $t['Ticket_no']; ?></td>
<td><?php echo $t['name']; ?></td>
<td><?php echo $t['Roll']; ?></td>
<td><?php echo $t['branch']; ?></td>
<td><?php echo $t['hostel_id']; ?></td>
<td><?php echo $t['Indisciplinary_desc']; ?></td>
<td><?php echo $t['reporting_date']; ?></td>
<td><input id="actionyes" type="submit" value="Yes"/>
<input id="actionno"type="submit" value="No"/>
</td>
</tr>
<?php
}
?>
i'm trying to repeat the row as the data is inserted in db.so i have run foreach loop but it is giving me warning not output so please anyone help me in this warning.
<?php
$query="SELECT i.Ticket_no,i.Roll,i.reporting_date,i.Indisciplinary_desc,r.hostel_id,s.branch,s.name FROM indisciplinary_dc_reports i,room_allocation1 r,student s WHERE i.Forward_status=0 AND i.roll=r.roll AND i.roll=s.roll AND r.end_date>NOW() AND i.Closure_status=0";
$query_run=mysql_query($query,$db);
if(mysql_num_rows($query_run)==False)
{
echo "No Pending Records.";
}
else
{
$ticket=mysql_fetch_assoc($query_run);
}
?>
Use regular syntax like this:
while ($ticket=mysql_fetch_assoc($query_run)) {
echo $ticket['Ticket_no'];
...other fields...
}
This is how mysql_fetch_assoc works
Returns an associative array that corresponds to the fetched row and
moves the internal data pointer ahead. mysql_fetch_assoc() is equivalent to calling mysql_fetch_array() with MYSQL_ASSOC for the
optional second parameter. It only returns an associative array
So it has a pointer and you can't use it more than once in another loop.
Also
Warning
This extension was deprecated in PHP 5.5.0, and it was removed in PHP
7.0.0. Instead, the MySQLi or PDO_MySQL extension should be used.
I currently have made a page that shows all the users, but I just want to only display the currently logged in user, Please help me im begging you I spent 4 hours of nothing T_T im new at php and im very lost, im so hopeless right now
<?PHP
$customerquery=mysql_query("select * from customerinfo");
while($customerrows=mysql_fetch_array($customerquery)){
?>
<tr>
<td>Id</td><td>First Name</td><td>Last Name</td><td>Address</td><td>Contact No</td> <td>Username</td><td>Password</td><td>Edit</td>
</tr>
<tr>
<td><?PHP echo $customerrows['id'];?></td>
<td><?PHP echo $customerrows['fname'];?></td>
<td><?PHP echo $customerrows['lname'];?></td>
<td><?PHP echo $customerrows['address'];?></td>
<td><?PHP echo $customerrows['contactno'];?></td>
<td><?PHP echo $customerrows['username'];?></td>
<td><?PHP echo $customerrows['password'];?></td>
<td>edit</td>
</tr>
<?PHP } ?>
You need to specify a WHERE condition in your query. That will fetch only one row, so you will not need a while loop:
$id = (int) $_GET['id']; // assuming you pass user id in URL
$customerquery = mysql_query("select * from customerinfo WHERE id = $id");
$customerrows = mysql_fetch_array($customerquery);
// rest of your html