Search query shows all results when clicking search button - php

I got a simple search query that works, but shows all results when the search button is clicked without a search input.
It also shows results with parent_id 26 or cattid 26 which I want to prevent in my query. Why is it still showing results with those id's and how can I prevent every result appearing on the result page when there is no search input?
How it is build:
HTML:
<li>
<div class="mn-wrap">
<form method="post" class="form" action="zoeken/">
<div class="search-wrap">
<button class="search-button animate" type="submit" title="Start zoeken">
<i class="fa fa-search"></i>
</button>
<input type="text" name="zoekterm" class="form-control search-field" placeholder="Zoek...">
</div>
</form>
</div>
</li>
.htaccess:
RewriteRule ^zoeken/ /zoeken.php?zoeken=1 [L]
Queries:
if ($_GET['zoeken'] != '') {
$zoekterm = $_POST['zoekterm'];
// zoeken
$zoeken = "SELECT * FROM `lb_content` WHERE catid NOT IN ('1', '26', '27', '28') and introtext LIKE '%".$conn->real_escape_string($zoekterm)."%' OR title LIKE '%".$conn->real_escape_string($zoekterm)."%'";
$zoekencon = $conn->query($zoeken);
$zoekeni = array();
while ($zoekeni[] = $zoekencon->fetch_array());
// zoeken c
$zoekc = "SELECT * FROM `lb_categories` WHERE parent_id NOT IN ('1', '26', '27', '28') and level = 2 and description LIKE '%".$conn->real_escape_string($zoekterm)."%' OR title LIKE '%".$conn->real_escape_string($zoekterm)."%'";
$zoekccon = $conn->query($zoekc);
$zoekci = array();
while ($zoekci[] = $zoekccon->fetch_array());
}
And finally the result page:
<div class="row multi-columns-row alt-features-grid">
<?
$aantal = count($zoekeni) + count($zoekci) - 2;
if($aantal == 0){
echo '<div class="col-sm-6 col-md-4 col-lg-4">
<div class="alt-features-item align-center">
<div class="alt-features-icon">
</div>
<h3 class="alt-features-title font-alt">Er zijn geen resultaten</h3>
</div>
</div>';
}
if($zoekeni[0]['id']){
foreach ($zoekeni as $resultaat) {
if($resultaat['introtext']){
echo '
<div class="col-sm-6 col-md-4 col-lg-4">
<div class="alt-features-item align-center">
<div class="alt-features-icon">
</div>
<h3 class="alt-features-title font-alt">'.$resultaat['title'].'</h3>
<div class="alt-features-descr align-left">
'.IntroText($resultaat['introtext']).'<br><br>
<div class="align-right">
Lees meer
</div>
</div>
</div>
</div>
';
}
}
}
if($zoekci[0]['id']){
foreach ($zoekci as $resultaat) {
if($resultaat['description']){
echo '
<div class="col-sm-6 col-md-4 col-lg-4">
<div class="alt-features-item align-center">
<div class="alt-features-icon">
</div>
<h3 class="alt-features-title font-alt">'.$resultaat['title'].'</h3>
<div class="alt-features-descr align-left">
'.IntroText($resultaat['description']).'<br><br>
<div class="align-right">
Lees meer
</div>
</div>
</div>
</div>
';
}
}
}
?>
</div>

Related

select dropdown value depending first dropdown value in codeigniter php

This is my view file here i use 5 search field like product, group, branch, startdate and end date. All are placed in different table. Both were worked nicely and searched nicely but now i want some additional option that is when i select a particular branch in group field dynamically show values based on branch field value. Now it is showing whole data in db.
NOTE: i want this change appear when dropdown select.
<div class="row">
<div class="col-md-12">
<div class="tab-content">
<form method="get" id="frmSearchGroupPur" action="<?php echo
base_url('admin/group/listgroup'); ?>">
<div class="form-body">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="col-md-5 control-label"
style="text-align: left">Product</label>
<div class="col-md-7">
<?php
$product = array();
// if($data['products']){
// foreach ($data['products'] as
$p)
{
// $product[$p['id']] =
$p['name'];
// }
// }
echo form_dropdown('product', $product,
$data['product'], array('class' => 'form-control
select2','id'=>'product'));
?>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="col-md-5 control-label"
style="text-align: left">Branch</label>
<div class="col-md-7">
<?php
$branch = array(NULL=>'Any');
if($data['branches']){
foreach ($data['branches'] as $w){
$branch[$w['id']] = $w['name'];
}
}
echo form_dropdown('branch', $branch,
$data['branch'], array('class' => 'form-control','id'=>'branch_dat'));
?>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="col-md-5 control-label"
style="text-align: left">Group</label>
<div class="col-md-7">
<?php
$group = array(NULL=>'Any');
if($data['groups']){
foreach ($data['groups'] as $g){
$group[$g->id] = $g->name;
}
}
echo form_dropdown('group', $group,
$data['group'], array('class' => 'form-control'));
?>
</div>
</div>
</div>
</div><br/>
<div class="row">
<div class="col-md-4">
<div class="form-group">
<label class="col-md-5 control-label"
style="text-align: left">Purchase Date From</label>
<div class='input-group date col-md-7'
id='datetimepicker6'>
<?php echo
form_input('fromdate',$data['fromdate'],array('class' => 'form-
control','id'=>'fromdate')); ?>
<span class="input-group-addon">
<span class="glyphicon glyphicon-
calendar"></span>
</span>
</div>
</div>
</div>
<div class="col-md-4">
<div class="form-group">
<label class="col-md-5 control-label"
style="text-align: left">Purchase Date To</label>
<div class='input-group date col-md-7'
id='datetimepicker7'>
<?php echo
form_input('todate',$data['todate'],array('class' => 'form-
control','id'=>'todate')); ?>
<span class="input-group-addon">
<span class="glyphicon glyphicon-
calendar"></span>
</span>
</div>
</div>
</div>
</div><br/>
<div class="row">
<div class="col-md-4">
<div class="form-group pull-center">
<button type="submit" id="btnFilter" class="btn
btn-info">Submit</button>
<a href="<?php echo
base_url('admin/group/listgroup'); ?>" class="btn btn-default">Reset</a>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
and my model file to get group is
function getGroupDetails($groupid=0,$state=''){
$this->db->where('id',$groupid);
$this->db->where('branchid',$state);
$query = $this->db->get('group');
if($query->num_rows()==1){
return $query->row_array();
}else{
return FALSE;
}
and my controller function is
function get_group(){
$state=$this->input->post('brch');
$result = $this->model_group->getGroupDetails($state);
// echo json_decode($result);
}
and my not worked jquery file to change group dynamically is below
$('branch_dat').change(function(){
var branch_da=$('#branch_dat').val();
if(branch_da != "")
{
var post_url="admin/sale/get_group";
$('branch_dat').change(function(){
var branch_da=$('#branch_dat').val();
if(branch_da != "")
{
var post_url="admin/sale/get_group";
$.ajax({
type:"POST",
url:post_url,
data:function(params)
{
return{ brch : params.brch};
}
});
}
});

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;

Grouping Bootstrap Cards

Im trying to add a group onto some bootstrap cards so that a the cards are displaying the data first and then the relevant cards after, e.g:
22 March 2018
1st-Card 2nd-Card
23 March 2018
1st-Card
At the moment I have this, but this displays all of my cards on a row:
<div class="card">
<div class="card-body">
<div class="card-header"><i class="material-icons floatleft">today</i><div floatleft>'.date("d/m/Y", strtotime($row['Date'])).'</div></div>
<h5 class="card-title">'.$row['Firstname'].' '.$row['Surname'].'</h5>
<p class="card-text">'.$row['Notes'].'</p>
</div>
<div class="card-footer">
<small class="text-muted">Added: '.date("d/m/Y", strtotime($row['timestamp'])).'</small>
</div>
</div>
</div>
Is their anyway to group by date?
This is my PHP for each row:
<?php
$no = 1;
$total = 0;
while ($row = mysqli_fetch_array($tablequery))
{
$amount = $row['LineRef'] == 0 ? '' :
number_format($row['LineRef']);
echo
' <div class="col-sm-3 OMHCardPadding">
<div class="card">
<div class="card-body">
<div class="card-header"><i class="material-icons floatleft">today</i>
<div floatleft>'.date("d/m/Y", strtotime($row['Date'])).'</div></div>
<h5 class="card-title OMHCardPadding">'.$row['Firstname'].' '.$row['Surname'].'</h5>
<p class="card-text OMHCardPadding">'.$row['Notes'].'</p> </div> <div class="card-footer">
<small class="text-muted">Added: '.date("d/m/Y",strtotime($row['timestamp'])).'</small>
</div>
</div>
</div>
';
$total += $row['LineRef'];
$no++;
}?>
My actual query is just a simple SELECT statement:
SELECT * FROM APPOINTMENTS

Specific column field Search implementation in Codeigniter

I have been having a bug in my code for the past weeks, I have tried all sorts of ways but can't get it to work, I am trying to implement a specific column field search functionality in codeigniter. Here is my scenario, a user lands on the age, and decides to search for a list of people, by name, member affiliation and location. here's my controller, model and view respectively...
model:
function get_advanced($address2,$partners,$typeofirm){
echo $address2,$partners,$typeofirm;
$query = "SELECT firm_id,address2,partners,typeofirm FROM auditfirms WHERE address2 LIKE '%$address2%' OR partners LIKE '%$partners%' OR typeofirm LIKE '%$typeofirm%' ORDER BY 'firm_id' LIMIT 10";
// return print_r(json_encode($query->result_array()));
$adv = $this->db->query($query)->result_array();
if ($query->num_rows() > 0){
$row = $query->row_array();
echo $query;
var_dump($adv); die();
return $adv;
}
else{
echo 'Error at syntax';
}
controller
function advanced(){
$this->load->library('pagination');
$config['base_url'] = 'http://localhost/icpak/index.php/firms/search';
$config['total_rows'] = $this->db->get('auditfirms')->num_rows();
$query1 = $config['per_page'] = 10;
$query2 = $config['uri_segment'] = 3;
$config['num_links'] = 5;
$config['full_tag_open'] = '';
$config['full_tag_close'] = '';
$config['cur_tag_open'] = '<span class="current_page">';
$config['cur_tag_close'] = '</span>';
$config['anchor_class'] = 'class="btn btn-default" ';
$this->pagination->initialize($config);
$address2 = $this->input->post('address2');
$partners = $this->input->post('partners');
$typeofirm = $this->input->post('typeofirm');
$data['advanced'] = $this->firms_model->get_advanced($address2,$partners,$typeofirm);
$this->load->view('index/advanced', $data);
}
view: is a modal window on which the form sits on...
<!--Modal-1-->
<div class="modal fade" id="myModal-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">X</button>
<h3 class="modal-title">Advanced Search</h3>
</div>
<div class="modal-body" style="padding:0px; margin:0 auto; ">
<div class="col-md-12" style="padding:30px !important; margin:0 auto;">
<!-- <form id="contactForm" class="contact"> -->
<?php echo form_open_multipart('firms/advanced', array('id' => 'contactForm', 'class' => 'contact'));?>
<div class="row">
<div class="form-group">
<label class="col-sm-4 control-label">Location</label>
<div class="col-sm-8">
<input class="form-control mb15" type="input" name="address2" placeholder="Search by Location" aria-controls="firms" />
</div>
</div><br><br>
</div>
<div class="row">
<div class="form-group">
<label class="col-sm-4 control-label">Members</label>
<div class="col-sm-8">
<input class="form-control mb15" type="input" name="partners" placeholder="Search by Member" aria-controls="firms" />
</div>
</div><br><br>
</div>
<div class="row">
<div class="form-group">
<label class="col-sm-4 control-label">Type of Firm</label>
<div class="col-sm-8">
<select class="form-control mb15" name="typeofirm" placeholder="Search by Type of Firm">
<option value="Auditing">Auditing</option>
<option value="NULL">Null</option>
</select>
</div>
</div><br><br>
</div>
<div class="row">
<div class="form-group">
<button class="btn btn-primary" id="submit">Submit</button>
<button type="reset" class="btn btn-reset">Reset</button>
</div>
</div>
<!-- </form> -->
<?php echo form_close();?>
</div>
</div> <!-- col-md-12 -->
</div> <!-- modal-body -->
</div> <!-- modal content -->
</div> <!-- modal-dialog -->
</div> <!-- modal fade -->
<!--End -Modal-1-->
Thank you in advance...
There is problem with your $query. Please see comment in code.
function get_advanced($address2,$partners,$typeofirm){
echo $address2,$partners,$typeofirm;
$query = "SELECT firm_id,address2,partners,typeofirm FROM auditfirms WHERE address2 LIKE '%$address2%' OR partners LIKE '%$partners%' OR typeofirm LIKE '%$typeofirm%' ORDER BY 'firm_id' LIMIT 10";
// return print_r(json_encode($query->result_array()));
$adv = $this->db->query($query)->result_array();
// $query is string.. so at this point you must get error.
// if ($query->num_rows() > 0){
if (count($adv) > 0){
// $row variable is unused. but it will give you first record.
$row = $adv[0];
return $adv;
}
else{
echo 'Error at syntax';
}
}

Double quotes inside html from no where displaying white space

it might be a stupid question but i struggle with finding the source of my problem.I have a white space from no where, pages are saved as utf-8 and my php/html adds some double quotes that generates me white space. If someone can help me with this i would be glad:)
Here is the img
The problem is between col-md-8 and cold-md-4.First function si the left content, second is the right side.
code: 1st function
function arata()
{
global $dbh;
echo'
<div class="container">
<div class="row">
<div class="col-md-8">
<div id="cale"> Acasă <img src="images/sageata.jpg"><span> Sesiuni de instruire </span> </div>
<div id="title_page"><h2>Sesiuni de instruire</h2></div>
<div id="continut">
<div class="box box-solid">
<div class="box-body">
<div class="box-group" id="accordion">
<!-- we are adding the .panel class so bootstrap.js collapse plugin detects it -->
';
$stmt = $dbh->prepare("SELECT * FROM Sesiune order by ID_Sesiune desc");
$stmt->execute();
while ($row = $stmt->fetch())
{
$id_sesiune=$row['ID_Sesiune'];
$titlu=$row['Titlu'];
$desc=$row['Descriere'];
echo' <div class="panel box box-primary">
<div class="box-header">
<h4 class="box-title">
<a data-toggle="collapse" data-parent="#accordion" href="#'.$id_sesiune.'">
'.$titlu.'
</a>
</h4>
</div>
<div id="'.$id_sesiune.'" class="panel-collapse collapse">
<div class="box-body">
'.$desc.'
</div>
</div>
</div>';
}
echo' </div>
</div><!-- /.box-body -->
</div><!-- /.box -->
</div></div>';
}
code: 2nd function
function Stiri()
{
global $dbh;
echo'
<div class="col-md-4">
<div id="inscrie"><button type="button" class="btn2 btn-primary2" data-toggle="button">Click aici pentru înscriere<span class="glyphicon glyphicon-chevron-right"></span></button></div>
<div id="search">
<div class="input-group">
<form method="GET" class="cauta" action="cautare.php">
<input type="text" class="form-control" name="cautare" placeholder="Caută în site ...">
<span class="input-group-btn">
<button class="btn btn-default" type="submit"><span class="glyphicon glyphicon-search"></span></button>
</span>
</form>
</div></div>
<div id="noutati">
<h2>Noutăţi</h2>
<ul>';
$stmt = $dbh->prepare("SELECT * FROM Noutati order by Data desc limit 7");
$stmt->execute();
while ($row = $stmt->fetch())
{
echo '<li>'.$row['Titlu'].'</li>';
}
echo'</ul>
<div id="toate"><button type="button" class="btn3 btn-primary3">Toate noutăţile</button></div>
</div>
</div>
</div>
</div>';
}
───→</div>↲
───→<div class="col-md-4">...
With ↲ being a new line, and ───→ being a tab. You have space! The "quotes" you see are the DOM inspector saying "here's a text node", they're not in the source. All that's in your source, is the whitespace that you put there.
Try:
</div><div class="col-md-4">...

Categories