Posting array to arrays in PHP - php

I'm trying to post the implode data of multiple select html to database but it is dynamic.
Result will be like this:
data1|data2|data3 = from multiple select(already get)
how can I achieve this kind of result? It is separated with commas
data1|data2|data3, data1|data2|data3, data1|data2|data3
The separated data inside the commas come from another multiple select.
Here's my code
HTML
<div class="required field">
<label>Subjects:</label>
<select class="ui fluid search dropdown" name="pass_subj[]" multiple="">
<option value="">Subject</option>
<option value="data1">subject1</option>
<option value="data2">subject2</option>
<option value="data3">subject3</option>
<option value="data4">subject4</option>
<option value="data5">subject5</option>
</select>
</div>
<div class="two wide field" style="padding: 23px 0px 0px;">
<button class="passmore ui icon yellow button" type="button">
<i class="plus icon"></i>
</button>
</div>
php
$pass_subj = $_POST['pass_subj'];
$pass_subjs = implode("|", $pass_subj);

I solved my own problem: My current project was using fomantic-ui; on my previous attempt, I used multiple select via select tag, which gives combined array values. To fix this, I used a dropdown via a div tag:
<div class="required field">
<label>Subjects:</label>
<div class="ui multiple selection dropdown clearable">
<input name="pass_subj[]" type="hidden">
<i class="dropdown icon"></i>
<div class="default text">Subject</div>
<div class="menu">
<div class="item" data-value="AP">Araling Panlipunan</div>
<div class="item" data-value="ENG">English</div>
<div class="item" data-value="FIL">Filipino</div>
</div>
</div>
</div>
<div class="two wide field" style="padding: 23px 0px 0px;">
<button class="passmore ui icon yellow button" type="button"><i class="plus icon"></i></button>
</div>
My PHP:
$pass_subj = $_POST['pass_subj'];
$pass_subjs = implode('#',$pass_subj);
The result will be:
AP#AP,ENG#AP,ENG,FIL#AP,FIL,MATH,ENG#AP,FIL,ENG,MATH,SCI

Related

How to choose $this element in each container(jQuery)?

I have few containers with radio buttons. That containers have unique classes(var-wrapper-1,var-wrapper-2). I'm choosing by one radio element in different containers, but I can add 'selected' class only for one element in one container at one time. I need to choose by one radio element in each container and to add class for all selected elements in all containers. One size in size, one material from materials, and add for selected variant attr-selected css class Inside one container only one variant, but in each container has to be one selected variant. Is it possible to make it dynamic or only manually, using containers unique classes?
That's a code, which I use for only one variant in one container
jQuery('.attr-container label').click(function() {
jQuery('.attr-container label').removeClass('attr-selected');
jQuery(this).addClass('attr-selected');
});
<div class="var-wrapper-1">
<div class="label var-label">
<label for="pa_size">Size</label>
</div>
<div class="value var-value">
<div class="variation-radios">
<div class="attr-container">
<div class="radio-span" >
<input type="radio" id="attribute_pa_size-l" name="attribute_pa_size" value="s">
<label for="attribute_pa_size-l">L</label>
</div>
</div>
<div class="attr-container">
<div class="radio-span">
<input type="radio" id="attribute_pa_size-m" name="attribute_pa_size" value="m">
<label for="attribute_pa_size-m">M</label>
</div>
</div>
</div>
</div>
</div>
<div class="var-wrapper-2">
<div class="label var-label">
<label for="pa_material">Material</label>
</div>
<div class="value var-value">
<div class="variation-radios">
<div class="attr-container">
<div class="radio-span" >
<input type="radio" id="attribute_pa_material-cotton" name="attribute_pa_material" value="cotton">
<label for="attribute_pa_material-cotton">Cotton</label>
</div>
</div>
<div class="attr-container">
<div class="radio-span" >
<input type="radio" id="attribute_pa_material-lace" name="attribute_pa_lace" value="lace">
<label for="attribute_pa_material-lace">Lace</label>
</div>
</div>
</div>
</div>
</div>
.attr-selected{
font-weight: 600;
border-bottom: 1px solid grey;
}
The code is still more complex than it needs to be, please reduce its size to a minimal example as #mplungjan suggested in their comment.
If what you're asking matches my guess, you need the css :checked pseudo class. Here is an article on this topic:
https://www.w3docs.com/snippets/css/how-to-style-the-selected-label-of-a-radio-button.html
input[type="radio"]:checked {
// something
}
input[type="radio"] {
// something else
}
No Javascript is needed here

Bootstrap modals not correctly hiding

First and foremost, the code is a mess because I had gotten some outside help from a person who did not take his coding seriously, right now I need to meet a deadline and am focusing on functionality, so I apologize beforehand, I'll get to cleaning it up in time.
We are creating a simple shopping page that includes PHP, bootstrap. We store the product information the in a mysqli database. We have multiple modals for each item where you can choose the size, and then add them to the cart.
The problem is that while the bootstrap modals cannot be seen, they are still "clickable" as if they were active when they are not. This does not apply to the cart modal, at least as far as I can tell.
I tried to fix this by changing the z index of the class of modals, however, that did not work.
the html (and PHP):
<section class="products">
<?php
$db = new Database();
$db->connect();
$db->select('tbl_items','productid,Product_Name,Product_Price,Product_Quantity,Category,Product_Picture',NULL,'Category!="Beverage" and Product_Quantity > 0','productid ASC'); // Table name, Column Names, JOIN, WHERE conditions, ORDER BY conditions
$res = $db->getResult();
$rows = array();
foreach ($res as $row)
{?>
<div class="product-card">
<form method="post" class="product-form card-form">
<div class="product-image">
<?php echo '<img class="gallery-pic responsive" src="data:image/jpeg;base64,'.base64_encode( $row['Product_Picture'] ).'"/>';?>
</div>
<div class="product-info-container">
<div class="product-info">
<h3 id="prod-name" class="prod-info"><?php echo $row['Product_Name']; ?><h3>
</div>
<div class="product-info">
<span class="prod-info">
<h4>R<?php echo $row['Product_Price']; ?></h4>
</span>
</div>
</div>
<div class="product-info add-btn-container">
<div class="customn-btn btn-lg btn-block add-cart-btn" title="Add to FOGo"
data-toggle="modal" data-target="#product<?php echo $row['productid'];?>modal"
onclick="resetSize()">
Add to cart<i class="fa fa-cart-plus" aria-hidden="true"></i>
</div>
</div>
</form>
</div>
I assign the product ID to the id of the modal to so that it can be referenced in the add to cart button above
Continue in the loop:
<div class="modal fade product-modal" id="product<?php echo $row['productid'];?>modal"
role="dialog">
<div class="modal-dialog">
<!-- Modal content-->
<div class="modal-content">
<div class="modal-header color-gradient">
<button type="button" title="Close Plate" class="close"
data-dismiss="modal">×</button>
<h4 id="item-title" class="modal-title"><?php echo $row['Product_Name'];?></h4>
</div>
<div class="display-pic-container">
<?php echo '<img class=" responsive" src="data:image/jpeg;base64,'.base64_encode( $row['Product_Picture'] ).'"/>';?>
</div>
<div class="modal-footer">
<div class="form-group">
<label class="size-lbl" for="size">Size</label>
<select class="form-control" name="size" onchange="changeSize(event)">
<option value="Small">Small</option>
<option value="Medium">Medium</option>
<option value="Large">Large</option>
</select>
</div>
<button type="button" title="Close Plate"
class="close-btn btn-lg btn-block cart-btn" id="close_cart"
data-dismiss="modal"><i class="fa fa-times" aria-hidden="true"></i>
Close</button>
<span onclick="addToCart(<?php echo $row['productid'];?>, event )"
title="Add to cart" class="btn-lg btn-block cart-btn check-out-btn"><i
class="fa fa-credit-card" aria-hidden="true"></i>
Add to cart</span>
</div>
</div>
</div>
</div>
<?php
}
?>
</section>

How to give icon filter for size and colours in php

I have developed a website which has filters for product sorting and filtration.
So it comes as rows of values with check boxes on it.
Here is an image of what it looks like now:
I want it to look as same as it is here (sample from flipkart).
Here is my code
So please let me know how can I make it to image icon
<section class="sky-form">
<span class="glyphicon glyphicon-minus colit" data-toggle="collapse" data-target="#neck"></span>
<b style="font-size:1em">Neck type</b>
<div class="row row1 scroll-pane collapse in" id="neck" style="width:100%">
<?php foreach($r5 as $k5 => $v5){ ?>
<div class="col col-4">
<label class="checkbox"><input type="checkbox" name="neck" value="<?php echo $r5[$k5]["data"];?>" <?php if(!empty($_SESSION['filarr'])){ if(in_array($r5[$k5]["data"] ,$_SESSION['filarr'])){ echo "checked";} } ?>><i></i><?php echo $r5[$k5]["data"]; ?></label>
</div>
<?php } ?>
</div>
</section>
<section class="sky-form">
<span class="glyphicon glyphicon-minus colit" data-toggle="collapse" data-target="#color"></span>
<b style="font-size:1em">Colour</b>
<div class="row row1 scroll-pane collapse in" id="color" style="width:100%">
<?php foreach($r6 as $k6 => $v6){ ?>
<div class="col col-4">
<label class="checkbox"><input type="checkbox" name="colour" value="<?php echo $r6[$k6]["data"];?>" <?php if(!empty($_SESSION['filarr'])){ if(in_array($r6[$k6]["data"] ,$_SESSION['filarr'])){ echo "checked";} } ?>><i></i><?php echo $r6[$k6]["data"];?></label>
</div>
<?php } ?>
</div>
</section>
Checkbox looks change depending on browser and OS used. There is't much you can do to change that. Only solution is to switch them with JavaScript checkboxes, something like http://icheck.fronteed.com/

use flags for country list call from SQL in php

i have a form for choose country that list call from sql
now how can put flags for all
<div class="col-xs-12 marpad">
<div class="labelsrch">Going from</div>
<div class="inputwrp mapmrkr">
<select class="custmselct padspl" name="nationality" required>
<option value="" selected="selected">Tell us where are you from</option>
<?php
foreach($country as $each_countries){
?>
<option value="<?=$each_countries->iso_code?>">
<?=$each_countries->country_name?>
</option>
<?php
}
?>
</select>
</div>
</div>
you can use flags and select box from Semantic-UI: http://semantic-ui.com/collections/form.html#form (see Country select box)
and change < i > class to the abbreviation country name for example "ir": < i class="ir flag">< /i>
you must get this name from Database
<div class="field">
<label>Country</label>
<div class="ui fluid search selection dropdown">
<input type="hidden" name="country">
<i class="dropdown icon"></i>
<div class="default text">Select Country</div>
<div class="menu">
<div class="item" data-value="af"><i class="af flag"></i>Afghanistan</div>
<div class="item" data-value="ax"><i class="ax flag"></i>Aland Islands</div>
<div class="item" data-value="al"><i class="al flag"></i>Albania</div>
<div class="item" data-value="dz"><i class="dz flag"></i>Algeria</div>
<div class="item" data-value="as"><i class="as flag"></i>American Samoa</div>
<div class="item" data-value="ad"><i class="ad flag"></i>Andorra</div>
<div class="item" data-value="ao"><i class="ao flag"></i>Angola</div>
<div class="item" data-value="ai"><i class="ai flag"></i>Anguilla</div>
</div>
</div>
</div>
</div>
If you don't want to use some existing codes for this as this one:
Flags
I would insert into database image name or link with country name and id. And with ajax on country name typing show the flag.

<select> not populating, buttons inline with <select>

I'm working with html, php and bootstrap to create some lists and buttons. My first questions is that I have written a script populate a "select" drop down list. It should go to the "sounds/" directory and populate itself with .wav files. The "select" shows up properly, it just doesn't populate the list. I do have .wav files in the directory and I gave full permissions to the directory itself. So its not that.
My other question is how would I put a button inline with the the "select" drop down. I don't want on the next line down.
<!--CALL TAB-->
<div id="call">
<div class="container">
<div class="hero-unit">
<h5>Call Functions -</h5>
<h6>Test Paragraph</h6>
<br>
<h6> Select a Sound One -</h6>
<div class="row">
<div class="span2">
<select id="sound1">
<?php
foreach(glob('sounds/*.wav') as $filename){
$rest = substr($filename, 7);
echo "<option>".$rest."</option>";
}
?>
</select>
</div>
</div>
<br>
<h6> Select a Sound Two -</h6>
<div class="row">
<div class="span2">
<select id="sound2">
<?php
foreach(glob('sounds/*.wav') as $filename){
$rest = substr($filename, 7);
echo "<option>".$rest."</option>";
}
?>
</select>
</div>
</div>
<br>
<h6>Volume - </h6>
<div id="slider-range-max">
</div>
<div class="row">
<div class="span6">
<br>
<p><a class="btn btn-large btn-primary" href="index.html">Play <i class="icon- play"></i></a> <a class="btn btn-large btn-danger" href="index.html">Pause <i class="icon-pause"></i></a>
</div>
</div>
</div>
<hr>
<footer>
<p>© FOOTER</p>
</footer>
</div>
</div>
Getting the button next to the select is simple. If you're not styling the select or button to be a block element, then they should appear next to each other (inline block). If the HTML below doesn't work for you (button is not next to select), then try adding float: left; to both the select and button.
For your glob(), are you sure the path is correct? Where is the PHP file that's executing this versus the sounds folder? What's your directory structure?
http://jsfiddle.net/3JQeZ/
<div class="row">
<div class="span2">
<select id="sound1">
<option>1 option</option>
<option>2</option>
<option>3</option>
</select>
<button>Button</button>
</div>
</div>

Categories