How to Hide or Show an included with PHP - php

I'm trying to hide an included file with a condition.
<?php include('header_dashboard.php'); ?>
<?php include('session.php'); ?>
<?php $get_id = $_GET['id']; ?>
<?php
$post_id = $_GET['post_id'];
if($post_id == ''){
?>
<script>
window.location = "assignment_student.php<?php echo '?id='.$get_id; ?>";
</script>
<?php
}
?>
<body id="studentTableDiv">
<?php include('navbar_student.php'); ?>
<div class="container-fluid">
<div class="row-fluid">
<?php include('assignment_link_student.php'); ?>
<div class="span6" id="content">
<div class="row-fluid">
<!-- breadcrumb -->
<?php $class_query = mysqli_query($conn, "select * from teacher_class
LEFT JOIN class ON class.class_id = teacher_class.class_id
LEFT JOIN subject ON subject.subject_id = teacher_class.subject_id
where teacher_class_id = '$get_id'")or die(mysqli_error());
$class_row = mysqli_fetch_array($class_query);
?>
<ul class="breadcrumb">
<li><?php echo $class_row['class_name']; ?> <span class="divider">/</span></li>
<li>Asignaciones <span class="divider">/</span></li>
<li><b>Subir Asignación</b></li>
</ul>
<!-- end breadcrumb -->
<!-- block -->
<div id="block_bg" class="block">
<div class="navbar navbar-inner block-header">
<div id="" class="muted pull-left"></div>
</div>
<div class="block-content collapse in">
<div class="span12">
<?php
$query1 = mysqli_query($conn, "select * FROM assignment where assignment_id = '$post_id'")or die(mysqli_error());
$row1 = mysqli_fetch_array($query1);
?>
<div class="alert alert-info">Subir respuesta de asignacion en : <?php echo $row1['fname']; ?></div>
<div id="">
<table cellpadding="0" cellspacing="0" border="0" class="table" id="">
<thead>
<tr>
<th>Fecha Subida</th>
<th>Nombre de Archivo</th>
<th>Descripción</th>
<th>Enviado por:</th>
<th>Calificación</th>
</tr>
</thead>
<tbody>
<?php
$query = mysqli_query($conn, "select * FROM student_assignment LEFT JOIN student on student.student_id = student_assignment.student_id where assignment_id = '$post_id' order by assignment_fdatein DESC")or die(mysqli_error());
while($row = mysqli_fetch_array($query)){
$id = $row['student_assignment_id'];
$student_id = $row['student_id'];
?>
<tr>
<td><?php echo $row['assignment_fdatein']; ?></td>
<td><?php echo $row['fname']; ?></td>
<td><?php echo $row['fdesc']; ?></td>
<td><?php echo $row['firstname']." ".$row['lastname']; ?></td>
<?php if ($session_id == $student_id){ ?>
<td>
<span class="badge badge-success"><?php echo $row['grade']; ?></span>
</td>
<?php }else{ ?>
<td></td>
<?php } ?>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</div>
</div>
<!-- /block -->
</div>
</div>
<?php include('submit_assignment_sidebar.php') ?>
</div>
<?php include('footer.php'); ?>
</div>
<?php include('script.php'); ?>
</body>
</html>
<?php include('submit_assignment_sidebar.php') ?>
OK what I'm trying to do is move this include that is at the end
<?php include('submit_assignment_sidebar.php') ?>
To:
<?php if ($session_id == $student_id){ ?>
<td>
<span class="badge badge-success"><?php echo $row['grade']; ?></span>
</td>
<?php }else{ ?>
<td></td>
<?php include('submit_assignment_sidebar.php') ?>
<?php } ?>
But it doesn't work. Doesn't include de sidebar file. Any sugestion?

Related

Random data listing and grouping

I have a 9-person classroom. I want to randomly divide the students in this class into three-person classes. It keeps returning the same names in my query. How can I do this, can you help?
I listed all the students first. Then I want to randomly group them into three.
My source code:
<?php
require 'db.php';
$students = $db->query('SELECT * FROM students')->fetchAll(PDO::FETCH_ASSOC);
?>
<div class="container mt-2">
<div>
<table class="table table-bordered">
<thead>
<tr>
<th scope="col">ID</th>
<th scope="col">Name</th>
<th scope="col">No</th>
</tr>
</thead>
<tbody>
<?php foreach($students as $student): ?>
<tr>
<th scope="row"><?php echo $student['id'] ?></th>
<td><?php echo $student['name'] ?></td>
<td><?php echo $student['no'] ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php
$randomstudents = $db->query('select * from students order by rand() limit 3')->fetchAll(PDO::FETCH_ASSOC);
?>
<div class="row">
<div class="col-md-3">
<h6>3 Person Classroom</h6>
<hr>
<ul>
<?php foreach($randomstudents as $rs): ?>
<li><?php echo $rs['name']; ?></li>
<?php endforeach; ?>
</ul>
</div>
<div class="col-md-3 offset-md-1">
<h6>3 Person Classroom</h6>
<hr>
<?php foreach($randomstudents as $rs): ?>
<li><?php echo $rs['name']; ?></li>
<?php endforeach; ?>
</div>
<div class="col-md-3 offset-md-1">
<h6>3 Person Classroom</h6>
<hr>
<?php foreach($randomstudents as $rs): ?>
<li><?php echo $rs['name']; ?></li>
<?php endforeach; ?>
</div>
</div>
</div>
you can try to use array_chunk()
<?php
$randomstudents = $db->query('select * from students order by rand()')
->fetchAll(PDO::FETCH_ASSOC);
$randomstudents = array_chunk($randomstudents, 3);
foreach ($randomstudents as $groupOfThree) :
?>
<div class="col-md-3">
<h6>3 Person Classroom</h6>
<hr>
<ul>
<?php foreach($groupOfThree as $rs): ?>
<li><?php echo $rs['name']; ?></li>
<?php endforeach; ?>
</ul>
</div>
<?php endforeach; ?>

when i click edit button nothing show in the edit form this the error

I am getting the following error:
http://localhost/sites/admin_panel/student_center_system/controller/admin/editmaster.php?item_id=Notice: Undefined variable: row in C:\xampp\htdocs\sites\admin_panel\student_center_system\controller\admin\viewitems.php on line 49
when i click edit button on viewitem.php nothing shows up in the form it is empty this viewitems.php The database connection is working perfect but the problem is the edit form .Ihave been stack for two days with this problem about edit form not working.could someone help me please i will appreciate thank you.
<?php
include "navigation.php";
include "header.php";
include "footer.php";
?>
<?php
include("../dbConfig.php");
$query = "SELECT item_id,item_name,description,item_category,pic FROM lost_items_table";
$returnD = mysql_query($query);
$returnD1 = mysql_query($query);
$result = mysql_fetch_assoc($returnD);
?>
<!-- Page Content -->
<div id="page-wrapper">
<div class="container-fluid">
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">View Items</h1>
<div class="row">
<div class="col-lg-12">
<div class="panel panel-default">
<div class="panel-heading">View Items</div>
<table width="100%" class="table table-striped table-bordered table-hover" id="dataTables-example">
<tr>
<th>Item Id</th>
<th>Item Name</th>
<th>Description</th>
<th>Item category</th>
<th>Picture</th>
<th>Edit</th>
<th>Delete</th>
</tr>
<?php
while($result1 = mysql_fetch_assoc($returnD1)){
?>
<tr>
<td>
<?php echo $result1['item_id']; ?>
</td>
<td><?php echo ucfirst($result1['item_name']); ?></td>
<td><?php echo ucfirst($result1['description']); ?></td>
<td><?php echo ucfirst($result1['item_category']); ?></td>
<td><?php echo ucfirst($result1['pic']); ?></td>
<td>
Edit
</td>
<td>
Delete
</td>
</tr>
<?php
}
?>
</table>
<!-- /.table-responsive -->
</div>
</div>
<!-- /.panel -->
</div>
<!-- /.col-lg-12 -->
</div>
</div>
<!-- /.col-lg-12 -->
</div>
<!-- /.row -->
</div>
</div>
this is editmaster.php file.this is the form for editing data and nothing is showing up in the form its empty.what could be wrong with my code .
<?php session_start();
include("../dbConfig.php");
include "navigation.php";
include "header.php";
include "footer.php";
{
}
$item_id = '';
$item_name = '';
$description = '';
$item_category = '';
$pic = '';
if (isset($_POST['updateitem']))
{
if (is_numeric($_POST['item_id']))
{
$item_id = $_POST['item_id'];
$item_name = mysql_real_escape_string(htmlspecialchars($_POST['item_name']));
$description = mysql_real_escape_string(htmlspecialchars($_POST['description']));
$item_category = mysql_real_escape_string(htmlspecialchars($_POST['item_category']));
$pic = mysql_real_escape_string(htmlspecialchars($_POST['pic']));
if ($item_name == '' || $description == '' || $item_category == '' || $pic == '')
{
$error = 'ERROR: Please fill in all required fields!';
valid($item_id, $item_name, $description, $item_category, $pic, $error);
}
else
{
mysql_query("UPDATE lost_items_table SET item_name = '$item_name', description = '$description', item_category = '$item_category', pic = '$pic' WHERE item_id = '$item_id'")
or die(mysql_error());
header("Location: viewitems.php");
}
}
else
{
echo 'Error!';
}
}
else
{
if (isset($_GET['item_id']) && is_numeric($_GET['item_id']) && $_GET['item_id'] > 0)
{
$item_id = $_GET['item_id'];
$result = mysql_query("SELECT * FROM lost_items_table WHERE item_id=$item_id")
or die(mysql_error());
$row = mysql_fetch_array($result);
if($row)
{
$item_name = $row['item_name'];
$description = $row['description'];
$item_category = $row['item_category'];
$pic = $row['pic'];
valid($item_id, $item_name, $description, $item_category, $pic,'');
}
else
{
echo "No results!";
}
}
else
{
echo 'Error!';
}
}
?>
<!-- Page Content -->
<div id="page-wrapper">
<div class="container-fluid">
<!-- /.row -->
<div class="row">
<!--div class="col-md-8 col-md-offset-4"-->
<div class="col-lg-6">
<div class="Register-panel panel panel-default">
<!--div class="panel panel-default"-->
<div class="panel-heading">
Edit Item
</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-6">
<div class="panel-body">
<form role="form" action="adminPage.php">
<input type="text" name="item_id" value=<?php echo $item_id; ?> readonly><br>
<input type="text" name="item_name" required autofocus placeholder="Item-Name" value=<?php echo $item_name; ?>><br>
<input type="text" name="description" required autofocus placeholder="Description" value=<?php echo $description; ?>><br>
<input type="text" name="item_category" required autofocus placeholder="Item_category" valu
e=<?php echo $item_category; ?>><br>
<input type="text" name="pic" required autofocus placeholder="pic" value=<?php echo $pic; ?>><br>
<input type="submit" name="updateitemBtn" value="Update">
</form>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

undefined variable sub_total. even after defining the variable

<?php
include('includes/db.php');
?>
<?php include('functions/functions.php'); ?>
<?php
include('header.php');
?>
<?php
include('topheader.php');
?>
<?php
include('nav.php');
?>
<div id="content">
<div class="container">
<div class="col-md-12">
<ul class="breadcrumb">
<li>Home</li>
<li>Cart</li>
</ul> <!--breadcrumb ends--->
</div> <!---col-md-12 ends-->
<div class="col-md-9" id="cart">
<div class="box">
<form action="cart.php" method="post" enctype="multipart-form-data">
<h1>Shopping Cart</h1>
<?php
$ip_add = getUserIP();
$select_cart = "select * from cart where ip_add='$ip_add'";
$run_cart = mysqli_query($conn, $select_cart);
$count = mysqli_num_rows($run_cart);
?>
<p class="text-muted">You currently have <?php echo $count; ?> items in your cart</p>
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th colspan="2">Product</th>
<th>Quantity</th>
<th colspan="1">Unit Price</th>
<th>Container</th>
<th colspan="1">Delete</th>
<th colspan="2">Sub Total</th>
</tr>
</thead> <!--thead ends-->
<tbody>
<?php
$total = 0;
while ($row_cart = mysqli_fetch_array($run_cart)) {
$pro_id = $row_cart['p_id'];
$pro_size = $row_cart['size'];
$pro_qty = $row_cart['qty'];
$get_products = "select * from products where product_id='$pro_id'";
$run_products = mysqli_query($conn, $get_products);
while ($row_products = mysqli_fetch_array($run_products)) {
$product_title = $row_products['product_title'];
$product_img1 = $row_products['product_img1'];
$only_price = $row_products['product_price'];
$sub_total = $row_products['product_price'] * $pro_qty;
$total += $sub_total;
}
?>
<tr>
<td><img src="admin_area/product_images/<?php echo $product_img1; ?>"></td>
<td><?php echo $product_title; ?></td>
<td><?php echo $pro_qty; ?></td>
<td>₹<?php echo $only_price; ?>.00</td>
<td><?php echo $pro_size ?></td>
<td><input type="checkbox" name="remove[]" value="<?php echo $pro_id; ?>"></td>
<td>₹<?php echo $sub_total; ?>.00</td>
</tr> <!---tr ends-->
<?php } ?>
</tbody>
<tfoot>
<tr>
<th colspan="5">TOTAL</th>
<th colspan="2">₹ <?php echo $total; ?>.00</th>
</tr>
</tfoot> <!--tfoot ends-->
</table> <!--table ends-->
</div> <!---table-responsive end-->
<div class="box-footer">
<div class="pull-left">
<a href="index.php" class="btn btn-default">
<i class="fa fa-chevron-left"></i>Continue Shopping
</a>
</div> <!--pullleft ends-->
<div class="pull-right">
<button class="btn btn-default" type="submit" name="update" value="Update Cart"><i class="fa fa-refresh"></i>Update Cart </button>
<a href="checkout.php" class="btn btn-primary">
Proceed to checkout<i class="fa fa-chevron-right"></i>
</a>
</div> <!--pullright ends-->
</div> <!----box footer ends-->
</form> <!---form ends-->
</div> <!---box ends-->
<?php
function update_cart() {
global $conn;
if (isset($_POST['update'])) {
foreach ($_POST['remove'] as $remove_id) {
$delete_product = "delete from cart where p_id='$remove_id'";
$run_delete = mysqli_query($conn, $delete_product);
if ($run_delete) {
echo "<script>window.open('cart.php','_self')</script>";
}
}
}
}
echo #$up_cart = update_cart();
?>
<div class="row same-height-row">
<div class="col-md-3 col-md-6">
<div class="box same-height headline">
<h3 class="text-center">Recently Viewed Product</h3>
</div> <!----box same-height headline end-->
</div> <!---col-m-3 col-md-6 ends---->
<?php
$get_products = "select * from products order by rand() LIMIT 0,3";
$run_products = mysqli_query($conn, $get_products);
while ($row_products = mysqli_fetch_assoc($run_products)) {
$pro_id = $row_products['product_id'];
$pro_title = $row_products['product_title'];
$pro_price = $row_products['product_price'];
$pro_img1 = $row_products['product_img1'];
echo "<div class='center-responsive col-md-3 col-sm-6'>
<div class='product same-height'>
<a href='details.php?pro_id=$pro_id'>
<img src='admin_area/product_images/$pro_img1' class='img-responsive'>
</a>
<div class='text'>
<h3><a href='details.php?pro_id=$pro_id'>$pro_title</a></h3>
<p class='price'>₹ $pro_price</p>
</div>
</div>
</div>";
}
?>
</div>
</div>
<div class="col-md-3">
<div class="box" id="order-summary">
<div class="box-header">
<h3>Order Summary</h3>
</div> <!--box-header ends-->
<p class="text-muted">
Shipping and additional costs are calulated based on the value you have entered.
</p>
<div class="table-responsive">
<table class="table">
<tbody>
<tr>
<td>Order Subtotal</td>
<th>₹<?php echo $sub_total; ?></th>
</tr>
<tr>
<td>Shipping and Handling</td>
<td>₹0.00</td>
</tr>
<tr>
<td>Tax</td>
<td>₹0.00</td>
</tr>
<tr class="total">
<td>Total</td>
<th>₹ <?php echo $total; ?></th>
</tr>
</tbody>
</table> <!--table ends-->
</div> <!---table responsive ends-->
</div> <!---box ends-->
</div> <!----col-md-3 ends--->
</div> <!--container ends-->
</div> <!---content ends-->
<?php include_once 'footer.php'; ?>
i get undefined variable sub_total even after defining variable subtotal above. Can someone figure out what the problem is?? I have check all curly brackets and semicolen. Due on a project that needs to be submited tomorrow. I am thinking improving the coding later but the basic functionality is not working.

What the error of update function?

I development admin control panel in my system when i update some thing in category the data not updated. what the error of my code? for more help you can download my files from here http://www.mediafire.com/download/m9psmr55pib5555/update_category.rar
<form action="categories.php" method="post">
<label>Edit category</label>
<?php
/*start of select data */
if(isset($_GET['edit_cat'])){
$cat_id = $_GET['edit_cat'];
$update_cat ="SELECT * FROM categories WHERE cat_id= $cat_id";
$run_cat_id = mysqli_query($connect , $update_cat);
while($row =mysqli_fetch_assoc($run_cat_id)){
$cat_id = $row['cat_id'];
$cat_title = $row['cat_name'];
?>
<div class="form-group">
<!--to pick the value -->
<input value="<?php if(isset($cat_title)){echo $cat_title;} ?>" type="text" class="form-control" name="cat_name">
</div>
<?php }}?>
<?php
if(isset($_POST['update'])){
$cat_update = $_POST['cat_name'];
$query ="UPDATE categories SET cat_name ='{$cat_update}' WHERE cat_id ={$cat_id}";
$update_query= mysqli_query($connect , $query);
<?php
ob_start();
include("includes/header.php");
include("includes/db.php");
?>
<div id="page-wrapper">
<div class="container-fluid">
<?php
if(isset($_GET['edit_cat'])){
$cat_id = $_GET['edit_cat'];
include ("includes/update_category.php");
}
?>
</div>
<!-- end of category form -->
</div>
<!--
===========================================================================================================
-->
<!-- start of table to show categories-->
<div class="col-lg-6">
<div class="btn btn-success"><h3>categories</h3></div>
<div class="table-responsive" >
<table class="table table-bordered table-hover">
<thead>
<tr>
<th width="10px">Id</th>
<th width="400px">category title</th>
</tr>
</thead>
<tbody>
<?php
/*Select from DB to show categories in table*/
$i=1;
$query = "SELECT *FROM categories";
$run_cat = mysqli_query($connect , $query);
while($row = mysqli_fetch_assoc($run_cat)){
$cat_id = $row['cat_id'];
$cat_name =$row ['cat_name'];
?>
<tr>
<td><?php echo $i++;?></td>
<td><?php echo $cat_name; ?></td>
<td><div class='btn btn-warning' name="edit_cat"><i class='fa fa-pencil-square-o fa-2'></i> Edit</div></td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<!-- end of table to show categories-->
<!-- =============================================================================
-->
</div>
</div>
</div>
</body>
</html>
if(!$update_query){
die("QUERY FAILED".mysqli_error($connect));
}
}
?>
<div class="form-group">
<input type="submit" name="update" value="submit" class="btn btn-success"/>
</div>
</form>

Display rating above Reviews

We are using following code for displaying review & ratings section. I want to display stars above "Title": This is really very good product
<?php $_items = $this->getReviewsCollection()->getItems();?>
<div class="box-collateral box-reviews" id="customer-reviews">
<?php if (count($_items)):?>
<div class="review-heading">
<h2>
<?php echo $this->__('') ?>
<span class="reviewtab">
<?php
// echo count($_items);
?>
Ratings & Reviews
</span>
</h2>
<?php echo $this->getChildHtml('toolbar') ?>
</div>
<dl>
<?php foreach ($_items as $_review):?>
<dt>
<a href="<?php echo $this->getReviewUrl($_review->getId()) ?>">
<?php echo $this->escapeHtml($_review->getTitle()) ?>
</a>
</dt>
<dd>
<?php $_votes = $_review->getRatingVotes(); ?>
<?php echo nl2br($this->escapeHtml($_review->getDetail())) ?>
<?php if (count($_votes)): ?>
<table class="ratings-table">
<colgroup>
<col class="review-label" />
<col class="review-value" />
</colgroup>
<tbody>
<?php foreach ($_votes as $_vote): ?>
<tr>
<th><?php echo $this->escapeHtml($_vote->getRatingCode()) ?></th>
<td>
<div class="rating-box">
<div class="rating" style="width:<?php echo $_vote->getPercent() ?>%;"></div>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<span class="review-meta">
<?php echo $this->__('Review by %s', $this->escapeHtml($_review->getNickname())) ?>
/
<?php echo $this->__('(Posted on %s)', $this->formatDate($_review->getCreatedAt()), 'long') ?>
</span>
</dd>
<?php endforeach; ?>
</dl>
<?php // echo $this->getChildHtml('toolbar') ?>
<?php elseif($this->getParentBlock()): ?>
<?php echo $this->getParentBlock()->getReviewsSummaryHtml($this->getProduct(), 'short', true)?>
<?php endif;?>
<?php echo $this->getChildHtml('review_form') ?>
</div>
When I tried with css, it didn't work for me.
I tried swapping code, but it didn't work for me either. Am I doing a mistake by swapping?
Please help me to find solution.
Thanks in advance
This should help, you might need to make minor css changes i think.
<?php $_items = $this->getReviewsCollection()->getItems();?>
<div class="box-collateral box-reviews" id="customer-reviews">
<?php if (count($_items)):?>
<div class="review-heading">
<h2>
<?php echo $this->__('') ?>
<span class="reviewtab">
<?php
// echo count($_items);
?>
Ratings & Reviews
</span>
</h2>
<?php echo $this->getChildHtml('toolbar') ?>
</div>
<dl>
<?php foreach ($_items as $_review):?>
<dt>
<?php $_votes = $_review->getRatingVotes(); ?>
<?php if (count($_votes)): ?>
<table class="ratings-table">
<colgroup>
<col class="review-label" />
<col class="review-value" />
</colgroup>
<tbody>
<?php foreach ($_votes as $_vote): ?>
<tr>
<th><?php echo $this->escapeHtml($_vote->getRatingCode()) ?></th>
<td>
<div class="rating-box">
<div class="rating" style="width:<?php echo $_vote->getPercent() ?>%;"></div>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php endif; ?>
<a href="<?php echo $this->getReviewUrl($_review->getId()) ?>">
<?php echo $this->escapeHtml($_review->getTitle()) ?>
</a>
</dt>
<dd>
<?php echo nl2br($this->escapeHtml($_review->getDetail())) ?>
<span class="review-meta">
<?php echo $this->__('Review by %s', $this->escapeHtml($_review->getNickname())) ?>
/
<?php echo $this->__('(Posted on %s)', $this->formatDate($_review->getCreatedAt()), 'long') ?>
</span>
</dd>
<?php endforeach; ?>
</dl>
<?php // echo $this->getChildHtml('toolbar') ?>
<?php elseif($this->getParentBlock()): ?>
<?php echo $this->getParentBlock()->getReviewsSummaryHtml($this->getProduct(), 'short', true)?>
<?php endif;?>
<?php echo $this->getChildHtml('review_form') ?>

Categories