I'm building a forum using php and bootstrap. It works 100%, my only issue is when a user posts in a thread, the post and the user profile images has a big gap. It looks like a padding issue, but there is not padding between them. Any advice would be brilliant
echo '<div class="container form">
<div class="page-header page-heading">
<tr class="text-center">
<th colspan="2"><h2>' . $row['topic_subject'] . '</h2></th>
</tr>
<table class="table forum table-striped table-hover">
<thead>
<tr>
<th class="cell-stat"></th>
</tr>
</thead/>';
//fetch the posts from the database
$posts_sql = "SELECT
posts.post_topic,
posts.post_content,
posts.post_date,
posts.post_by,
users.user_id,
users.user_name
FROM
posts
LEFT JOIN
users
ON
posts.post_by = users.user_id
WHERE
posts.post_topic = " . mysql_real_escape_string($_GET['id']);
$posts_result = mysql_query($posts_sql);
if(!$posts_result)
{
echo '<tr><td>The posts could not be displayed, please try again later.</tr></td></table>';
}
else
{
while($posts_row = mysql_fetch_assoc($posts_result))
{
echo '
<tbody>
<tr>
<td class="text-center">
</td>
<td class="hidden-xs hidden-sm">
<img src="ppp.png"><br>
<i class="fa fa-clock-o">
</i>
<ul class="pull-left user-info">
<li>'
.$posts_row['user_name'].
'</li>'.
'<li>'
. date('d-m-Y H:i', strtotime($posts_row['post_date'])).
'</li>
</td>
<td class="pull-right">'.
'<p>'
.htmlentities(stripslashes($posts_row['post_content'])).
'</p>
</td>
</tr>';
}
}
if(!$_SESSION['signed_in'])
{
echo '<tr><td colspan=2>You must be signed in to reply. You can also sign up for an account.';
}
else
{
//show reply box
echo '<tr><td colspan="2"><h2>Reply:</h2><br />
<form method="post" action="reply.php?id=' . $row['topic_id'] . '">
<textarea name="reply-content"></textarea><br /><br />
<input type="submit" value="Submit reply" />
</form></td></tr>';
}
//finish the table
echo '</thead></table>';
}
}
I think the gap might be as a result pull-right applied on the table
<td class="pull-right">'.
'<p>'
.htmlentities(stripslashes($posts_row['post_content'])).
'</p>
</td>
You might want to remove it completely. If not, try applying pull-left to the paragraph instead of table
<td >'.
'<p class="pull-left">'
.htmlentities(stripslashes($posts_row['post_content'])).
'</p>
</td>
Related
I have a table with data that is being pulled from a database and I am trying to add a button to where it will load more data but when I click on it no data comes up. I am new to coding so I don't have that much experience.
This is the main page
Index.php
<?php
include 'database.php'; // MySQL Connection
$query = "SELECT * FROM Clever_Students";
$result = mysqli_query($conn, $query);
?>
<body>
<br /><br />
<div class="container">
<br />
<div class="table-responsive">
<br />
<h4 align="center">Student Data Management</h4>
<div class="table-responsive">
<table class="table table-striped">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th width="20%" class="text-center">View Student Details</th>
</tr>
<?php
while($row = mysqli_fetch_array($result))
{
?>
<tr>
<td><?php echo $row["First_name"]; ?></td>
<td><?php echo $row["Last_Name"]; ?></td>
<td><input type="button" name="view" value="view" id="<?php echo $row["Student_id"]; ?>" class="btn btn-info btn-xs view_data" /></td>
</tr>
<?php
}
?>
</table>
</div>
</div>
</div>
<!-- Employee Details -->
<div id="dataModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal">×</button>
<h4 class="modal-title">Student Details</h4>
</div>
<div class="modal-body" id="student_detail">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
<script>
$(document).ready(function(){
$('.view_data').click(function(){
var Student_id = $(this).attr("Student_id");
$.ajax({
url:"select.php",
method:"post",
data:{Student_id:Student_id},
success:function(data){
$('#student_detail').html(data);
$('#dataModal').modal("show");
}
});
});
});
</script>
</body>
This where the modal should be pulling the data from.
select.php
<?php
if (isset($_POST["Student_id"])) {
$output = '';
include 'database.php'; // MySQL Connection
$query = "SELECT * FROM Clever_Students WHERE Student_id = '" . $_POST["Student_id"] . "'";
$result = mysqli_query($conn, $query);
$output .= '
<div class="table-responsive">
<table class="table table-striped">';
while ($row = mysqli_fetch_array($result)) {
$output .= '
<tr>
<td width="30%"><label>First Name</label></td>
<td width="70%">' . $row["First_name"] . '</td>
</tr>
<tr>
<td width="30%"><label>Last Name</label></td>
<td width="70%">' . $row["Last_Name"] . '</td>
</tr>
<tr>
<td width="30%"><label>Gender</label></td>
<td width="70%">' . $row["Gender"] . '</td>
</tr>
<tr>
<td width="30%"><label>School ID</label></td>
<td width="70%">' . $row["School_id"] . '</td>
</tr>
';
}
$output .= "</table></div>";
echo $output;
}
?>
I have added the code above. Anything will help.
i have that table and a div with a quicksearch and after i write 2 or 3 letters he show results, but then the div search dissapear after show the results and if i want to write something new, i have to refresh the page
thats the div
<table id="tabela" class="table admin">
<tr class="outro">
<th width="15%">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.quicksearch/2.3.1/jquery.quicksearch.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<div class="form-group input-group">
<span class="input-group-addon"><i class="glyphicon glyphicon-search"></i></span>
<input name="consulta" id="txt_consulta" placeholder="Procurar..." type="text" class="form-control">
</div>
</th>
<th width="10%"></th>
<th width="30%"></th>
<th width="15%">
<img src="../assets/img/add.PNG" class="icone" />Adicionar utilizador
</a>
</th>
</tr>
<tr class="tabela">
<th width="10%">
<p>Nome</p>
</th>
<th width="5%"></th>
<th width="30%">
<p>Permissões</p>
</th>
<th width="10%"></th>
</tr>
<?php
foreach ($utilizadores as $key => $value) {
echo '<tr><td>' . '<p class="texto">' . $value->nome . '</p>' . '</td>';
echo '<td>' . '<button type="button" class="btn btn-info" data-toggle="modal" data-target="#myModal">' . '<p>Info</p>' . '</button></td>';
echo '<td>';
if ($value->tipo_user == "1") {
echo '<p class="texto">' . "Administrador" . '</p>';
} else if ($value->tipo_user == "2") {
echo '<p class="texto">' . "Gestor" . '</p>';
} else {
echo '<p class="texto">' . "Utilizador" . '</p>';
}
'</td>';
echo '<td>Eliminar</p></td></tr>';
}
?>
</table>
and thats the script
<script>
$('input#txt_consulta').quicksearch('table#tabela tbody tr');
</script>
what am i doing wrong?
It's because your quicksearch filters all rows of your table. You can solve that by giving your dynamically added rows a class and set quicksearch upon that class.
echo '<tr class="filter_row"><td>' . '<p class="texto">' . $value->nome . '</p>' . '</td>';
and then you have to add that to the configuration script:
<script>
$('input#txt_consulta').quicksearch('table#tabela tbody tr.filter_row');
</script>
I'm trying to implement a feature which allows me to delete students from a students list. (which is a table)
Though when I click delete it does not delete the student in that current row HOWEVER.. if i change my query to DELETE FROM students WHERE id = 1 for example.. it works. So, I'm believing the problem lies with not being able to grab the id from the current row however, I'm not sure where I am going wrong with this.
//StudentsList.php
<?php include ('../resources/styling.html'); ?>
<?php include ('adminNavbar.php'); ?>
<!--HTML styling of the table that outputs the database entries, bootstrap styling-->
<div class="container content-area">
<div class="row">
<div class="col-md-12">
<div class="panel">
<br>
<div class="text-center border border-light p-5">
<p class="h4 mb-4">All Student Accounts</p>
</div>
<br>
<table class="table table-hover">
<thead>
<tr>
<th scope="col">#</th>
<th scope="col">First Name</th>
<th scope="col">Surname</th>
<th scope="col">Programme</th>
<th scope="col">Student ID</th>
<th scope="col">Delete</th>
</tr>
</thead>
<tbody>
</div>
</div>
</div>
</div>
<?php
include ('../resources/config.php');
$sql = "SELECT id,firstname, surname, programme, studentid FROM students";
$result = $db->query($sql);
// while loop to output data of each row for each student in database
while($row = $result->fetch_assoc()) {
echo '<tr>
<td scope="row">' . $row["id"]. '</td>
<td>' . $row["firstname"] .'</td>
<td> '.$row["surname"] .'</td>
<td> '.$row["programme"] .'</td>
<td> '.$row["studentid"] .'</td>
<td ><a class="btn btn-danger" href="MLdelete.php?id=".$row["id"].""</a> Delete</td>
</tr>';
}
$db->close();
?>
</tbody>
</table>
<div class="text-center border border-light p-5">
Add New Student Account
</div>
//MLdelete.php
<?php
require ( '../resources/config.php' );
if(isset($_GET["id"])){
$id = mysqli_real_escape_string($db, $_GET["id"]);
// sql to delete a record
$query = "DELETE FROM students WHERE id ='{$id}'";
$del=mysqli_query($db,$query);
if ($del) {
header("Location: StudentsList.php");
} else {
echo "Error deleting record: " . $db->error;
}
}
$db->close();
?>
Basically, when I click the DELETE button for a row, nothing happens.
You did not properly quote your <a> link.
It should be
<td ><a class="btn btn-danger" href="MLdelete.php?id=' . $row["id"] . '"</a> Delete</td>
Also use prepared statements as per my comment. This will prevent SQL injection attacks.
Check out prepared statements explanation and examples via the PHP manual
I have a table that I want to assign a staff member to for each row. I want a dropdown on the last column with all the staff members so I can assign a staff member by clicking their username in the dropdown.
I'm trying to do a while loop inside a while loop but am getting an error.
This is my current code:
<table class="table table-bordered table-striped js-dataTable-full table-header-bg">
<thead>
<tr>
<th>Actions</th>
<th>Username</th>
<th>Service</th>
<th>Price</th>
<th>Date Ordered</th>
<th>Account Email</th>
<th>Account Password</th>
<th>Status</th>
<th>Assign to staff</th>
</tr>
</thead>
<tbody>
<?php
$clients_result = mysqli_query($con, "SELECT * FROM boosting_orders ORDER BY id ASC");
$query = mysqli_query( $con, "SELECT * FROM users" );
if(mysqli_num_rows($clients_result) > 0) {
while($payment_row = mysqli_fetch_array($clients_result)) {
echo '
<tr id="no_enter">
<td style="text-align: center;">
<div class="btn-group">
<a class="btn btn-xs btn-default" type="button" data-toggle="tooltip" title="" data-original-title="Edit Order" href="orders_admin?action=edit&identification='.$payment_row['id'].'"><i class="fa fa-pencil"></i></a>
<a class="btn btn-xs btn-default" type="button" data-toggle="tooltip" title="" data-original-title="Remove Order" href="orders_admin?action=delete&identification='.$payment_row['id'].'"><i class="fa fa-times"></i></a>
</div>
</td>
<td>
'.$payment_row['users_name'].'
</td>
<td>
'.$payment_row['service'].'
</td>
<td>
$'.$payment_row['price'].'
</td>
<td>
'.$payment_row['date_ordered'].'
</td>
<td>
'.$payment_row['email'].'
</td>
<td>
'.$payment_row['password'].'
</td>
<td>
'.($payment_row['status'] == 'Completed' ? '<span class="label label-success" data-toggle="tooltip" title="" data-original-title="Your account has successfully been boosted">Completed</span>' : '<span class="label label-info" data-toggle="tooltip" title="" data-original-title="This order is either still pending or corrupt">Pending</span>').'
</td>
<td>
<select name="assign_staff" class="form-control">
'. while($row = mysqli_fetch_array($query)) { .'
<option value="'.$row['username'].'">'.$row['username'].'</option>
'. } .'
</select>
</td>
</tr>
';
} } else { } ?>
</tbody>
you can't concatenate string with while syntax,
the code in the last <td> should be:
echo '<select name="assign_staff" class="form-control">';
while ($row = mysqli_fetch_array($query)) {
echo '<option value="' . $row['username'] . '">' . $row['username'] . '</option>';
}
echo '</select>
When I click the delete button, the values of those checkboxes that are checked in the table are not shown. It is suppose to delete records on the database based on the id but i'm stuck in getting the value of the checkboxes. Please help correct my code. I'm using bootstrap for your information.
PHP
$sql = "SELECT id, title FROM box";
$query = mysqli_query($db, $sql);
if(isset($_POST['btnDelete'])) {
$checkbox = isset($_POST['chkDelete']) ? $_POST['chkDelete'] : array();
for($i=0;$i<count($checkbox);$i++)
{
$message = $checkbox[$i];
}
}
HTML
<div class="content">
<div id="table">
<table class="col-md-12 table-bordered table-striped table-condensed cf">
<thead class="cf">
<tr>
<th></th>
<th>#</th>
<th>Title</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
while($result = mysqli_fetch_array($query))
{
$html = '<tr>
<td data-title="">
<input name="chkDelete[]" type="checkbox" value="' . $result['id'] . '">
</td>
<td data-title="#">' . $result['id'] . '</td>
<td data-title="Title">' . $result['title'] . '</td>
<td data-title="Action">
Edit
</td>
</tr>';
echo $html;
}
?>
</tbody>
</table>
</div>
<form action="" method="POST">
<input type="submit" name="btnDelete" value="Delete" />
</form>
<div class="message"><?php echo $message;?></div>
</div> <!--//END content-->
PHP (Write Delete Query inside for loop to delete all checked checkbox.)
<?php
if(isset($_POST['btnDelete']))
{
$checkbox = isset($_POST['chkDelete']) ? $_POST['chkDelete'] : array();
$id = 0;
for($i=0;$i<count($checkbox);$i++)
{
$id = $checkbox[$i];
$deleteQuery = "DELETE FROM box WHERE id='$id'";
$DeleteQueryExec = mysqli_query($db, $deleteQuery);
}
}
?>
HTML (Put entire table inside <form></form>)
<div class="content">
<form action="" method="POST">
<div id="table">
<table class="col-md-12 table-bordered table-striped table-condensed cf">
<thead class="cf">
<tr>
<th></th>
<th>#</th>
<th>Title</th>
<th>Action</th>
</tr>
</thead>
<tbody>
<?php
$sql = "SELECT id, title FROM box";
$query = mysqli_query($db, $sql);
while($result = mysqli_fetch_array($query))
{
$html = '<tr>
<td data-title="">
<input name="chkDelete[]" type="checkbox" value="' . $result['id'] . '">
</td>
<td data-title="#">' . $result['id'] . '</td>
<td data-title="Title">' . $result['title'] . '</td>
<td data-title="Action">
Edit
</td>
</tr>';
echo $html;
}?>
</tbody>
</table>
</div>
<input type="submit" name="btnDelete" value="Delete" />
<div class="message"><?php echo $message;?></div>
</form>
</div> <!--//END content-->