open Collapse sidebar with same DB id - php

I'm currently working on the forum section of my website.
I followed the link #CBroe suggest me on the comments and implemented offcanvas for my previous problem and now I have this:
<table class="table is-indent changes" id="newsTable">
<thead>
<th></th>
<th></th>
</thead>
<tbody>
<?php foreach($fetchNews as $data):
echo '<tr class="trNew btnSelect" type="button" data-bs-toggle="offcanvas" data-bs-target="#offcanvasRight" aria-controls="offcanvasRight" id=\''.$data['id'].'\'>' ?>
<td class="cell-60 responsive-hide" style="width: 100px;">
<img class="author width" src="<?php echo '../../resource/img/users_Initials/' . $data['autore'].'.png' ?>">
</td>
<td id="<?php echo $data['id']; ?>">
<input type="hidden" id="idNew" value="<?php echo $data['id']; ?>" data-value="<?php echo $data['id']; ?>">
<div class="content">
<div class="title" id="title"> <?php echo $data['titolo']; ?> </div>
<div class="metas">
<span class="author"><?php echo $data['autore']; ?> - </span>
<span class="data"><?php echo $data['data']; ?></span>
</div>
</div>
<?php endforeach;?>
</td>
</tr>
</tbody>
</table>
And this is the offcanvas the table below open:
<!--PANEL NEWS-->
<?php foreach($fetchNews as $data):?>
<div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasRight" aria-labelledby="offcanvasRightLabel">
<div class="offcanvas-header">
<h1 id="newsTitolo"><?php echo $data['titolo']??''; ?></h1>
<button type="button" class="btn-close" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<div class="forum-header">
<img class="author width" src="<?php echo '../../resource/img/users_Initials/' . $data['autore'].'.png' ?>">
<span class="name"><?php echo $data['autore']??''; ?></span>
<span class="time"><?php echo $data['data']??''; ?></span>
</div>
<div class="forum-content">
<div id="newsTesto" class="articolo">
<?php $Parsedown = new Parsedown();
echo $Parsedown->text(file_get_contents('post/'.$data['titolo'].'/'.$data['titolo'].'.txt')??''); ?>
</div>
<p> <?php echo $data['allegato']??'';?></p>
</div>
</div>
</div>
<?php endforeach;?>
<!--END PANEL NEWS-->
What I basically need to do is display the article with the same ID as the title on the table as this example image: table & panel that by clicking on the first title (ahaaa) it opens the corresponding article.
I tried some stuff like adding $data['id'] on both data-bs-target and data-bs-toggle of the and as id of the offcanvas but it didnt work

Related

How do I echo a clickable URL in PHP?

How do I echo a clickable URL in PHP?
i want to makes this code as a clickable link, so i can click it, but i got no idea how to make it. Please help me if you know this case.
picture of the problem code
and these are my code :
<div class="container-fluid">
<div class="card">
<div class="card-header">Detail Shelter</div>
<div class="card-body">
<?php foreach($shelter as $slt): ?>
<div class="row">
<div class="col-md-4">
<img src="<?php echo base_url().'/upload/'.$slt->gambar ?>" class="card-img-top">
</div>
<div class="col-md-8">
<table class="table">
<tr>
<td>Nama Shelter</td>
<td><strong></strong><?php echo $slt->nama_shelter ?></td>
</tr>
<tr>
<td>Lokasi Shelter</td>
<td><strong></strong><?php echo $slt->lokasi_shelter?></td>
</tr>
<tr>
<td>Deskripsi</td>
<td><strong></strong><?php echo $slt->deskripsi ?></td>
</tr>
<tr>
<td>Telpon</td>
<td><strong></strong><?php echo $slt->no_telp ?></td>
</tr>
</table>
<?php echo anchor('dashboard/index',
'<div class="btn btn-sm btn-danger"> Kembali </div>') ?>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
</div>
To make a link clickable you need to use the tag see HERE
For example:
<tr>
<td>Lokasi Shelter</td>
<td><strong></strong>LINK TEXT</td>
</tr>
assuming the link you want is <?php echo $slt->lokasi_shelter?>
You just need to do this : click here

passing parameter to modal window with data-target is not working

I have designed one page consisting of one modal window which is opening with tag.
I want to pass some parameters to modal window which i will be using to populate table data based on the parameter value.It is working with one parameter but not working with another parameter.
Following is the HTML to open modal window......
<table id="MyTable1" class="table table-sm table-striped table-lightfont paginated">
<thead class="thead-light">
<tr>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","GRP_DESC"); ?></th>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MODULE_NAME"); ?></th>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","GMA_ACCESS_FLAG"); ?></th>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","OPTIONS"); ?></th>
</tr>
</thead>
<tbody>
<?php
if ($_SESSION['$language']="E") {
$groupdata=SelectData("group_module_access,user_group,modules","gma_id,gma_grp_id,grp_desc,gma_module_id,module_name,gma_access_flag","gma_grp_id=grp_id and gma_module_id=module_id","gma_grp_id,gma_id");
}
else {
$groupdata=SelectData("group_module_access,user_group,modules","gma_id,gma_grp_id,grp_bldesc as grp_desc,gma_module_id,module_blname as module_name,gma_access_flag","gma_grp_id=grp_id and gma_module_id=module_id","gma_grp_id,gma_id");
}
foreach ($groupdata as $groupdatalist) {
//$allids[]=$groupdatalist["gma_id"]; ?>
<tr>
<td><?php echo $groupdatalist["grp_desc"];?></td>
<td><?php echo $groupdatalist["module_name"];?></td>
<?php if($groupdatalist["gma_access_flag"]=="N"):?>
<td style="text-align:right;width:10px;"><input type="checkbox" name="accessflag[]" id="accessflag"
value="<?php echo "{$groupdatalist['gma_id']}"?>"/> </td>
<?php else:?>
<td style="text-align:right;width:10px;"><input type="checkbox" checked name="accessflag[]" id="accessflag" width="10px"
value="<?php echo "{$groupdatalist['gma_id']}"?>"/> </td>
<?php endif;?>
<td style="display:none;"><?php echo $groupdatalist["gma_grp_id"];?></td>
<td style="display:none;"><?php echo $groupdatalist["gma_module_id"];?></td>
<td style="display:none;"><input type="text" name="gmaid" id="gmaid" value="<?php echo $groupdatalist["gma_id"];?>"></td>
<!--<td style="display:none"><input type="text" name="allids[]" value="<//?php echo "{$groupdatalist['gma_id']}"?>"/></td>-->
<td>
<span data-toggle="modal" data-target="#myModal-<?php echo $groupdatalist['gma_id'];?>">
<a href="#" class="btn btn-light btn-sm shadow-none"
data-toggle="tooltip" title="<?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MENUPERMISSION");?>">
<i class="fa fa-pencil-square-o"></i>
</a>
</span>
</td>
</tr>
<?php } ?>
</tbody>
</table>
Here is the modal window HTML.....
<div id="myModal-<?php echo $groupdatalist['gma_grp_id'];?>" class="modal show fade" data-backdrop="static">
<div class="modal-dialog modal-dialog-centered">
<div class="modal-content">
<div class="modal-header">
<h6 class="modal-title">Menu List</h6>
</div>
<div class="modal-body">
<div class="control-container" style="padding:10px;">
<div class="row">
<div class="col-md-12" style="text-align:center">
<label style="color:red">
<?php //session_start();
if (!empty($_SESSION['$SaveMsg'])) { echo $_SESSION['$SaveMsg']; }
unset($_SESSION['$SaveMsg']);
?>
</label>
</div>
</div>
<div class="row">
<div class="col-md-4">
<label><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","GRP_DESC"); ?>
</label>
</div>
<div class="col-md-8">
<input class="text-control" type="text" name="grpid" id="grpid"
value="" readonly required maxlength="50" style="width:100%;display:none;" autofocus />
<input class="text-control" type="text" name="grpname" id="grpname"
value="" readonly required maxlength="50" style="width:100%" autofocus />
</div>
</div>
<div class="row">
<div class="col-md-4">
<label><?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MODULE_NAME"); ?>
</label>
</div>
<div class="col-md-8">
<input class="text-control" type="text" name="moduleid" id="moduleid"
value="" readonly required maxlength="50" style="width:100%;display:none" autofocus />
<input class="text-control" type="text" name="modulename" id="modulename"
value="" readonly required maxlength="50" style="width:100%" autofocus />
</div>
</div>
<?php $gmaid= "<script>document.writeln(gmaid);</script>";
echo $gmaid;?>
<!--table starts here -->
<table id="MyTable2" class="table table-sm table-striped table-lightfont paginated">
<thead class="thead-light">
<tr>
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MENUACCESS","MENUNAME"); ?></th>
<!--<th><//?php echo GetBilingualLabels($_SESSION['$language'],"MODULEACCESS","MODULE_NAME"); ?></th>-->
<th><?php echo GetBilingualLabels($_SESSION['$language'],"MENUACCESS","ACCESS_FLAG"); ?></th>
<!--<th><//?php echo GetBilingualLabels($_SESSION['$language'],"MENUACCESS","OPTIONS"); ?></th>-->
</tr>
</thead>
<tbody>
</table>
<!-- table ends here -->
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">
<i class="fa fa-close"></i>
<?php echo GetBilingualLabels($_SESSION['$language'],"BUTTON","CANCEL"); ?>
</button>
<button type="submit" name="updmenuperm" formnovalidate class="btn btn-primary"> <!--onclick="DispMsg(<//?php echo "'".$_SESSION['AlertMsg']."'";?>)"-->
<i class="fa fa-save"></i>
<?php echo GetBilingualLabels($_SESSION['$language'],"BUTTON","SAVE"); ?>
</button>
</div>
</div>
</div>
</div>
</div>
Above code is working perfectly but if i am using another value as parameter it is not opening the modal window at all.
for ex. if i am using $groupdatalist['gma_id'] which is integer value, it is not opening modal window.
Multiple issues here.
First a </div> is missing at the end.
Then you are defining $groupdatalist in a foreach, but trying to use it outside the loop:
<div id="myModal-<?php echo $groupdatalist['gma_grp_id'];?>" class="modal show fade" data-backdrop="static">
If you want one modal per <td> you have to move your modal into the foreach loop.
Finally, you call the modal using $groupdatalist['gma_id']
<span data-toggle="modal" data-target="#myModal-<?php echo $groupdatalist['gma_id'];?>">
but the modal ID is define using a different variable : $groupdatalist['gma_grp_id']:
<div id="myModal-<?php echo $groupdatalist['gma_grp_id'];?>"

How to initiate if else statement inside a td tag

In my database, I have a table column that has a filepath for images. The filepath's name is photo Some of my rows don't have a filepath. Inside my while loop forshowing the table, I would like to add a condition that if there is no filepath, it would prompt the text "User did not upload a photo yet." and when it has filepath, I can show the filepath and link it with a target blank.
This is my php file for it.
<?php require_once 'process.php';
session_start();
$role = $_SESSION['sess_userrole'];
$name = $_SESSION['sess_name'];
if(!isset($_SESSION['sess_username']) && $role!="admin"){
header('Location: index.php?err=2');
}
?>
<html>
<head>
<title>User Accounts</title>
<link rel="icon" href="isalonlogo.png">
<link rel="stylesheet" href="css2/bootstrap.min.css">
<script src="css/jquery-3.3.1.slim.min.js"></script>
<script src="css/popper.js/1.14.3/umd/popper.min.js"></script>
<script src="css/bootstrap.min.js"></script>
</head>
<body>
<?php
if (isset($_SESSION['message'])):?>
<div class="alert alert-<?=$_SESSION['msg_type']?>">
<?php
echo $_SESSION['message'];
unset ($_SESSION['message']);?>
</div>
<?php endif ?>
<div class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<span class="navbar-brand" href=""><?php echo " " . "$name"?>, here are the Stylist user lists.</span>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav navbar-right">
<li>User Lists</li>
<li><?php echo $_SESSION['sess_username'];?></li>
<li>Logout</li>
</ul>
</div>
</div>
</div>
<br> <br> <br>
<div class="container">
<?php
$mysqli = new mysqli("localhost","id7508046_root","123123123as","id7508046_isalon") or die(mysqli_error($mysqli));
$result = $mysqli->query("SELECT * FROM stylist ") or die($mysqli->error);
?>
<div class="row justify-content-center" width="80%">
<table class="table">
<thead>
<tr>
<th>UserName</th>
<th>Name</th>
<th>Image</th>
<th colspan="2">Action</th>
</tr>
</thead>
<?php
while($row = $result->fetch_assoc()): ?>
<tr>
<td><?php echo $row['username'] ?></td>
<td><?php echo $row['name'] ?></td>
// THIS PART HERE IS THE PROBLEM
<td><?php if(strcmp($row['photo'],"") == 0): {echo 'Ola';
}else:
{echo '<img src="'.$row['photo'].'">';
}
endif;
?></td>
<td>
<a href="userlist.php?edit=<?php echo $row['stylist_id']; ?>"
class="btn btn-info">Edit</a>
<a href="process.php?delete=<?php echo $row['stylist_id']; ?>"
class="btn btn-danger">Delete</a>
</td>
</tr>
<?php endwhile; ?>
</table>
</div>
<?php
function pre_r($array){
echo '<pre>';
print_r($array);
echo '</pre>';
}
?>
<br>
<br>
<div class="container justify-content-center">
<h5 class=" justify-content-center">Admin <?php echo $name;?>, create or edit an account here.</h5>
<form action="process.php" method="POST">
<input type="hidden" name="id" value="<?php echo $id; ?>">
<div class="form-group">
<label>UserName</label>
<input type="text" name="username" class="form-control" value="<?php echo $username;?>" placeholder="Enter new user Username" required>
</div>
<div class="form-group">
<label>Password</label>
<input type="text" name="password" class="form-control" value="<?php echo $password;?>" placeholder="Enter new user Password" required>
</div>
<div class="form-group">
<?php
if($update == TRUE): ?>
<button type="submit" class="btn btn-primary" name="update">Update</button>
<input type="button" class="btn btn-primary" name="reset" value="Reset" onclick="window.location.href='stylistUserlist.php'">
<?php
else: ?>
<button type="submit" class="btn btn-primary" name="save">Save</button>
<input type="button" class="btn btn-primary" name="reset" value="Reset" onclick="window.location.href='stylistUserlist.php'">
<?php
endif; ?>
</div>
</form>
</div>
</div>
</body>
Try
<td>
<?php if(!empty(trim($row['photo']))): ?>
<img src="<?php echo $row['photo'];?>"/>
<?php else: ?>
User did not upload a photo yet
<?php endif; ?>
</td>
Use below code for TD as you currently added same code in if and else both instead of using if else you can use the ternary operator.
<td>
<?php $photo = (isset($row['photo'])) ? $row['photo'] : "";
echo ($photo) ? "'. <img src=".$photo."> .'" : ""; ?>
</td>

cart button not working

Hi I have some more issues in my coding.when i have to changed my coding structure from div to table add to cart button not working.when it is working when it is in div but i have change to table cart button not working please help me to resolve my issue..
Code below is the old one (div) thats working fine here..
<?php if($microproduct['nr']){?>
<div class="product-box">
<div class="list" id="micropro">
<?php foreach ($microproduct['result'] as $resultmicroproduct){ ?>
<div class="row">
<div class="col-md-3">
<img src="images/feature-two-one.png" class="img-fluid mx-auto d-block">
</div>
<div class="col-md-7">
<div class="pro-desc">
<h5><?php echo $conn->stripval($resultmicroproduct['microsoft_product_legalname']);?></h5>
<p>Part number: <?php echo $conn->stripval($resultmicroproduct['microsoft_product_partnumber']);?></p>
<p>Item Name: <?php echo $conn->stripval($resultmicroproduct['microsoft_product_name']);?></p>
<p>Product family: <?php echo $conn->stripval($resultmicroproduct['microsoft_product_family']);?></p>
<h4><i class="fa fa-rupee"></i> <?php echo $conn->stripval($resultmicroproduct['microsoft_product_price']);?></h4>
</div>
</div>
<div class="col-md-2">
<div class="wrapper-div">
<input min="1" type="number" name="quantity<?php echo $resultmicroproduct['microsoft_product_id'] ?>" class="form-control" id="quantity" value="1" autocomplete="off">
<br>
<?php $postvalue = base64_encode(json_encode($resultmicroproduct)); ?>
<input type="hidden" name="type" value="microsoft_product">
<button class="btn btn-dark btn-sm add_to_cart" id="<?php echo $resultmicroproduct['microsoft_product_id'] ?>" >Add to Cart</button>
</div>
</div>
</div>
<?php } ?>
</div>
</div>
<?php } ?>
Code Below is the new one (table) cart button not working..
<table id="example" class="table table-striped table-bordered" style="width:100%">
<thead>
<tr>
<th>Image</th>
<th>Product Description</th>
<th>Quantity & Cart</th>
</tr>
</thead>
<?php if($microproduct['nr']){?>
<tbody>
<?php foreach ($microproduct['result'] as $resultmicroproduct){ ?>
<tr class="product-box">
<td><img src="images/feature-two-one.png" class="img-fluid mx-auto d-block"></td>
<td>
<div class="pro-desc">
<h5><?php echo $conn->stripval($resultmicroproduct['microsoft_product_legalname']);?></h5>
<p>Part number: <?php echo $conn->stripval($resultmicroproduct['microsoft_product_partnumber']);?></p>
<p>Item Name: <?php echo $conn->stripval($resultmicroproduct['microsoft_product_name']);?></p>
<p>Product family: <?php echo $conn->stripval($resultmicroproduct['microsoft_product_family']);?></p>
<h4><i class="fa fa-rupee"></i> <?php echo $conn->stripval($resultmicroproduct['microsoft_product_price']);?></h4>
</div>
</td>
<td>
<div class="wrapper-div">
<input min="1" type="number" name="quantity<?php echo $resultmicroproduct['microsoft_product_id'] ?>" class="form-control" id="quantity" value="1" autocomplete="off">
<br>
<input type="hidden" name="type" value="microsoft_product">
<button class="btn btn-dark btn-sm add_to_cart" id="<?php echo $resultmicroproduct['microsoft_product_id'] ?>">Add to Cart</button>
</div>
</td>
</tr>
<?php } ?>
</tbody>
<?php } ?>
<tfoot>
<th>Image</th>
<th>Product Description</th>
<th>Quantity & Cart</th>
</tfoot>
</table>
You don't even have a form.
<form action ="?" method="?">
//your inputs and submit
</form>
What do you expect to happen if you don't define what to do?

all subjects in same table in my sheetmark

What do I need to change from below code in order to get all the subjects in the same table?
<?php
include('grade.php');
$mysubject = $grade->getsubject();
?>
<p>This is a template for a simple marketing or informational website. It includes a large callout called a jumbotron and three supporting pieces of content. Use it as a starting point to create something more unique.</p>
<p><a class="btn btn-primary btn-lg" href="#" role="button">Learn more »</a></p>
</div>
</div>
<div class="container">
<!-- Example row of columns -->
<div class="row">
<?php foreach($mysubject as $row): ?>
<div class="col-lg-4 gradeform">
<div class="form_hover " style="background-color: #428BCA;">
<p style="text-align: center; margin-top: 20px;">
<i class="fa fa-bar-chart-o" style="font-size: 147px;color:#fff;"></i>
</p>
<div class="header">
<div class="blur"></div>
<div class="header-text">
<div class="panel panel-success" style="height: 247px;">
<div class="panel-heading">
<h3 style="color: #428BCA;">Subject: <?php echo $row['subject'];?></h3>
</div>
<div class="panel-body">
<table class="table table-bordered">
<tr class="alert alert-danger">
<th>TD</th>
<th>Exam</th>
<th>catching</th>
<th>average</th>
</tr>
<?php $mygrade = $grade- >getgrade($row['id']); ?>
<tr>
<td><?php echo $mygrade['att1']; ?></td>
<td><?php echo $mygrade['exam1']; ?></td>
<td><?php echo $mygrade['quiz1']; ?></td>
<td><?php echo $mygrade['project1']; ?></td>
</tr>
</table>
<div class="form-group">
<?php $teacher = $grade->getteacher($row['id']); ?>
<label>Teacher: <?php echo $teacher;?></label><br />
<label>Semester: <?php echo $row['sem']?> Sem</label><br />
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
i have every subject in différent table
The problem is, in each iteration of foreach loop you're creating a new table. If you want to display all the subjects under one table, just take the <table> outside of your foreach loop, like this:
// your code
<div class="container">
<!-- Example row of columns -->
<div class="row">
<div class="col-lg-4 gradeform">
<div class="form_hover " style="background-color: #428BCA;">
<p style="text-align: center; margin-top: 20px;">
<i class="fa fa-bar-chart-o" style="font-size: 147px;color:#fff;"></i>
</p>
<div class="header">
<div class="blur"></div>
<div class="header-text">
<div class="panel panel-success" style="height: 247px;">
<table class="table table-bordered">
<?php foreach($mysubject as $row): ?>
<div class="panel-heading">
<h3 style="color: #428BCA;">Subject: <?php echo $row['subject'];?></h3>
</div>
<div class="panel-body">
<tr class="alert alert-danger">
<th>TD</th>
<th>Exam</th>
<th>catching</th>
<th>average</th>
</tr>
<?php $mygrade = $grade- >getgrade($row['id']); ?>
<tr>
<td><?php echo $mygrade['att1']; ?></td>
<td><?php echo $mygrade['exam1']; ?></td>
<td><?php echo $mygrade['quiz1']; ?></td>
<td><?php echo $mygrade['project1']; ?></td>
</tr>
<div class="form-group">
<?php $teacher = $grade->getteacher($row['id']); ?>
<label>Teacher: <?php echo $teacher;?></label><br />
<label>Semester: <?php echo $row['sem']?> Sem</label><br />
</div>
<?php endforeach; ?>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</div>

Categories