I have a table that should retrieve all the row form the database based on a selection from the same row.
HTML & PHP Code
<div class="row">
<div class="table-responsive">
<table class="table table-bordered" id="tab_logic">
<thead>
<tr>
<th>Brand Name</th>
<th>Item Name</th>
<th>Model Number</th>
<th class="col-md-2">Item Description</th>
<th>Part Number</th>
<th>Unit</th>
<th class="col-md-1">QTY</th>
<th class="col-md-1">Unit Price (SR)</th>
<th class="col-md-1">Total Price (SR)</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<strong>Record</strong>
</td>
<td>
<strong>Record</strong>
</td>
<td>
<strong>Record</strong>
</td>
<td>
<div class="form-group">
<?php
$query = $con->query("SELECT products_itemDescription FROM pruc_products"); // Run your query --> For Item Desc.
echo '<select class="form-control" id="DescriptionS2forms" name="itemDescription">'; // Open your drop down box
echo '<option value="" selected="selected" disabled></option>'; //Empty Value for VALIDATION
// Loop through the query results, outputing the options one by one
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
echo '<option value="'.$row['products_itemDescription'].'">'.$row['products_itemDescription'].'</option>';
}
echo '</select>';// Close your drop down box
?>
</div>
</td>
<td>
<strong>Record</strong>
</td>
<td>
<strong>Record</strong>
</td>
<td>
<div>
<input class="form-control" type="number" name="requestQTY" required>
</div>
</td>
<td>
<div>
<input class="form-control" type="number" name="requestUnit" step="0.01" min="0.01" max="1000000" required>
</div>
</td>
<td>
<strong>Record</strong>
</td>
<td class="col-md-1" id="deleteBtn">
<a class="btn btn-default deleteBtn">Delete</a>
</td>
</tr>
</tbody>
</table>
</div>
</div>
So I have this selection as defined it is fetched from the database so I need every "Record" to be fetched also but based on the selection I'll make from the selection tab.
PHP & SQL Query
<?php
$sql = $con->prepare("SELECT products_brandName FROM pruc_products WHERE products_brandName, products_itemDescription = (products_id)") ;
$sql->execute() ;
while( $row = $sql->fetch()):
echo '<strong>'.$row['products_brandName'].'</strong>';
endwhile ?>
any help for this?
products_barndName needs to equal something. Also, don't use a comma to separate your conditions in a WHERE clause. Try this:
WHERE products_brandName = 'x' AND products_itemDescription = (products_id)
Related
I am working on a small course registration system. I have a table called 20182019carryovertbl I select students carry over fron the table and its working well. I need to convert the selected info to an HTML form with submit button( This will go into another table 20192020coursestbl). How d i set name for my inputs
<table>
<thead>
<tr>
<th>Register course</th>
<th>Course Title</th>
<th>Corse Code</th>
<th>Unit</th>
<th>Lecturer</th>
</tr>
</thead>
<tbody>
<?php $sql = "SELECT * from 20182019carryovertbl WHERE matricno = '$matno' ";
$query = $dbh -> prepare($sql);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);
$cnt=1;
if($query->rowCount() > 0)
{
foreach($results as $result)
{ ?>
<tr>
<td> <input type="checkbox" name="reg1" value="1" class="custom-control-input"></td>
<td>
<?php echo htmlentities($result->coursetitle);?>
</td>
<td>
<?php echo htmlentities($result->coursecode);?>
</td>
<td>
<?php echo htmlentities($result->unit);?>
</td>
<td>
<?php echo htmlentities($result->lecturer);?>
</td>
</tr>
<?php $cnt=$cnt+1; }} ?>
</tbody>
</table>
you can use your unique key from database like Id:
<td>
<input type="checkbox" name="reg<?php echo $result->id;" value="1"class="custom-control-input">
</td>
and it's gonna be unique name
I am trying to output my acf 5 repeater field in a table.
I use the following code:
<?php
// check if the repeater field has rows of data
if (have_rows('founder')):
?>
<div class="control-group">
<label class="control-label">Founders</label>
<div class="controls">
<table class="table table-hover">
<thead>
<tr>
<th>Image</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<?php
// loop through the rows of data
while (have_rows('founder')):
the_row(); ?>
<tr>
<td> <img src="<?php the_sub_field('founder_img'); ?>"></img> </td>
<td><?php echo get_sub_field('firstname'); ?> <?php the_sub_field('lastname'); ?></td>
</tr>
<?php
endwhile; ?>
</tbody>
</table>
</div>
</div>
<?php endif; ?>
However, even though I have in my backend all the fields filled I get the following output:
The html output looks like the following:
<div class="control-group">
<label class="control-label">Founders</label>
<div class="controls">
<table class="table table-hover">
<thead>
<tr>
<th>Image</th>
<th>Name</th>
</tr>
</thead>
<tbody>
<tr>
<td> <img src="https://example.com/wp-content/uploads/2016/03/no-avai.jpg"> </td>
<td>test test</td>
</tr>
<tr>
<td> <img src="https://example.com/wp-content/uploads/2016/03/no-avai.jpg"> </td>
<td>Firstname Lastname</td>
</tr>
</tbody>
</table>
</div>
</div>
Any suggestion what I am doing from?
This question already has answers here:
jQuery sum rows adding all cells
(3 answers)
Closed 5 years ago.
Below is my table code with Add New button. Onclick Add New
button new row will create. In picture you can see this. User will
input debit and credit values at the end all debit values should be
calculate and sum should be display and same for the credit value. I
am using jQuery to create new row:
Jquery code:
<script type="text/javascript">
$("#add, .check ").click(function() {
$('#datatable-buttons tbody>tr:last')
.clone(true)
.insertAfter('#datatable-buttons tbody>tr:last').find('input').each(function(){
$(this).val('');
});
});
</script>
Html table code:
<table id="datatable-buttons" class="table table-striped jambo_table bulk_action">
<thead>
<tr class="headings">
<th>
<input type="checkbox" id="check-all" class="flat">
</th>
<th class="column-title">Account</th>
<th class="column-title">Debits</th>
<th class="column-title">Credits</th>
<th class="column-title">Description</th>
<th class="column-title">Name</th>
<th class="column-title no-link last"><span class="nobr">Action</span>
</th>
<th class="bulk-actions" colspan="7">
<a class="antoo" style="color:#fff; font-weight:500;">Bulk Actions ( <span class="action-cnt"> </span> ) <i class="fa fa-chevron-down"></i></a>
</th>
</tr>
</thead>
<tbody>
<tr class="even pointer">
<td class="a-center ">
<input type="checkbox" class="flat" name="table_records">
</td>
<td class=" "><select class="form-control" name="journalname">
<option>Choose option</option>
<?php
$sql = mysqli_query($conn,'SELECT * FROM `chartofaccounts`');
while ($row1 = mysqli_fetch_array($sql))
{?>
<option value="<?php echo $row1["name"];?>"><?php echo $row1["name"];?></option>
<?php }?>
</select></td>
<td class=""><input class="form-control" type="text" name="debit" ></td>
<td class=" "><input class="form-control" type="text" name="credit"></td>
<td class=" "><input class="form-control" type="text" name="descc"></td>
<td class=" "><input class="form-control" type="text" name="name"></td>
<td class=" last">View
</td>
</tr>
</tbody>
</table>
<button type="button" id="add">Add New</button>
Below image will give you clear understanding:
made you a simple example of how to calculate the sum from the input fields.
check snippet below or jsFiddle
add numbers to the 3 inputs, and then click on View , it will get the sum of the 3 input values.
var input = $("input"),
button = $("td.last a")
$(button).click(function () {
var sum = 0;
$(input).each(function() {
sum += Number($(this).val());
});
$(this).html(sum)
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table>
<tr>
<td>
<input>
</td>
<td>
<input>
</td>
<td>
<input>
</td>
<td class=" last">View
</tr>
</table>
Need to display retrieved data from mysql table in table format, but not getting the right display i planned for. This is how i want it to look like
Target display
But this is what am getting based on my code
Current display
This is the html code
<div>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Department</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$staff_set = find_all_employee();
while ($staff = mysqli_fetch_assoc($staff_set)) {
//display staff first name, last name, department and action (edit and delete links)
?>
<tr>
<td>
<?php
echo $staff["first_name"];
}
?>
</td>
<?php
$staff_set = find_all_employee();
while ($staff = mysqli_fetch_assoc($staff_set)) {
//display staff last name
?>
<td>
<?php
echo $staff["last_name"];
}
?>
</td>
<?php
$staff_set = find_all_employee();
while ($staff = mysqli_fetch_assoc($staff_set)) {
//display staff department
?>
<td>
<?php
echo $staff["department"];
}
?>
</td>
<td>
<span class="glyphicon glyphicon-pencil"> Edit</span>
 
<span class="glyphicon glyphicon-trash"> Delete</span>
</td>
</tr>
</tbody>
</table>
</div>
Here is the function that am using to find the list of all employee from the my staff table
function find_all_employee() {
global $connection;
$query = "select * from staff";
$staff_set = mysqli_query($connection, $query);
confirm_query($staff_set);
return $staff_set;
}
Is there a better way to write the loop and display my data in the right way? I have looked up similar threads but still not able to grasp.
I dont understand why you calling so much tie function and also why making so much loops. Let me try fi your code:
<div>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Department</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$staff_set = find_all_employee();
while ($staff = mysqli_fetch_assoc($staff_set)) {
//display staff first name, last name, department and action (edit and delete links)
?>
<tr>
<td>
<?php echo $staff["first_name"]; ?>
</td>
<td>
<?php echo $staff["last_name"]; ?>
</td>
<td>
<?php echo $staff["department"]; ?>
</td>
<td>
<span class="glyphicon glyphicon-pencil"> Edit</span>
 
<span class="glyphicon glyphicon-trash"> Delete</span>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
Since OP asked for a varying technique in a comment:
<?php
// Select all staff first name, last name, and department info
$staff_set = find_all_employee();
$staff_results = array();
while ($staff = mysqli_fetch_assoc($staff_set)) {
$staff_results[] = $staff;
}
?>
<div>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Department</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php if (!empty($staff_results)): ?>
<?php foreach($staff_results as $staff_member): ?>
<tr>
<td>
<?= $staff_member["first_name"]; ?>
</td>
<td>
<?= $staff_member["last_name"]; ?>
</td>
<td>
<?= $staff_member["department"]; ?>
</td>
<td>
<span class="glyphicon glyphicon-pencil"> Edit</span>
 
<span class="glyphicon glyphicon-trash"> Delete</span>
</td>
</tr>
<?php endforeach; ?>
<?php else: ?>
<tr><td colspan="4">No Staff Members Found.</td></tr>
<?php endif; ?>
</tbody>
</table>
</div>
This also introduces the short tag syntax (<?=) for replacing calls to echo. Read this thread if your PHP version is < 5.4. This also introduces control structure alternate syntax, for better readability with HTML. The above approach separates the concern of selecting data from the DB from the presentation of the HTML. This allows for easier debugging, as well as future adaptation and modularization of your application.
I have a database
that have two tables.
The sql query fetching data correctly.
I want to sort fields data by typing table heading in text box and click on go that in table footer.
Many Thanks
<table border="0" cellpadding="0" cellspacing="0" width="50%">
<thead>
<tr>
<th class="capt" colspan="6">Available Projects</th>
</tr>
<tr>
<th>Select</th>
<th>Project</th>
<th>Crawler</th>
<th>Description</th>
<th>Status</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
include(dirname(__file__)."/includes/dbConn.php");
$result = mysql_query("SELECT *, ( SELECT name FROM projects WHERE projects.id = crawlers.pid ) AS pname FROM `crawlers`", $appConn);
while($row = mysql_fetch_array($result))
{
?>
<tr id="crawler_<?php echo $row['id']; ?>">
<td>
<input value="" id="check" type="checkbox">
<input id="crawler_id_<?php echo $row['id']; ?>" type="hidden" value="<?php $row['id']; ?>" /> <!-- crawler id -->
</td>
<td><?php echo $row['pname']; ?></td>
<td><?php echo $row['name']; ?></td>
<td>username#domain.com</td>
<td>Enabled</td>
<td><a class="edit" href="#">edit</a><a class="add" href="#">run</a><a class="delete" href="#">delete</a></td>
</tr>
<?php } ?>
</tbody>
<tfoot>
<tr>
<th colspan="6"> Sort Fields by <input value="type here" id="field" type="text"> Go </th>
</tr>
</tfoot>
</table>
I think, you are looking for ORDER BY
Have a look at the MySQL Documentation about the SELECT syntax: http://dev.mysql.com/doc/refman/5.0/en/select.html