this what i need make dynamicI am new to Laravel and need help in programming this checkbox in select dropdown.
my html form
<div class="container w60">
<div class="row pad_y_20">
<div class="col s12">
<h3 class="c_black center-align bold">Search for Our Products</h3>
</div>
<div class="input-field my_arrow col s12 m10 push-m1 l3" >
<select multiple>
<option value="" disabled selected>Properties</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
</div>
<div class="input-field my_arrow col s12 m10 push-m1 l3">
<select multiple>
<option value="" disabled selected>Target animals</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
</div>
<div class="input-field my_arrow col s12 m10 push-m1 l3">
<select multiple>
<option value="" disabled selected>Form</option>
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
</select>
</div>
<div class="col s12 m10 push-m1 l3">
Search
</div>
</div>
</div>
my database table
Thanks a lot for helping. I need php code or Laravel.
In your Controller, you can pass object to the blade template:
$products = Product::get();
return view('your.blade.view')->with([
'products' => $products
});
Then in your blade template file you can use them:
<select multiple name="property">
#foreach($products as $product)
<option value="{{ $product->id }}"> {{ $product->name }} </option>
#endforeach
</select>
This is an example, you need to tweak this code to satisfy your needs but it should be the right track to follow
This php code may help
<?php
//connect to your database here
require_once("../core/init.php");
//query database
$q_property = $db->query(("select properties from products2"));
$q_animal = $db->query(("select animal_id from products2"));
$q_form = $db->query(("select form from products2"));
?>
<div class="row pad_y_20">
<div class="col s12">
<h3 class="c_black center-align bold">Search for Our
Products</h3>
</div>
<div class="input-field my_arrow col s12 m10 push-m1 l3" >
<select multiple name="property">
<option value="" disabled selected>Properties</option>
<?php
//we loop over each property value and echo it to our select input
while($row = mysqli_fetch_row($q_property)){
$property = $row[0];
?>
<option value="<?= $property ?>"><?= $property ?></option>
<?php } ?>
</select>
</div>
<div class="input-field my_arrow col s12 m10 push-m1 l3">
<select multiple name="target_animal">
<option value="" disabled selected>Target animals</option>
<?php
//we loop over each animal_id value and echo it to our select input
while($row = mysqli_fetch_row($q_animal)){
$animal = $row[0];
?>
<option value="<?= $animal ?>"><?= $animal ?></option>
<?php } ?>
</select>
</div>
<div class="input-field my_arrow col s12 m10 push-m1 l3">
<select multiple name="form">
<option value="" disabled selected>Form</option>
<?php
//we loop over each form value and echo it to our select input
while($row = mysqli_fetch_row($q_form)){
$form = $row[0];
?>
<option value="<?= $form ?>"><?= $form ?></option>
<?php } ?>
</select>
</div>
<div class="col s12 m10 push-m1 l3">
<input type="submit" value="search"/a>
</div>
</div>
</div>
Check this image
Related
<div class="form-group row">
<label for="event_name" class="col-sm-2 col-md-1 col-form-label">Event Name</label>
<div class="col-sm-4 col-md-4">
<select class="form-control event" name='event_name' id='event_name'>
<option value="Option_1">Option 1</option>
<option value="Option_2">Option 2</option>
<option value="Option_3">Option 3</option>
<option value="Option_4">Option 4</option>
<option value="Option_5">Option 5</option>
</select>
</div>
</div>
<h4>{Event name}</h4>
my question is how to get {Event name} when i select any option?
You can do with easily with a session within a form. Just do something at the top like:
<?php
if (isset($_GET['form'])) {
$_SESSION['eName'] = $_GET['event_name'];
}
?>
<div class="form-group row">
<label for="event_name" class="col-sm-2 col-md-1 col-form-label">Event Name</label>
<div class="col-sm-4 col-md-4">
<form method="GET" action="">
<select class="form-control event" name='event_name' id='event_name'>
<option value="Option_1">Option 1</option>
<option value="Option_2">Option 2</option>
<option value="Option_3">Option 3</option>
<option value="Option_4">Option 4</option>
<option value="Option_5">Option 5</option>
</select>
<input type="submit" name="form">
</form>
</div>
</div>
<h4><?php if(isset($_SESSION['eName'])) { echo $_SESSION['eName']; }?></h4>
i got my answer and it's for without submitting value
<?PHP
$event_name = $_GET['event_name'];
?>
<script>
jQuery(function($){
$('#event_name').change(function(e){
let event_name = e.target.value;
window.location.href = `/wp-admin/admin.php?pageName&event_name=${event_name}`;
});
}
</script>
everyone! I am making a form consisting of fully drop down selectable menus where the user will populate the field. After pressing the submit form, I plan that information will be pulled from a database to display search results to the user. I am a little new to SQL and PHP, so any help would be appreciated! I attached the form and PHP code separately.
<form autocomplete="on" class="form-horizontal" action="" enctype="multipart/form-data" method="POST" name= "unit_assignments">
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="course_designation" class="col-lg-4 control-label">Course</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="course_designation" id="course_designation">
<option value="" selected disabled>Please Select</option>
<option value="_105">105</option>
<option value="_105i">105i</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="year" class="col-lg-4 control-label">Year</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="year" id="year">
<option value="" selected disabled>Please Select</option>
<option value="_2018">2018</option>
<option value="_2017">2017</option>
<option value="_2016">2016</option>
<option value="_2015">2015</option>
<option value="_2014">2014</option>
<option value="_2013">2013</option>
<option value="_2012">2012</option>
<option value="_2011">2011</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="semester" class="col-lg-4 control-label">Semester</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="semester" id="semester">
<option value="" selected disabled>Please Select</option>
<option value="fall">Fall</option>
<option value="spring">Spring</option>
<option value="summer">Summer</option>
<option value="maymester">Maymester</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="discipline" class="col-lg-4 control-label">Discipline</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="discipline" id="discipline">
<option value="" selected disabled>Please Select</option>
<option value="nat_sciences">Natural Sciences</option>
<option value="health_medicine">Health Medicine</option>
<option value="social_sciences">Social Sciences</option>
<option value="humanities">Humanities</option>
<option value="digital_humanities">Digital Humanities</option>
<option value="law">Law</option>
<option value="business">Business</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="digital_literacy" class="col-lg-4 control-label">Type</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="digital_literacy" id="digital_literacy">
<option value="" selected disabled>Please Select</option>
<option value="podcast">Podcast</option>
<option value="video">Video</option>
<option value="webpage">Webpage</option>
<option value="sparks">Sparks</option>
<option value="illustrator">Illustrator</option>
<option value="in_design">In Design</option>
<option value="canvas">Canvas</option>
<option value="pitochart">Pitochart</option>
<option value="power_point">Power Point</option>
<option value="spreadsheet">Spreadsheet</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="genre" class="col-lg-4 control-label">Genre</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="genre" id="genre">
<option value="" selected disabled>Please Select</option>
<option value="book_review">Book Review</option>
<option value="film_review">Film Review</option>
<option value="play_review">Play Review</option>
<option value="literature_review">Literature Review</option>
<option value="peer_reviewed_journal_articles">Peer Reviewed Journal Article</option>
<option value="conference_paper">Conference Paper</option>
<option value="conference_presentation">Conference Presentation</option>
<option value="grant_proposal">Grant Proposal</option>
</select>
</div>
</div>
</div>
</div>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<div class="form-group">
<label for="method" class="col-lg-4 control-label">Method</label>
<div class="col-lg-8">
<select type="hidden" class="form-control" name="method" id="method">
<option value="" selected disabled>Please Select</option>
<option value="archival_research">Archival Research</option>
<option value="textual_analysis">Textual Analysis</option>
<option value="rhetorical_analysis">Rhetorical Analysis</option>
<option value="reviewing_the_literature">Reviewing the Literature</option>
</select>
</div>
</div>
</div>
</div>
<center>
<div class="col-sm-4">
<h4></h4>
<div class="panel panel-default background-light padded">
<center>
<input class="btn btn-primary btn-block" type="submit" value="submit">
</center>
</div>
</div>
</center>
</form>
This is the PHP portion of the code. The page just keeps returning an empty number for conditions and only prints out "SELECT * FROM unit_assignments". It never ends up executing the rest of the code and I was wondering if it was because my PHP code is wrong or my form code. My page does connect to the database, so I don't think there are any database errors.I have tried varying methods of writing the PHP code but to no avail, which leaves me to believe maybe the PHP code and the form just aren't connecting.
<?php
// define the list of fields
$fields = array('course_designation', 'year', 'discipline', 'digital_literacy', 'genre', 'method');
$conditions = array();
// loop through the defined fields
foreach($fields as $field){
// if the field is set and not empty
if(!empty($_POST[$field])) {
// create a new condition while escaping the value inputed by the user (SQL Injection)
$conditions[] = "`$field` LIKE '%" . mysqli_real_escape_string($_POST[$field]) . "%'";
}
}
// }
// builds the query
$query = "SELECT * FROM unit_assignments ";
echo count($conditions);
// if there are conditions defined
if(count($conditions) > 0) {
// append the conditions
$query .= "WHERE " . implode (' AND ', $conditions); // you can change to 'OR', but I suggest to apply the filters cumulative
}
echo "$query";
$result = mysqli_query($mysqli_link, $query);
mysqli_close($mysqli_link);
if(isset($_POST['submit'])) {
while($row = mysqli_fetch_array($result)) {
$course_designation = $row['course_designation'];
$year = $row['year'];
$discipline = $row['discipline'];
$digital_literacy = $row['digital_literacy'];
$genre = $row['genre'];
$method = $row['method'];
echo "Course: $course_designation<br>Year: $year<br>Discipline: $discipline<br>digital_literacy: $digital_literacy<br>Genre: $genre<br>Method: $method<br>";
}
}
?>
3 dependent multi dropdown list same select name at the end of the select field each drop down. When i click portfolio level option based on the div display show one dependent dropdown list among three. When i click at showed dropdown list only posted to last selected value. In that i make every drop down list last select name same; i.e name=worklocation.
The html code below:
<form method="post" action="user-work.php" enctype="multipart/form-data">
<div class="form-group">
<select name="pfLevel" id="portfolio_levels" class="form-control">
<option value="">Select Portfolio Level</option>
</select>
</div>
<div style='display:none;' id='Countryshow' class="form-group">
<select name="workLocation[]" id="counrey7" class="form-control">
<option value="">Select Country</option>
</select>
</div>
<div style='display:none;' id='stateshow'>
<div class="form-group">
<select name="" id="country6" class="form-control">
<option value="">Select country</option>
</select>
</div>
<div class="form-group">
<select name="workLocation[]" id="state6" class="form-control">
<option value="">Select State</option>
</select>
</div>
</div>
<div style='display:none;' id='cityshow'>
<div class="form-group">
<select name="" id="country5" class="form-control">
<option value="">Select country</option>
</select>
</div>
<div class="form-group">
<select name="" id="state5" class="form-control">
<option value="">Select state</option>
</select>
</div>
<div class="form-group">
<select name="workLocation[]" id="city5" class="form-control">
<option value="">Select city</option>
</select>
</div>
</div>
<div class="col-xs-12"><div class="btn-group text-left">
<button class="btn btn-primary">Submit</button>
<button class="btn btn-secondry">Close</button>
</div></div>
</form>
php code
<?php
require 'inc/database.php';
if ( !empty($_POST)) {
$pfLevel=$_POST['pfLevel'];
$workLocation=$_POST['workLocation'];
$pdo = Database::connect();
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$sql = "INSERT INTO userworkinfo (intWorkLocation,userPfLevel) values(?,?)";
$q = $pdo->prepare($sql);
$q->execute(array($workLocation,$pfLevel));
Database::disconnect();
echo '<script>alert("working details posted successfully");</script>';
}
?>
Use select input name with index.
<select name="workLocation[0]" id="counrey7" class="form-control">
<option value="">Select Country</option>
</select>
<select name="workLocation[1]" id="state6" class="form-control">
<option value="">Select state</option>
</select>
<select name="workLocation[2]" id="city5" class="form-control">
<option value="">Select city</option>
</select>
I am trying to get the total amount for the a variety of tickets that are available. from the select box, the user can chose the number of tickets he wants. in the end, the total amount is getting displayed. My issue is, on changing the selection of number of tickets, it is getting added to the previous total. i want to deduct it, and then add the correct amount. i have this running code.
This is the html i have.
<form>
<div class="row">
<div class="col-xs-12 col-sm-4">
<label>OAP</label>
</div>
<div class="col-xs-12 col-sm-4">
<select class="venet-stock" data-price="20">
<option value="1">
1
</option>
<option value="2">
2
</option>
<option value="3">
3
</option>
<option value="4">
4
</option>
<option value="5">
5
</option>
<option value="6">
6
</option>
</select>
</div>
<div class="col-xs-12 col-sm-4">
<p class="number">
£<span>20</span>
</p>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-4">
<label>General</label>
</div>
<div class="col-xs-12 col-sm-4">
<select class="venet-stock" data-price="35">
<option value="1">
1
</option>
<option value="2">
2
</option>
<option value="3">
3
</option>
<option value="4">
4
</option>
<option value="5">
5
</option>
<option value="6">
6
</option>
</select>
</div>
<div class="col-xs-12 col-sm-4">
<p class="number">
£<span>35</span>
</p>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-4">
<label>Concession</label>
</div>
<div class="col-xs-12 col-sm-4">
<select class="venet-stock" data-price="50">
<option value="1">
1
</option>
<option value="2">
2
</option>
<option value="3">
3
</option>
<option value="4">
4
</option>
<option value="5">
5
</option>
<option value="6">
6
</option>
</select>
</div>
<div class="col-xs-12 col-sm-4">
<p class="number">
£<span>50</span>
</p>
</div>
</div>
<p class="push h20"></p>
<div class="row">
<div class="col-xs-12 col-sm-4">
<label>Total</label>
</div>
<div class="col-xs-12 col-sm-4">
<p class="total">
£<span id="price-total">50</span>
</p>
</div>
This is my Jquery code.
var price_total = 0;
jQuery( '.venet-stock' ).change(function() {
price = jQuery(this).attr('data-price');
guest = jQuery( this ).val();
price_total += guest*price;
jQuery( '#price-total').text( price_total );
});
Thanks in advance.
Working Fiddle https://jsfiddle.net/t3vs4dgx/
HTML Code. Add only a Zero option to every dropdown.
<form>
<div class="row">
<div class="col-xs-12 col-sm-4">
<label>OAP</label>
</div>
<div class="col-xs-12 col-sm-4">
<select class="venet-stock" data-price="20">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
<div class="col-xs-12 col-sm-4">
<p class="number">£<span>20</span></p>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-4">
<label>General</label>
</div>
<div class="col-xs-12 col-sm-4">
<select class="venet-stock" data-price="35">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
<div class="col-xs-12 col-sm-4">
<p class="number">£<span>35</span></p>
</div>
</div>
<div class="row">
<div class="col-xs-12 col-sm-4">
<label>Concession</label>
</div>
<div class="col-xs-12 col-sm-4">
<select class="venet-stock" data-price="50">
<option value="0">0</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</div>
<div class="col-xs-12 col-sm-4">
<p class="number">£<span>50</span></p>
</div>
</div>
<p class="push h20"></p>
<div class="row">
<div class="col-xs-12 col-sm-4">
<label>Total</label>
</div>
<div class="col-xs-12 col-sm-4">
<p class="total">£<span id="price-total">0</span></p>
</div>
</div>
</form>
JS Code. Going through all selections when one is changed and add price_total for this run
$( '.venet-stock' ).change(function() {
var price_total = 0;
$( '.venet-stock' ).each(function(i,e){
price = $(e).attr('data-price');
guest = $(e).val();
price_total += guest*price;
});
jQuery( '#price-total').text( price_total );
});
I want to display all the data from table in MySQL database when I choose 'any' option. I don't know how to do that. Please look at the code below.
<form method="post" action="listing_grid.php">
<div class="row">
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="formBlock select">
<label for="location">Property for: </label><br/>
<select name="property_for" id="beds" class="formDropdown">
<option value="Property for sale">Property for sale</option>
<option value="Property for rent">Property for rent</option>
</select>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="formBlock select">
<label for="propertyType">Property Type</label><br/>
<select name="property_type" id="propertyType" class="formDropdown">
<option value="any">Any</option>
<option value="Houses">Houses</option>
<option value="Apartments">Apartments</option>
<option value="Bungalows">Bungalows</option>
<option value="Land">Land</option>
<option value="Commercial property">Commercial property</option>
</select>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="formBlock">
<label for="price-min">Price Range</label><br/>
<div style="float:right; margin-top:-25px;">
<div class="priceInput"><input type="text" name="price_min" id="price-min" class="priceInput" /></div>
<span style="float:left; margin-right:10px; margin-left:10px;">-</span>
<div class="priceInput"><input type="text" name="price_max" id="price-max" class="priceInput" /></div>
</div><br/>
<div class="priceSlider"></div>
<div class="priceSliderLabel"><span>0</span><span style="float:right;">800,000</span></div>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="formBlock select">
<label for="location">Location</label><br/>
<input id="tags" type="text" name="location">
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-6">
<div class="formBlock select">
<label for="beds">Beds</label><br/>
<select name="beds" id="beds" class="formDropdown">
<option value="any">Any</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-6">
<div class="formBlock select">
<label for="baths">Baths</label><br/>
<select name="baths" id="baths" class="formDropdown">
<option value="any">Any</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-6">
<div class="formBlock select">
<label for="area2">Search radius</label><br/>
<select name="area" id="area2" class="formDropdown">
<option value="any">Any</option>
<option value="0.25">within 1/4 mile</option>
<option value="0.5">within 1/2 mile</option>
<option value="1">within 1 mile</option>
<option value="3">within 3 miles</option>
<option value="5">within 5 miles</option>
<option value="10">within 10 miles</option>
<option value="20">within 20 miles</option>
<option value="30">within 30 miles</option>
<option value="40">within 40 miles</option>
</select>
</div>
</div>
<div class="col-lg-4 col-md-4 col-sm-6">
<div class="formBlock">
<label for="price-min">Size Range (Square Feet)</label><br/>
<div style="float:right; margin-top:-25px;">
<div class="priceInput"><input type="text" name="size_min" id="price-min1" class="priceInput" /></div>
<span style="float:left; margin-right:10px; margin-left:10px;">-</span>
<div class="priceInput"><input type="text" name="size_max" id="price-max1" class="priceInput" /></div>
</div><br/>
<div class="priceSlider1"></div>
<div class="priceSliderLabel"><span>0</span><span style="float:right;">80,000</span></div>
</div>
</div>
<div class="col-lg-3 col-md-3 col-sm-6">
<div class="formBlock">
<input class="buttonColor" type="submit" name="find_property" value="FIND PROPERTIES" style="margin-top:24px;">
</div>
</div>
<div style="clear:both;"></div>
</div>
</form>
Here when i choose 'any' option, I want to display all the data from my table...
I am using query like below
$property_for=$_POST['property_for'];
$property_type=$_POST['property_type'];
$price_min=$_POST['price_min'];
$price_max=$_POST['price_max'];
$location=$_POST['location'];
$beds=$_POST['beds'];
$baths=$_POST['baths'];
$area=$_POST['area'];
$size_min=$_POST['size_min'];
$size_max = $_POST['size_max'];
$property_listing_for_sale = "";
$sql = mysqli_query($con, "SELECT * FROM properties WHERE category = '$property_for' AND bed_rooms = '$beds' AND bath_rooms = '$baths' ORDER BY date_added DESC") or die(mysqli_error($con));
I am newbie.. so help me.. Thanks in advance..
You should work with dynamic query's:
$baths = $_POST['baths'];
if ($baths == '*') {
$query = "select * from properties ";
} else {
$query = "select * from properties where baths = '$baths'"
}
Also you should learn about prepared statements.
A second way is to change your option value to %
<option value="Any">
And then you can use the following query:
select * from properties where baths like '$baths'