I am workin on PHP codeigniter
See this attached image, here i need to get values of selected checkboxes and save in a database table by clicking on the button called CONFIRM
My view Code:
<?php foreach($studentlist as $llist){
echo form_open("trusts/MoveData?id=".$llist['id']); }?>
<button name="submit" type="submit" value="<?php echo #$studentlist1->id; ?>" class="btn btn-success btn-flat pull-right marginBot10px"><i class="icon_set_1_icon-76"></i> CONFIRM </button>
<?php echo form_close(); ?>
<table class="table table-bordered" id="employee_grid">
<thead>
<tr>
<!--<th><input type="checkbox" id="select_all"></th>-->
<th>Select</th>
<th>Student Name</th>
<th>Gender</th>
<th>Email</th>
<th>Phone</th>
<th>Program Id</th>
<th>Program Name</th>
</tr>
</thead>
<tbody>
<?php
$i=1;
foreach($studentlist as $llist){
?>
<tr id="<?php echo $llist["id"]; ?>">
<td><input type="checkbox" name="ids[]" value="<?php echo $llist['id']; ?>"> </td>
<td><?php echo $llist['Name']; ?></td>
<td><?php echo $llist['Gender']; ?></td>
<td><?php echo $llist['Email']; ?></td>
<td><?php echo $llist['Phone']; ?></td>
<td><?php echo $llist['ProgramId']; ?></td>
<td><?php echo $llist['ProgramName']; ?></td>
<!-- <td></td>-->
</tr>
<?php
$i++;
}
?>
</tbody>
</table>
How get selected checkbox values of this view in my controller?
When the form is submitted you an get the selected checkbox values like:
$selected = $this->input->post('ids');
here $selected is an array, so use foreach() to get its values.
Related
Table name :- add_user
data is inserting in it, there is a column due_date storing date in (dd-mm-yyyy) format
now i want to create a filter for due_date. But my code is not working. When i'm running the code it is showing all data, it is not filtering it.
here is my code
<form class="form-inline" method="post" action="">
<label> <b>From Date : </b></label>
<input type="date" name="s_date" class="form-control">
<input type="date" name="e_date" class="form-control">
<button type="submit" name="search" class="btn btn-success">Search</button>
</form>
<?php
error_reporting(0);
include_once "config2.php";
if(count($_POST)>0) {
$s_date=date("dd-mm-yyyy", strtotime($_POST['s_date']));
$e_date=date("dd-mm-yyyy", strtotime($_POST['e_date']));
$result = mysqli_query($conn,"SELECT * FROM add_user WHERE due_date BETWEEN '$s_date' AND '$e_date'");
}
?>
<center>
<table class='table table-bordered'>
<thead class="thead-dark">
<tr>
<th>Action</th>
<th>Pet Photo</th>
<th>Owner</th>
<th>Mobile Number</th>
<th>Category</th>
<th>Pet Id</th>
<th>Pet Name</th>
<th>Address</th>
</tr>
<?php
$i=0;
while($row = mysqli_fetch_array($result)) {
?>
<tr>
<td><button class="btn btn-info">View</button></td>
<td><img src="/pet_img/<?php echo $row["signature"]; ?>"width="60px"height="80px"> </td>
<td><img src="/pet_img/<?php echo $row["photo"]; ?>"width="60px"height="80px"> <br><b> <?php echo $row["name"]; ?> </td>
<td><?php echo $row["mobile"]; ?></td>
<td><?php echo $row["type"]; ?></td>
<td><b><font color="green"><?php echo $row["pet_id"]; ?></font></b></td>
<td><?php echo $row["pet_name"]; ?></td>
<td><?php echo $row["add1"]; ?> <?php echo $row["add2"]; ?> <?php echo $row["add3"]; ?> <?php echo $row["pin"]; ?></td>
</tr>
<?php
$i++;
}
?>
</table>
</body>
</html>
Your column data type needs to be either timestamp or date/datetime. You can't compare date strings in this format.
Basically I need to have the columns with my delete and edit buttons visible only if the admin logs in, I know how to determine if an admin is logged in. Is there a way to echo the tags that need to be shown? Thanks in advance!
<table>
<tr>
<th>ID</th>
<th>Full Name</th>
<th>Email Address</th>
<th>Address</th>
<th>City</th>
<th>State</th>
<th>Zip Code</th>
<th>Status</th>
<th>Edit?</th>
<th>Delete?</th>
</tr>
<?php foreach ($users as $user) : ?>
<tr>
<td><?php echo $user->getUser_id();?></td>
<td><?php echo $user->getFirstName().' '.$user->getLastName();?></td>
<td><?php echo $user->getEmailAddress(); ?></td>
<td><?php echo $user->getAddress();?></td>
<td><?php echo $user->getCity(); ?></td>
<td><?php echo $user->getState(); ?></td>
<td><?php echo $user->getZipCode(); ?></td>
<td><?php echo $user->getActiveDescription();?></td>
these two <td> should only be shown if x is true:
<td>
<form action ="" method="post">
<input type="hidden" name="controllerRequest"
value="show_user_edit">
<input type="hidden" name="user_id"
value="<?php echo $user->getUser_id(); ?>"/>
<input type="submit" value="Edit"></form>
</td>
<td>
<form action="" method="post">
<input type="hidden" name="controllerRequest"
value="delete_user">
<input type="hidden" name="user_id"
value="<?php echo $user->getUser_id(); ?>"/>
<input type="submit" value="Delete" id="red">
</form>
</td>"
;
}
}
?>
</tr>
<?php endforeach; ?>
</table>
You need to use <?php if(x): ?> and <?php endif ?>see: https://www.php.net/manual/en/control-structures.if.php#112231
Our Wordpress site are infected and we are deleted all files. we have now only database and want to extract all information from db and afther this copy on other site.
so I am using this php class to connect db and call some information. I am calling now posts with data, but need categories also.
For example:
Post Title, Post Content, Post Category
here is my working code without category names
$posts = $db->get('c3624322676f_wp_posts');
but I have no idea how to call categories names here.
This is my html + foreach
<table class="table table-hover">
<thead class="thead-inverse">
<tr>
<th>#</th>
<th>Title</th>
<th>Type</th>
<th>Content</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($posts as $post) : ?>
<tr>
<th scope="row"><?php echo $count++; ?><a href=""></th>
<td><?php echo $post['post_title']; ?></td>
<td><?php echo $post['post_type']; ?></td>
<td><?php echo strip_tags ($post['post_content']); ?></td>
<td>
<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $post['ID']; ?>" />
<input style="cursor:pointer;" type="submit" class="btn btn-primary" value="Delete" />
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
This should work
<table class="table table-hover">
<thead class="thead-inverse">
<tr>
<th>#</th>
<th>Title</th>
<th>Type</th>
<th>Content</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php foreach ($posts as $post) : ?>
<tr>
<th scope="row"><?php echo $count++; ?><a href=""></th>
<td><?php echo $post['post_title']; ?></td>
<td><?php echo $post['post_type']; ?></td>
<td><?php echo strip_tags ($post['post_content']); ?></td>
<?php
$separator = ',';
$output = '';
$categories = get_the_category($post['post_title']);
if ($categories){
foreach($categories as $category) {
$output .= ''.$category->cat_name.''.$separator;
}
echo trim($output, $separator);
}
?>
<td>
<form action="" method="post">
<input type="hidden" name="id" value="<?php echo $post['ID']; ?>" />
<input style="cursor:pointer;" type="submit" class="btn btn-primary" value="Delete" />
</form>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
I have a table with multiple columns (index.php). One column is a checkbox. Whenever the checkbox is checked, it displays another row where you can select a quantity. You can then hit a button called "Add to Order" and it will take you to a confirmation page (index-order.php) where I want it to display each row along with all of the data in that specified row that has the checkbox checked. Currently, I am getting no errors in my console, but no data is being displayed at all.
What do I need to change to make this happen? Here is what I have so far.
Index.php code:
<form name="form1" method="POST" action="index-order.php">
<section id="addToOrder">
<button type="submit" class="order" id="order" name="order" value="AddToOrder">Add to Order</button>
</section>
<br>
<div id="my-div2" class="ui-widget">
<div class="ui-widget">
<table id="merchTable" cellspacing="5" class="sortable">
<thead>
<tr class="ui-widget-header">
<th class="sorttable_nosort"></th>
<th class="sorttable_nosort">Loc</th>
<th class="merchRow">Report Code</th>
<th class="merchRow">SKU</th>
<th class="merchRow">Special ID</th>
<th class="merchRow">Description</th>
<th class="merchRow">Quantity</th>
<th class="sorttable_nosort">Unit</th>
<th style="display: none;" class="num">Quantity #</th>
</tr>
</thead>
<tbody>
<?php foreach ($dbh->query($query) as $row) {?>
<tr>
<td class="ui-widget-content"><input type="checkbox" class="check" name="check"></td>
<td name="rows[0][0][loc]" class="loc ui-widget-content" id="loc-<?php echo intval ($row['Loc'])?>"><?php echo $row['Loc'];?></td>
<td name="rows[0][0][rp-code]" class="rp-code ui-widget-content" align="center" id="rp-code-<?php echo intval ($row['Rp-Code'])?>"><?php echo $row['Rp-Code'];?></td>
<td name="rows[0][0][sku]" class="sku ui-widget-content" id="sku-<?php echo intval ($row['SKU'])?>"><?php echo $row['SKU'];?></td>
<td name="rows[0][0][special-id]" class="special-id ui-widget-content" align="center" id="special-id-<?php echo intval ($row['Special-ID'])?>"><?php echo $row['Special-ID'];?></td>
<td name="rows[0][0][description]" class="description ui-widget-content" id="description-<?php echo intval ($row['Description'])?>"><?php echo $row['Description'];?></td>
<td name="rows[0][0][quantity]" class="quantity ui-widget-content" data-quantity="<?php echo $row['Quantity'] ?>" align="center" id="quantity-<?php echo intval ($row['Quantity'])?>"><?php echo $row['Quantity'];?></td>
<td name="rows[0][0][unit]" class="unit ui-widget-content" id="unit-<?php echo intval ($row['Unit'])?>"><?php echo $row['Unit'];?></td>
<td name="rows[0][0][quant]" style="display: none;" class="quantity_num ui-widget-content"><input type="textbox" style="width: 100px;" class="spinner" name="value" id="test"></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</form>
Index-order.php:
<?php if(isset($_POST['rows'])): ?>
<table cellspacing="20">
<tr align="center">
<th>Loc</th>
<th>Report Code</th>
<th>SKU</th>
<th>Special ID</th>
<th>Description</th>
<th>Quantity</th>
<th>Unit</th>
<th>Quantity #</th>
</tr>
<?php
foreach($_POST['rows'][0] as $row):
?>
<tr align="center">
<td><?php echo $row['loc']; ?></td>
<td><?php echo $row['rp-code']; ?></td>
<td><?php echo $row['sku']; ?></td>
<td><?php echo $row['special-id']; ?></td>
<td><?php echo $row['description']; ?></td>
<td><?php echo $row['quantity']; ?></td>
<td><?php echo $row['unit']; ?></td>
<td><?php echo $row['quant']; ?></td>
</tr>
<?php
endforeach;
?>
</table>
I am okay with the precedent answer, I never heard about this kind of method with PHP and it doesn't seems to be the right solution. Anyway, the following post would maybe help you : How to get value from td's via $_POST.
You cannot transfer datas through POST by using td ; but an alternative would be to use the "hidden" type of forms element :
<form action="script.php" method="post">
<td class=".."><input type="hidden" name="td1" value="...">value</td>
...
</form>
In PHP, you'll grab the data with the $_POST array and the td1 name :
<?php var_dump($_POST); ?>
Itwould in my opinion be the easier way to get what you want in a proper way ; the link I gave upper is also talking about DOMDocument, but it looks more complex to manage with.
//a table to display file from the database
<thead class="thead-inverse">
<tr>
<th>Description </th>
<th>Category</th>
<th>Upload By</th>
<th>Date</th>
<th></th>
</tr>
<thead>
<tbody class="sc">
<?php
// fetch the records from db
while ($row = mysql_fetch_assoc($result)) {
?>
<tr>
<td><?php echo $row['fdesc']; ?></td> //filename
<td><?php echo $row['category']; ?></td>
<td><?php echo $row['username']; ?></td> //user who have upload the file
<td><?php echo $row['fdatein']; ?></td>
//the download button
<td><a href="" ><button type="button" class="btn btn-unique active" data-toggle="tooltip" data-placement="right" title="Download"><i class="fa fa-download"></i> // get the specific to download
</button></a></td>
</tr>
<?php
}
?>
</tbody>
</table>
you can add the id in the the link url like so:
<a href="d1.php?fileId=<?php echo $row['fileID']; ?>" >
then in d1.php the id will be in the variable $_GET['fileID']