Viewing Data From a Table To Modal Using PHP - php

I am using a table to retrieve all the data from the database and an array of view button on each table row. If the view button is clicked, a modal will appear displaying all the information of the particular row.
The problem is that the only id read is the last id. Giving the same view results for each table row.
I have this line of code in the view button:
< button class="btn btn-info" data-toggle="modal" data-target="#myModal-viewaccountinfo">View< / button>
While my modal code is this:
<div class="modal fade" id="myModal-viewaccountinfo" role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header">
<h3 class="modal-title"><center>USER ACCOUNT INFORMATION</center></h3>
</div>
<div class="modal-body">
<form method="post" action="">
<br>
<?php
$id = $_GET['txtid'];
include ("connect.php");
$i ="select * from usersvis where userid=".$id;
$h= mysql_query($i);
if($tr=mysql_fetch_array($h))
{
?>
<div class="row">
<div class="col-lg-4">
Name:
</div>
<div class="col-lg-6">
<label type="text"><?php echo $tr[3] . ' ' . $tr['4'] . ' ' . $tr['2']; ?></label>
</div>
</div>
<br>
<div class="row">
<div class="col-lg-4">
Username:
</div>
<div class="col-lg-6">
<label type="text"><?php echo $tr[5]; ?></label>
</div>
</div>
<br>
<div class="row">
<div class="col-lg-4">
Password:
</div>
<div class="col-lg-6">
<label type="text"><?php echo $tr[6]; ?></label>
</div>
</div>
<br>
<div class="row">
<div class="col-lg-4">
Gender:
</div>
<div class="col-lg-6">
<label type="text"><?php echo $tr[7]; ?></label>
</div>
</div>
<br>
<div class="row">
<div class="col-lg-4">
Birthdate:
</div>
<div class="col-lg-6">
<label type="text"><?php echo $tr[8] . '-' . $tr['9'] . '-' . $tr['10']; ?></label>
</div>
</div>
<br>
<div class="row">
<div class="col-lg-4">
Address:
</div>
<div class="col-lg-6">
<label type="text"><?php echo $tr[11]; ?></label>
</div>
</div>
<br>
<div class="row">
<div class="col-lg-4">
Status:
</div>
<div class="col-lg-6">
<label type="text"><?php echo $tr[12]; ?></label>
</div>
</div>
<br>
<div class="modal-footer">
<button type="button" class="btn btn-danger" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
<?php
}
?>

Related

Setting Categories using tabs with Laravel

I would like to ask how to pull categories using tabs. I was able to pull all the items on one tab but I could not pull them per category. here is my code. The data comes from the database and seems to work on All items but I could not figure out how to pull them individually. I need some help with you expertise.
<div class="tab-content">
<div class="tab-pane container active" id="home">...</div>
<div class="tab-pane container fade" id="allItems">All Items
<div>
<div class="row">
<div class="col-12">
<div class="row">
#foreach($items as $per_item)
<div class="col-lg-4 col-6">
<div class="card mb-3">
<img src="{{$per_item->image_path}}" class="card-img-top">
<div class="card-body">
<small>{{$per_item->category->name}}</small>
<h4 class="card-title">
<a href="/items/{{$per_item->id}}">
{{$per_item->name}}
</a>
</h4>
<p class="card-text">{{$per_item->description}}</p>
<h3>{{$per_item->price}}</h3>
<form action="/cart/{{$per_item->id}}" method="POST">
#csrf
<div class="row">
<div class="col-12 col-md-5 col-lg-12 mb-2">
<input type="number" name="quantity" id="quantity"
class="w-100">
</div>
<div class="col-12 col-md-7 col-lg-12 mb-2">
<button type="submit" class="btn btn-primary">Add To
Cart</button>
</div>
</div>
</form>
</div>
</div>
</div>
#endforeach
</div>
</div>
</div>
</div>
</div>
<div class="tab-pane container fade" id="consumables">Consumables
<div>
</div>
</div>
<div class="tab-pvane container fade" id="pnuematicTools">Pnuematic
Tools</div>

Text from database overflow bootstrap container

I'm trying to get a text from the database but it overflows it's container. I tried putting a lot of lorem ipsum in the original code without the database info and it works fine.
This is what happen when I get the info directly from the database:
And this is a native lorem ipsum in the html file:
This is my html code:
<div class="col-md-8">
<div class="row">
<?php
$query = $mysqli->query("SELECT id,title,preview,author,timepost FROM news ORDER BY timepost DESC LIMIT 3");
$i = 1;
while($array = $query->fetch_array())
{
$date = DateTime::createFromFormat("Y-m-d H:i:s",$array['timepost']); ?>
<div class="col-md-12 mb-3" style="cursor: default;" id="<?php echo 'newsJunebia' . $i; $i++; ?>">
<div class="row">
<div class="col-md-12 bg-negro text-white rounded-top">
<strong><?= $array['title']; ?></strong>
</div>
</div>
<div class="row">
<div class="col-md-8 bg-negro-opacity text-naranja">
<small><em>Publicado el <?=$date->format('d');?> de <?= $date->format('F') ?>o del <?= $date->format('Y'); ?> a las <?= $date->format('H:i') ?></em></small>
</div>
<div class="col-md-4 bg-negro-opacity text-naranja d-flex flex-row-reverse">
<small><em>Autor: <?= $array['author']; ?></em></small>
</div>
</div>
<div class="row">
<div class="col-md-12 bg-negro-opacity text-white">
<p><?php echo $array['preview']; ?></p>
</div>
</div>
<div class="row">
<div class="col-md-12 bg-negro-opacity text-naranja rounded-bottom text-center">
<span style="cursor: pointer;" class="font-weight-bold font-italic text-naranja plusNews">Ver la noticia completa</span>
</div>
</div>
</div>
<?php } ?>
This is the form from where I save this info:
<div class="row">
<div class="col-md-12 mt-4">
<div class="card">
<div class="card-header bg-negro text-white">
<h5 class="card-title text-center">Agregar noticia</h5>
</div>
<form class="form" role="form" method="POST" id="form-news">
<input type="hidden" name="dblanguage" value="es_LA">
<div class="card-body bg-gris text-naranja font-weight-bold">
<div class="form-group">
<label for="newsType">Categoría de la noticia</label>
<select class="custom-select" id="newsType" name="newsType" disabled>
<option>Noticia Junebia</option>
</select>
</div>
<div class="form-group">
<label for="newsTitle">Título de la noticia (<span id="maxCharTitle">60</span> caracteres restantes)</label>
<input type="text" name="newsTitle" id="newsTitle" class="form-control" maxlength="60">
</div>
<div class="form-group">
<label for="newsPreview">Texto de vista previa (<span id="maxChar">120</span> caracteres restantes)</label>
<textarea type="text" name="newsPreview" id="newsPreview" class="form-control" maxlength="100"></textarea>
</div>
<div class="form-group">
<label for="newsContent">Contenido de la noticia</label>
<textarea id="newsContent" name="newsContent" class="form-control"></textarea>
</div>
<input type="hidden" name="username" value="<?= $_SESSION['userName'] ?>">
</div>
<div class="container-fluid justify-content-center d-flex bg-gris">
<button type="submit" class="btn btn-naranja btn-lg mb-2" id="btnAgregar">Agregar</button>
</div>
</form>
</div>
</div>
This is my php file to handle that form:
require_once('../database.php');
if(!isBanned() && isAdmin())
{
if(isset($_POST['newsTitle']))
{
$newsTitle = $_POST['newsTitle'];
$newsPreview = $_POST['newsPreview'];
$newsContent = $_POST['newsContent'];
$newsAuthor = $_POST['username'];
$newsTime = date('Y-m-d H:i:s');
$stmt = $mysqli->prepare("INSERT INTO news(title,preview,content,author,timepost) VALUES(?,?,?,?,?)");
$stmt->bind_param('sssss',$newsTitle,$newsPreview,$newsContent,$newsAuthor,$newsTime);
$stmt->execute();
echo true;
}
else
{
echo false;
}
}
else
{
echo false;
}
I'm using bootstrap 4.1
You just need a space and everything will be fine.
But if your text is looks like as you fetch. You can just try the following css with parent div of text:
word-break: break-all;

What is the master rules of grape html element by find method of simple dome parse

I am using simple_html_dome and I want to grab experience, education, and title.
By my code, I am getting (Call to a member function find() on null in ) error message but title is showing error is ($notrmjobs = $item->find('div[class=norm-jobs-wrapper]',0);) here.
What is the core rules to catch HTML tag by find method?
<div class="boxed">
<div class="row">
<div class="col-md-12">
<div class="norm-jobs-wrapper" onclick="DivOpen('id=734675&fcatId=1&ln=1');">
<div class="row">
<div class="col-sm-3 col-sm-push-3">
<!--<div class="row">
<div class="col-sm-12">
<div class="comp_logo"><img src="images/38951.jpg" alt=""></div>
</div>
</div>-->
</div>
<div class="col-sm-9 col-sm-pull-9">
<div class="row">
<div class="col-sm-12">
<div class="comp-name-text">GBA Techno Pvt. Ltd.</div>
</div>
<div class="col-sm-12">
<div class="job-title-text">
<a onclick="clickJObTitle()" target="_blank" href="jobdetails.asp?id=734675&fcatId=1&ln=1">
Sr. Executive, Accounts
</a>
</div>
</div>
<div class="col-sm-12">
<div class="edu-text">
<div class="row">
<div class="col-sm-2">
<div class="edu-text-s">
Education:
</div>
</div>
<div class="col-sm-10">
<div class="edu-text-d">
Masters/ MBA in Accounts or Finance from any reputed university
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-12">
<div class="row">
<div class="col-sm-9">
<div class="exp-text">
<div class="row">
<div class="col-sm-2">
<div class="exp-text-s">Experience:</div>
</div>
<div class="col-sm-10">
<div class="exp-text-d">
At least 3 year(s)
</div>
</div>
</div>
</div>
</div>
<div class="col-sm-3">
<div class="dead-text">
<div class="dead-text-s">Deadline: </div>
<div class="dead-text-d">
<strong>Dec 13, </strong>2017
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
include 'simple_html_dom.php';
$html = file_get_html('http://jobs.bdjobs.com/jobsearch.asp?fcatId=1&icatId=');
$boxed = $html->find('div[class=boxed]',0);
$raw = $boxed->find('div[class=row]');
foreach($raw as $key => $loop){
$item = $loop->find('div[class=col-md-12]',0);
$notrmjobs = $item->find('div[class=norm-jobs-wrapper]',0);
$raw = $notrmjobs->find('div[class=row]',0);
$sdivice = $raw->find('div[class=col-sm-9 col-sm-pull-9]',0);
$sraw = $sdivice->find('div[class=row]',0);
$asraw = $sraw->find('div[class=col-sm-12]',0);
$title = $asraw->find('div[class=comp-name-text]',0)->plaintext;
echo $title;
}
?>

Can't open Bootstrap modal in codeigniter

I can't open my modal in CodeIgniter.
I did a view for the modal and then I loaded in the controller. But when I click on the button, it doesn't show anything. No response. head have the Jquery and Bootstrap imports in the correct order.
Here i show you my code:
cdashboard.php:
//header
$this->load->view('UI/vheader');
//sidebar
$this->load->view('UI/vsidebar',$data);
//modals
$data['modaltarea'] = $this->load->view('tareas/vmodalnewtarea',NULL,TRUE);
//data in dashboard
$this->load->view('vdashboard',$data);
//footer
$this->load->view('UI/vfooter');
vmodalnewtarea.php:
<div id="newTareaModal" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="newTarea" aria-hidden="true">
<div class="modal-dialog" >
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Tarea nueva</h5>
</div>
<div class="modal-body">
<div class="container-fluid">
<!--Importar plantilla-->
<div class="row">
<div class="col-md-12">
<h3>Importar plantilla</h3>
</div>
<div class="row">
<!--Proyecto-->
<div class="col-md-4">
</div>
<!--Fase-->
<div class="col-md-4">
</div>
<!--Tarea-->
<div class="col-md-4">
</div>
</div>
</div>
<!--Nueva Fase-->
<div class="row">
<div class="col-md-12">
<h3>Nueva Tarea</h3>
</div>
<div class="row">
<div class="col-md-4">
<div class="row">
<input type="text" placeholder="Nombre" required />
</div>
<div class="row">
<!--<table id="tableHitos" class="table table-bordered table-strip" >
<thead>
<th>
Hitos
</th>
</thead>
<tbody>
</tbody>
</table>-->
<a type="button" class="btn"><i class="fa fa-plus"></i></a>
</div>
</div>
<div class="col-md-8">
<textarea id="txtaTarea" rows="5" placeholder="Descripcion" required>
</textarea>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<p>
aaaaaa
</p>
</div>
</div>
</div>
</div>
And the view where I call the modal, on other view (vrowfase.php):
<div class="row fase">
<div class="col-lg-12">
<div class="col-lg-2 text-center">
<div class="callout callout-warning">
<h4><?= $fase->nombre?></h4>
<div class="progress progress-xxs">
<div class="progress-bar" role="progressbar" style="width: 50%">
</div>
</div>
</div>
</div>
<div class="projectBar col-lg-10">
<div class="row Bar">
<?= $tareas; ?>
<button type="button" class="btn btn-app text-center" data-toogle="modal" data-target="#newTareaModal">
<i class="fa fa-plus"></i>
Nueva Tarea
</button>
</div>
</div>
</div>
</div>
thanks for the help!
your modal id is
newTareaModal
and your data-target in button is
TareaModal
was a error writing.
on vrowfase.php I had "data-toogle" and is "data-toggle"
thank you anyway!

Passing data from page to bootstrap modal using SQL & PHP

So as per title, im trying to pass show multiple data from database using sql on the bootstrap modal. The ID will be pass down from the link, how is it done? been finding multiple way but I still can't show the selected data;
So here is the trigger for the modal:
<?php while($row = mysqli_fetch_array($adm_query)){
$id = $row['admin_id']; ?>
<tr>
<td style="text-align:center"><?php echo $row['adm_name']; ?></td>
<td width="150" style="text-align:center"><?php echo $row['staff_no']; ?></td>
<td width="120" style="text-align:center"><?php echo $row['department']; ?></td>
<td width="138" style="text-align:center;">
<a data-toggle="modal" data-target="#myModal" data-id="<?php echo $row['admin_id']?>" class="btn btn-outline btn-info"><i class="fa fa-search-plus"></i></a>
</td>
<?php }?>
Then this is the modal content:
<!-- Modal -->
<div style="margin-top:5%;" class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<?php $sel_query=mysqli_query($conn, "select * from admin where admin_id='$idmodal'")or die(mysql_error($conn)); $selrow=mysqli_fetch_array($sel_query);?>
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<div class="panel panel-info" style="text-align:center;">
<div class="panel-heading">
<h4>Staff Details</h4>
</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label>Staff ID</label>
<p>
<?php echo $selrow[ 'staff_no']?>
</p>
</div>
<div class="form-group">
<label>Name</label>
<p>
<?php echo $selrow[ 'adm_name']?>
</p>
</div>
<div class="form-group">
<label>Services | Department</label>
<p>
<?php echo $selrow[ 'department']?>
</p>
</div>
</div>
<!-- /.col-lg-6 (nested) -->
<div class="col-lg-6">
<div class="form-group">
<label>Username</label>
<p>
<?php echo $selrow[ 'username']?>
</p>
</div>
<div class="form-group">
<label>Password</label>
<p>
<?php echo $selrow[ 'password']?>
</p>
</div>
<div class="form-group">
<label>Date</label>
<p>
<?php echo $selrow[ 'date_added']?>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
</div>
<!-- /.modal-content -->
</div>
The problem is nothing works, and i don't know where to start.
Appreciate for the help.
Create one class openModal in <a></a>. Use this class in <script></script> to get data-id
<?php while($row = mysqli_fetch_array($adm_query,MYSQLI_ASSOC)){
$id = $row['admin_id']; ?>
<tr>
<td style="text-align:center"><?php echo $row['adm_name']; ?></td>
<td width="150" style="text-align:center"><?php echo $row['staff_no']; ?></td>
<td width="120" style="text-align:center"><?php echo $row['department']; ?></td>
<td width="138" style="text-align:center;">
<a class="btn btn-outline btn-info openModal" data-toggle="modal" data-target="#myModal" data-id="<?php echo $row['admin_id']?>">
<i class="fa fa-search-plus"></i>
</a>
</td>
</tr>
<?php }?>
Place this code in the same page below.
<div style="margin-top:5%;" class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content"></div>
</div>
</div>
JS (data-id=.. is passed here.)
<script>
$('.openModal').click(function(){
var id = $(this).attr('data-id');
$.ajax({url:"ajax_modal.php?id="+id,cache:false,success:function(result){
$(".modal-content").html(result);
}});
});
</script>
ajax_modal.php (Create one page in same directory ajax_modal.php. If you are looking to change this page name. Change in <script></script> tag too. Both are related.)
<?php
// Get `id` from `<script></script>`
$id = $_GET['id'];
$sel_query=mysqli_query($conn, "select * from admin where admin_id='$id'") or die(mysql_error($conn));
$selrow=mysqli_fetch_array($sel_query,MYSQLI_ASSOC);
?>
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="myModalLabel">Modal title</h4>
</div>
<div class="modal-body">
<div class="panel panel-info" style="text-align:center;">
<div class="panel-heading">
<h4>Staff Details</h4>
</div>
<div class="panel-body">
<div class="row">
<div class="col-lg-6">
<div class="form-group">
<label>Staff ID</label>
<p>
<?php echo $selrow[ 'staff_no']?>
</p>
</div>
<div class="form-group">
<label>Name</label>
<p>
<?php echo $selrow[ 'adm_name']?>
</p>
</div>
<div class="form-group">
<label>Services | Department</label>
<p>
<?php echo $selrow[ 'department']?>
</p>
</div>
</div>
<!-- /.col-lg-6 (nested) -->
<div class="col-lg-6">
<div class="form-group">
<label>Username</label>
<p>
<?php echo $selrow[ 'username']?>
</p>
</div>
<div class="form-group">
<label>Password</label>
<p>
<?php echo $selrow[ 'password']?>
</p>
</div>
<div class="form-group">
<label>Date</label>
<p>
<?php echo $selrow[ 'date_added']?>
</p>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
</div>
For more info, click here
how-to-pass-current-row-value-in-modal
passing-data-via-modal-bootstrap-and-getting-php-variable
bootstrap-modal-and-passing-value
show-data-based-of-selected-id-on-modal-popup-window-after-click-a-button-php-my
Write below line in your code:-
$selrow=mysqli_fetch_assoc($sel_query);
OR
$selrow=mysqli_fetch_array($sel_query,MYSQLI_ASSOC);
instead of
$selrow=mysqli_fetch_array($sel_query);
Also it is bad practice to write query directly into modal.
You should use AJAX on click event. Also you should fill form data via jQuery OR javascript.

Categories