Join two tables by name for dropdown list - php

I have a script that is reading my wheel brands. If I select a wheel it show all the wheels from that brand...
But because I did GROUP BY merk_naam so in my dropdown there wont be 100 same brands I cant show them all...
Can somebody help me with the following:
I have two tables now:
Table 1: it_merken
Table 1
Table 2: it_merken2
Table 2
I want the merk_naam in a dropdown list
But when I do that I get a lot of double ones like AS 2 time in this example...
I want to JOIN in table 1 and table 2 the merk_naam in one query...
I cant figure out how...
Can somebody help me out?
This is the class I got now with the GROUP BY:
<?php
class merken extends connect
{
/**
* Merken lijst
*
* #param object
*/
private $merkenlijst;
/**
* Vraag merken op uit database
*
* #param int $id
* #return array
*/
public function getMerken($database, $id = NULL)
{
$sql = "SELECT merk_code, merk_logo, merk_naam, wiel_foto, wiel_nummer, wiel_info FROM ".$database."_merken";
if(!empty($id))
{
$sql .= " WHERE merk_code=:id";
}
else
{
$sql .= " GROUP BY merk_naam";
}
try
{
$stmt = $this->db->prepare($sql);
if(!empty($id)){ $stmt->bindParam(":id", $id, PDO::PARAM_STR); }
$stmt->execute();
$this->merkenlijst = $stmt->fetchAll(PDO::FETCH_OBJ);
$stmt->closeCursor();
return $this->merkenlijst;
}
catch (Exception $e)
{
die ( $e->getMessage() );
}
}
/**
* Maak een database object en sla de data op
*
* #param object $dbo
* #return void
*/
public function __construct($dbo = NULL)
{
/*
* Roep de parent constructor aan om te controleren op
* een database object
*/
parent::__construct($dbo);
}
}
?>
That is given me each brand one time in my dropdown but when I select nothing, I want to show all brands and because I use GROUP BY now I only see one wheel per brand after submit.
This is my PHP and HTML:
<div class="bandwielkolom">
<form name="wielenzoeken" action="index.php?lang=<?php echo $lang; ?>&p=<?php echo $_GET['p']; ?>#keuze" method="post">
<table class="wielentabel">
<tr>
<th colspan="2"><?php echo $searchwheelsbybrand; ?><a name="wiel"></a></th>
</tr>
<tr>
<td><?php echo $brand; ?>:</td>
<td>
<select name="wiel_merk" onchange="enable()">
<option value="0">- <?php echo $brand; ?> -</option>
<?php
$merken = $merkclass->getMerken($website, $merk);
foreach($merken as $merk)
{
echo "\t\t\t\t\t\t\t\t\t\t\t<option value=\"".$merk->merk_code."\"";
if(isset($_GET['search']) && $_GET['search'] == "wiel" && isset($_GET['merk']) && $_GET['merk'] != "0" || isset($_POST['wiel_submit']) && $_POST['wiel_merk'] != "0") { echo " selected=\"selected\""; }
echo ">".$merk->merk_naam."</option>\n";
}
?>
</select>
</td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="wiel_submit" value="<?php echo $search; ?>"/></td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"> </td>
</tr>
</table>
</form>
</div>
</div>
<div class="clearboth"></div>
<div id="main-right">
<?php
foreach($teksten as $tekst)
{
?>
<h1><strong><?php echo $tekst->tekst_header; ?></strong></h1>
<?php echo $tekst->tekst_content."\n"; ?>
<?php
if(!empty($tekst->tekst_img))
{
?>
<div class="imgcontainer">
<div class="imgcontent">
<img src="<?php echo $tekst->tekst_img; ?>" class="content_image" alt="<?php echo $tekst->tekst_header; ?>" />
</div>
</div>
<?php
}
?>
<?php
}
?>
</div>
</div>
<div class="clearboth"></div>
<div id="main-left">
<ul class="wheels">
<?php
if(isset($_POST['wiel_submit']) && $_POST['wiel_submit'] == $search || isset($_GET['merk']))
{
$merk = NULL;
if(isset($_POST['wiel_submit']) && $_POST['wiel_submit'] == $search)
{
echo "\t\t\t\t\t<h2>".$brandselection."</h2>
\t\t\t\t\t<br />\n";
$merk = $_POST['wiel_merk'];
}
?>
<?php
$merken = $merkclass->getMerken($website, $merk);
foreach($merken as $merk)
{
?>
<li><span class="title"><?php echo $merk->wiel_info; ?></span>
<a href="http://www.website.nl/website/images/w3/<?php echo $merk->wiel_foto; ?>" class="preview" title="Fotonummer: <?php echo $merk->wiel_foto; ?>">
<img src="http://www.website.nl/website/images/w3/<?php echo $merk->wiel_foto; ?>" alt="Fotonummer: <?php echo $merk->wiel_foto; ?>" class="wheelImg"/>
</a>
<span class="descr">
<img src="http://www.website.net/preview/bnet/logos/<?php echo str_replace(".png", "_100.png", $merk->merk_logo); ?>" style="padding-left:45px;" width="100" class="logo-merk" alt="<?php echo $merk->merk_naam; ?>"/>
</span>
</li>
<?php
}
?>
</ul>
<?php
}
?>
</div>
Any help is welcome because I can't figure it out!

You are getting doubles because some some of the fields in your SQL do not match, so you get a record for each.

Related

Why does the paging of a dataTable not work when filling the data again with Ajax?

I have a jQuery dataTable that depending on the option you select in a previous Select shows you some data or others. By default it shows those of the first option and so far everything is correct.
The problem comes when I select the second option, that the dataTable seems to be unconfigured and shows me all the results in a row without respecting the Paginate, also if I try to sort by name or another field it will show me the first option again. The same is also true if I try to change the table page.
I don't know where the error is.
I attach some images as a sample:
First option (everything works perfect): image
On select second option: image , image2
If i try to click on tabs 1 to 7 or p.ex. order the column
Universitatautomatically shows this (results of the first selector but without respecting the design of the table) image
First option selector code:
<div class="panel-body">
<div class="tab-content">
<div class="tab-pane fade in active no-info" id="tab1default">
<?php if($isAdmin){ ?>
<input type="hidden" id="niuProfessor" value="<?php echo $niu; ?>">
<div class="padding-bottom-20">
<select id="selectIfAdmin">
<option id="mineAdmin" value="mineAdmin">Les meves Universitats</option>
<option id="allAdmin" value="allAdmin">Totes les Universitats</option>
</select>
</div>
<!--<div id="showByGrau" class="padding-bottom-20" >
<select id="selectGrauAdmin">
<option value="-1">Tots els graus </option>
<?php foreach($degrees as $degree): ?>
<option value="<?php echo $degree->codiEstudis; ?>"><?php echo $degree->nomGrau; ?></option>
<?php endforeach; ?>
</select>
</div>-->
<?php } ?>
<div id="acordsTeacherAdmin" class="table-responsive">
<table class="table table-hover cell-border display compact" id="dev-table">
<thead>
<tr>
<th>Universitat</th>
<!-- <th>Grau</th>-->
<th>Places</th>
<th>Mesos</th>
<th>Període</th>
<!--<th>Assignatures</th>-->
<th><em class="fa fa-cog"></em></th>
</tr>
</thead>
<tbody id="taulaAcordsCoordinador">
<?php foreach ($agree as $ag): ?>
<tr >
<td><?php echo $ag->nomUniversitat; ?></td>
<!--<td><?php echo $ag->nomGrau; ?></td>-->
<td><?php echo $ag->plaçes; ?></td>
<td><?php echo $ag->mesos; ?></td>
<td><?php echo $ag->període; ?></td>
<!--<td align="center">
Opinar
</td>-->
<td align="center">
Publicar / Acord
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div class="modal fade" id="myModal" role="dialog">
<div class="modal-dialog">
</div>
</div>
<div id="debug">
</div>
</div>
</div>
Second option code (TaulaAcordsCoordinador.php):
<?php foreach ($agree as $ag): ?>
<tr >
<td><?php echo $ag->nomUniversitat; ?></td>
<td><?php echo $ag->plaçes; ?></td>
<td><?php echo $ag->mesos; ?></td>
<td><?php echo $ag->període; ?></td>
<!--<td align="center">
Opinar
</td>-->
<td align="center">
Publicar / Acord
</td>
</tr>
<?php endforeach; ?>
EventListener:
,$(document).on("change", "#selectIfAdmin", function(e){
e.preventDefault();
var data = {};
data.niu = $("#niuProfessor").val();
data.filtre = $(this).val();
filtrarAcordsAdmin(data);
})
Function with Ajax call:
function filtrarAcordsAdmin(data){
$.ajax({
type: "POST",
url: "perfil.php/" + "filtrarAcordsAdmin",
data: {"data":JSON.stringify(data)},
success: function(t, e, c) {
$("#taulaAcordsCoordinador").html(t);
/*if(data.filtre === "allAdmin"){$("#showByGrau").css('display','block');}
else{$("#showByGrau").css('display','none');}*/
},
error: function(t, e) {
}
})}
Perfi.php code:
case 'filtrarAcordsAdmin':
$actionName = "filtrarAcordsAdmin";
$data['data'] = $_POST['data'];
array_push($parameters,$data);
break;
filtrarAcordsAdmin controller:
public function filtrarAcordsAdmin($parameters){
$data = json_decode($parameters[0]['data']);
require_once 'models/TeachersModel.php';
require_once 'models/ConvenisModel.php';
$teachersModel = new TeachersModel();
$convenisModel = new ConvenisModel();
if($data->filtre == 'mineAdmin'){
$agree = $teachersModel->getAgreementsTeacher($data->niu);
}elseif ($data->filtre == 'allAdmin'){
$agree = $convenisModel->getConvenis();
}
$teachersModel->disconnect();
$convenisModel->disconnect();
$route = $this->view->show("TaulaAcordsCoordinador.php");
include($route);
}
Both functions getConvenis() and getAgreementsTeacher() are functions of a model that returns de result of a query into the BD like that:
public function getConvenis(){
try {
$consulta = $this->db->prepare('SELECT uni.nomUniversitat, uni.idUniversitat, es.nomGrau,co.codiConveni,co.codiCentreEstudis,ce.plaçes,ce.mesos,ce.període
FROM centreestudis ce, universitat_estudisuab un,universitats uni,estudisuab es,conveni co
WHERE ce.codiUniEstudis = un.codiUniEstudis
AND uni.idUniversitat = un.idUniversitat
AND un.codiEstudis = es.codiEstudis
AND co.codiCentreEstudis = ce.codiCentreEstudis
ORDER BY uni.nomUniversitat');
$consulta->execute();
$obj = $consulta->fetchAll(PDO::FETCH_OBJ);
} catch (Exception $e) {
}
return $obj;
}
public function getAgreementsTeacher($niu){
try {
$consulta = $this->db->prepare('SELECT ce.plaçes, ce.mesos, ce.període , un.nomUniversitat ,un.idUniversitat,co.codiConveni, eu.nomGrau
FROM professorscentre pr, centreestudis ce, universitat_estudisuab ue, estudisuab eu, universitats un, conveni co
WHERE pr.niuProfessor = ?
AND ce.codiCentreEstudis = pr.codiCentreEstudis
AND ue.codiEstudis = eu.codiEstudis
AND ce.codiUniEstudis = ue.codiUniEstudis
AND un.idUniversitat = ue.idUniversitat
AND co.codiCentreEstudis = ce.codiCentreEstudis
ORDER BY un.nomUniversitat');
$consulta->execute(array($niu));
$obj = $consulta->fetchAll(PDO::FETCH_OBJ);
return $obj;
} catch (Exception $e) {
}
}

Filter not filtering

I am trying to make a filter for website of cars. I would like to be able to filter by color of car represented by exterior. I do this by Select Distinct from exterior colors to list all of the exterior colors.
<h6 class="text-info">Select Color</h6>
<ul class="list-group">
<?php
$sql="SELECT DISTINCT exterior FROM newcars ORDER BY exterior";
$result=$conn->query($sql);
while($row=$result->fetch_assoc()) {
?>
<li class="list-group-item">
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" class="form-check-input product_check" name="" value="<?= $row['exterior']; ?>" id="exterior"><?= $row['exterior']; ?>
</label>
</div>
</li>
<?php
}
?>
</ul>
<div id="test">
<?php
$sql = "SELECT * FROM newcars";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
while ($row = mysqli_fetch_assoc($result)) {
echo ("<a href='newcarindex.php?id={$row['id']}'><div class='car'>");
echo '
<tr>
<td>
<img src="data:image\jpeg;base64,'.base64_encode($row['photo']).'"/>
</td>
</tr>
';
echo "<h2 class=car-name>";
echo $row['name'];
echo "</h2>";
echo "<span class=stock>STOCK#";
echo $row['stock'];
echo "</span>";
echo "<h3 class=car-msrp>";
echo $row['msrp'];
echo "</h3>";
echo "</div></a>";
}
} else {
echo "There are no Comments!";
}
?>
</div>
action.php this page i link to get the the results from what color they select. But I still cannot get it filter to the results.
include 'dbh.php';
if(isset($_POST['action'])) {
$sql = "SELECT * FROM newcars WHERE class !=''";
if(isset($_POST['class'])) {
$class = implode("','", $_POST['class']);
$sql .="AND class IN('".$class."')";
}
if(isset($_POST['body'])) {
$body = implode("','", $_POST['body']);
$sql .="AND class IN('".$body."')";
}
if(isset($_POST['exterior'])) {
$exterior = implode("','", $_POST['exterior']);
$sql .="AND class IN('".$exterior."')";
}
$result = $conn->query($sql);
$output='';
if($result->num_rows>0){
while($row=$result->fetch_assoc()){
$output .='<a href='newcarindex.php?id={$row['id']}'><div class='car'>
<tr>
<td>
<img src="data:image\jpeg;base64,'.base64_encode($row['photo']).'"/>
</td>
</tr>
<h2 class=car-name>'.$row['name'].'</h2>
<span class=stock>STOCK#'.$row['stock'].'</span>
<h3 class=car-msrp>'.$row['msrp'].'</h3>
</div></a>'
}
} else {
$output ="<h3>No Results</h3>";
}
echo $output;
}
?>
First of all you need to wrap your checkboxes in a HTML form that will send data to action.php file:
<h6 class="text-info">Select Color</h6>
<form action="action.php">
<ul class="list-group">
<?php
$sql = "SELECT DISTINCT exterior FROM newcars ORDER BY exterior";
$result = $conn->query($sql);
while($row=$result->fetch_assoc()) {
?>
<li class="list-group-item">
<div class="form-check">
<label class="form-check-label">
<input type="checkbox" class="form-check-input product_check" name="" value="<?= $row['exterior']; ?>" id="exterior"><?= $row['exterior']; ?>
</label>
</div>
</li>
<?php
}
?>
</ul>
<input type="submit" value="Filter" />
</form>
<div id="test">
...
Then, in action.php file you need to revise your SQL query. At this moment, when you concatenate base $sql variable with the one from if(isset($_POST['exterior'])) condition, the query looks like:
SELECT * FROM newcars WHERE class !=''AND class IN( ...
making it invalid (notice no space between !='' and AND).
Then the while loop has mixed apostrophes and quotation marks, which makes PHP code invalid. It should look like this:
while($row=$result->fetch_assoc()){
$photo = base64_encode($row['photo']);
$output .= "<a href='newcarindex.php?id={$row['id']}'>
<div class='car'>
<tr>
<td>
<img src='data:image\jpeg;base64,{$photo}'/>
</td>
</tr>
<h2 class='car-name'>{$row['name']}</h2>
<span class='stock'>STOCK#{$row['stock']}</span>
<h3 class='car-msrp'>{$row['msrp']}</h3>
</div></a>";
}

How to set a minimum order price within this code

Looking at a piece of code at the moment and trying to work out how to set a minimum order price of £10 within this code. I want the 'Confirm your order' CTA to be inactive unless the order is £10 - Or maybe upon selecting the CTA, no action, just a message to display saying the order should be £10 or over when the CTA is selected.
Any help would be great, I have a huge headache from this. I've been trying to learn to code but I am in way over my head with this one.
<?php
use mp_restaurant_menu\classes\models;
use mp_restaurant_menu\classes\View;
/**
* #return mixed
*/
function mprm_is_checkout() {
return models\Checkout::get_instance()->is_checkout();
}
/**
* #return mixed
*/
function mprm_get_checkout_uri() {
return models\Checkout::get_instance()->get_checkout_uri();
}
function mprm_get_checkout_cart_template() {
$data = array();
$data[ 'is_ajax_disabled' ] = models\Settings::get_instance()->is_ajax_disabled();
$data[ 'cart_items' ] = models\Cart::get_instance()->get_cart_contents();
mprm_get_template('shop/checkout-cart', $data);
}
/**
* #return mixed
*/
function mprm_checkout_button_next() {
$color = mprm_get_option('checkout_color', 'mprm-btn blue');
$color = ($color == 'inherit') ? '' : $color;
$padding = mprm_get_option('checkout_padding', 'mprm-inherit');
$style = mprm_get_option('button_style', 'button');
$purchase_page = mprm_get_option('purchase_page', '0');
ob_start();
?>
<input type="hidden" name="mprm_action" value="gateway_select"/>
<input type="hidden" name="page_id" value="<?php echo absint($purchase_page); ?>"/>
<input type="submit" name="gateway_submit" id="mprm_next_button" class="mprm-submit <?php echo $color; ?> <?php echo $padding; ?> <?php echo $style; ?>" value="<?php _e('Next', 'mp-restaurant-menu'); ?>"/>
<?php
return apply_filters('mprm_checkout_button_next', ob_get_clean());
}
/**
* Checkout purchase button
* #return mixed
*/
function mprm_checkout_button_purchase() {
$color = mprm_get_option('checkout_color', 'mprm-btn blue');
$color = ($color == 'inherit') ? '' : $color;
$style = mprm_get_option('button_style', 'button');
$label = mprm_get_option('checkout_label', '');
$padding = mprm_get_option('checkout_padding', 'mprm-inherit');
if (mprm_get_cart_total()) {
$complete_purchase = !empty($label) ? $label : __('Purchase', 'mp-restaurant-menu');
} else {
$complete_purchase = !empty($label) ? $label : __('Free Menu item', 'mp-restaurant-menu');
}
ob_start();
?>
<input type="submit" class="mprm-submit <?php echo $color; ?> <?php echo $padding; ?> <?php echo $style; ?>" id="mprm-purchase-button" name="mprm-purchase" value="<?php echo $complete_purchase; ?>"/>
<?php
return apply_filters('mprm_checkout_button_purchase', ob_get_clean());
}
/**
* #return bool
*/
function mprm_is_no_guest_checkout() {
return models\Misc::get_instance()->no_guest_checkout();
}
function mprm_checkout_tax_fields() {
if (models\Taxes::get_instance()->cart_needs_tax_address_fields() && mprm_get_cart_total()) {
mprm_default_cc_address_fields();
}
}
function mprm_checkout_submit() { ?>
<fieldset id="mprm_purchase_submit">
<?php do_action('mprm_purchase_form_before_submit'); ?>
<?php mprm_checkout_hidden_fields(); ?>
<?php echo mprm_checkout_button_purchase(); ?>
<?php do_action('mprm_purchase_form_after_submit'); ?>
</fieldset>
<?php
}
function mprm_checkout_additional_information() {
View::get_instance()->get_template('/shop/checkout-additional-information');
}
function mprm_checkout_final_total() {
?>
<p id="mprm_final_total_wrap">
<strong><?php _e('Total:', 'mp-restaurant-menu'); ?></strong>
<span class="mprm_cart_amount" data-subtotal="<?php echo mprm_get_cart_subtotal(); ?>" data-total="<?php echo mprm_get_cart_subtotal(); ?>"><?php echo mprm_currency_filter(mprm_format_amount(mprm_get_cart_total())); ?></span>
</p>
<?php
}
function mprm_checkout_hidden_fields() {
?>
<?php if (is_user_logged_in()) { ?>
<input type="hidden" name="mprm-user-id" value="<?php echo get_current_user_id(); ?>"/>
<?php } ?>
<input type="hidden" name="mprm_action" value="purchase"/>
<input type="hidden" name="controller" value="cart"/>
<input type="hidden" name="mprm-gateway" value="<?php echo models\Gateways::get_instance()->get_chosen_gateway(); ?>"/>
<?php
}
/**
* Delivery address default
*/
function mprm_checkout_delivery_address() {
if (mprm_get_option('shipping_address')): ?>
<p id="mprm-address-wrap">
<label for="shipping_address" class="mprm-label">
<?php _e('Shipping address:', 'mp-restaurant-menu'); ?>
</label>
<input type="text" name="shipping_address" value="" class="medium-text" placeholder="<?php _e('Enter your address.', 'mp-restaurant-menu'); ?>"/>
</p>
<?php endif;
}
/**
* Checkout order notes
*/
function mprm_checkout_order_note() {
?>
<p id="mprm-phone-number-wrap">
<label for="customer_note" class="mprm-label">
<?php _e('Order notes:', 'mp-restaurant-menu'); ?>
</label>
<textarea type="text" name="customer_note" id="customer_note" class="phone-number mprm-input"></textarea>
</p>
<?php }
/**
* Summary table
*/
function mprm_checkout_summary_table() { ?>
<span class="mprm-payment-details-label"><legend><?php _e('Order totals', 'mp-restaurant-menu'); ?></legend></span>
<table class="mprm-table">
<?php do_action('mprm_checkout_table_subtotal_before'); ?>
<tr>
<td class=""><span><?php _e('Subtotal', 'mp-restaurant-menu'); ?> </span></td>
<td><span class="mprm_cart_subtotal_amount"><?php echo mprm_currency_filter(mprm_format_amount(mprm_get_cart_subtotal())) ?></span></td>
</tr>
<?php do_action('mprm_checkout_table_subtotal_after'); ?>
<?php do_action('mprm_checkout_table_tax_before'); ?>
<?php if (mprm_use_taxes()) : ?>
<tr <?php if (!mprm_is_cart_taxed()) echo ' style="display:none;"'; ?>>
<td><span><?php _e('Tax', 'mp-restaurant-menu'); ?></span></td>
<td><span class="mprm_cart_tax_amount" data-tax="<?php echo mprm_get_cart_tax(); ?>"><?php echo mprm_currency_filter(mprm_format_amount(mprm_get_cart_tax())) ?></span></td>
</tr>
<?php endif; ?>
<?php do_action('mprm_checkout_table_tax_after'); ?>
<?php do_action('mprm_checkout_table_total_before'); ?>
<tr class="mprm-checkout-total">
<td>
<span><b><?php _e('Total', 'mp-restaurant-menu'); ?></b></span>
</td>
<td><span class="mprm_cart_amount"><b><?php echo mprm_currency_filter(mprm_format_amount(mprm_get_cart_total())) ?></b></span></td>
</tr>
<?php do_action('mprm_checkout_table_total_after'); ?>
</table>
<?php }
/**
* Send to success page
*
* #param string $query_string
*/
function mprm_send_to_success_page($query_string) {
return models\Checkout::get_instance()->send_to_success_page($query_string);
}
/**
* Send back to checkout
*
* #param $args
*/
function mprm_send_back_to_checkout($args) {
return models\Checkout::get_instance()->send_back_to_checkout($args);
}

Pagination in Codeigniter with sql and html table

I have a view containing a html table that display data retrieve from the database. Is it possible to go about doing a pagination for it?
Code for the view
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
</head>
<body>
<div class="row" ng-app="appcolor">
<div class="col-lg-12">
<!-- Section for tabs-->
<div class="tabbable">
<ul class="nav nav-tabs">
<li class="active">Home Banner</li>
</ul>
</div>
<!-- Section for tab content-->
<div class="tab-content">
<div class="tab-pane active" id="home_banner">
<fieldset>
<!-- Section for managing home banner -->
<legend>Manage Home Banner</legend>
<?php if($this->session->flashdata('notification')) {echo '<div class="alert alert-success">'.$this->session->flashdata('notification').'</div>'; } ?>
<?php if($banners != NULL) { ?>
<form action="<?php echo base_url().'backendBanner/update_banners'; ?>" method="POST">
<table style="" class="table table-striped">
<tr>
<th>Banner Image</th>
<th>Title</th>
<th>Description</th>
<th>Is Active</th>
<th>Seq Num</th>
<th>Viewed By</th>
<th>Link</th>
<th>Mobile Link</th>
<th>Delete</th>
</tr>
<?php } ?>
<?php foreach($banners as $banner) { ?>
<tr>
<input type="hidden" name="banner_path[]" value="<?php echo $banner['banner_path']; ?>">
<!-- Display the banner image -->
<td style="width:170px;"><?php echo "<img style='width:150px; height:100px'class='gc_thumbnail' src='".base_url()."../home_banner_images/".$banner['banner_path']."' style='padding:5px; border:1px solid #ddd'/>"; ?></td>
<!-- Display the banner title -->
<td style="width:170px;">
<input name="banner_title[]" type="text" value="<?php echo $banner['banner_title']; ?>" style="width:180px;">
</td>
<!-- Display the banner desc -->
<td style="width:170px;">
<input name="banner_desc[]" type="text" value="<?php echo $banner['banner_desc']; ?>" style="width:180px;">
</td>
<!-- Drop down list to select whether the banner is active -->
<td style="width:60px;">
<select name="is_active[]" style="width:60px;">
<?php
echo "<option value='0'"; if($banner['is_active'] == 0) {echo "selected";}; echo ">".'0'."</option>";
echo "<option value='1'"; if($banner['is_active'] == 1) {echo "selected";}; echo ">".'1'."</option>";
echo "</select>";
?>
</td>
<!-- Drop down list to select the sequence number -->
<td style="width:75px;">
<?php echo '<select name="seq[]" style="width:60px;">';
for($count =1 ; $count <= count($banners); $count ++)
{
echo "<option value='$count'"; if($banner['seq'] == $count) {echo "selected";}; echo ">".$count."</option>";
}
?>
</select>
</td>
<!-- Drop down list to select the banner can be view by which group of users-->
<td style="width:130px;">
<select name="viewed_by[]" style="width:120px;">
<?php
echo "<option value='members'"; if($banner['viewed_by'] == 'members') { echo "selected"; } echo ">".'Members'."</option>";
echo "<option value='non-members'"; if($banner['viewed_by'] == 'non-members') { echo "selected"; } echo ">".'Non-Members'."</option>";
echo "<option value='both'"; if($banner['viewed_by'] == 'both') { echo "selected"; } echo ">".'Both'."</option>";
echo "</select>"; ?>
</td>
<!-- Text field for user to input the banner url link -->
<td style="width:230px;">
<input name="url[]" type="text" value="<?php echo $banner['url']; ?>" style="width:180px;">
</td>
<!-- Text field for user to input the banner mobile url link -->
<td style="width:230px;">
<input name="murl[]" type="text" value="<?php echo $banner['murl']; ?>" style="width:180px;">
</td>
</tr>
<?php } ?>
<?php if($banners != NULL) { ?>
</table>
</fieldset>
</div>
</body>
</html>
Code for controller
class backendBanner extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->model('backend_banner_model');
$this->load->helper('url');
//$this->load->model('product_model');
}
public function index()
{
$this->landing_banners_upload();
}
function escapeQuote($var)
{
if (isset($var)){
$string = str_replace("'","''",$var);
}
return $string;
}
public function landing_banners_upload()
{
/*if ($this->session->userdata('admin_logged_in') == 1)
{*/
$config['allowed_types'] = 'gif|jpg|png';
$config['upload_path'] ='../home_banner_images';//This directory is under base url,
$config['overwrite'] = true;
$directory = '../home_banner_images/';
if (!file_exists($directory))
{
mkdir($directory, 0777, true);
}
$this->load->library('upload', $config);
if (!$this->upload->do_upload())
{
if($this->input->post('userfile'))
{
$data['error']= $this->upload->display_errors();
}
$data['banners'] = $this->backend_banner_model->get_landing_banners();
$this->load->view('layout/header');
$this->load->view('backendBanner/landing_banners_upload_view', $data);
$this->load->view('layout/footer');
}
else
{
$data['upload_data'] = $this->upload->data();
$file_name = $data['upload_data']['file_name'];
if(!$this->backend_banner_model->landing_banner_exist($file_name))
{
$this->backend_banner_model->insert_banner_image($this->upload->data());
}
redirect(base_url()."backendBanner/landing_banners_upload");
}
}}
Code for the model
class backend_banner_model extends CI_Model {
public function __construct ()
{
parent::__construct();
$this->db = $this->load->database('online', TRUE);
}
//Section for home banner (category)
/* Get the list of banner from the category of "home_banner */
public function get_landing_banners()
{
$this->db->select('*')->from('banner')->where('banner_category', 'home_banner');
$data = $this->db->get();
if ($data->num_rows() > 0) {
return $data->result_array();
}
}
}

Show song with typed letter

I'm making a search form with suggestions from database. All is going good but the problem is when I type "t" it shows the song with t likewise shows the song with s letter as well here is my code:
<?php
include('config.php');
if($_POST) {
$q = $_POST['searchword'];
$sql_res=mysql_query("select * from vass_songs");
while($row=mysql_fetch_array($sql_res)) {
$id=$row['id'];
$title=$row['title'];
$img=$row['img'];
$album_id=$row['album_id'];
$re_title='<b>'.$q.'</b>';
?>
<div class="suggestion_box" align="left">
<a href="/song/<?php echo $id; ?>">
<img src="/static/albums/<?php echo $id; ? >_small.jpg");">
</div><?php echo $title; ?><br/>
<span style="font-size:9px; color:#999999"><?php echo $country; ?></span>
</a>
</div>
<?php
}
} else {
}
?>
try this:
<?php
include('config.php');
if(isset($_POST['searchword'])) {
$q = $_POST['searchword'];
$sql_res=mysql_query("
SELECT *
FROM vass_songs
WHERE title LIKE '%$q%'
");
while($row=mysql_fetch_array($sql_res)) {
$id = $row['id'];
$title = $row['title'];
$img = $row['img'];
$album_id = $row['album_id'];
$re_title = "<b>{$q}</b>";
?>
<div class="suggestion_box" align="left">
<a href="/song/<?php echo $id; ?>">
<img src="/static/albums/<?php echo $id; ?>_small.jpg");">
<div><?php echo $title; ?></div><br/>
<span style="font-size:9px; color:#999999">
<?php echo $country; ?>
</span>
</a>
</div>
<?php
}
} else {
}
?>

Categories