I am trying to retrieve data field from a database and store them in a dropdown box so that they correlate to each other which i have done but when I put them into a dropdown box they appear but with no spaces between them and I want the words separated.
Any help much appreciated.
<form name="FrmAmend" method="post" action="amenddvd2.php">
Select from the list below<br>
<select name="Film" t[enter link description here][1]itle="Select DVD">
<option value="" selected disabled>Select DVD</option>
<?php
$result = mysqli_query($con, "SELECT `DVD ID`, `Title`, `Certificate` FROM tbldvd;");
while ($row = mysqli_fetch_assoc($result)) {
echo "<option value='" . $row['DVD ID'] . $row['Title'] . $row['Certificate'] . "'>" . $row['DVD ID'] . $row['Title'] . $row['Certificate'] . "</option>";
}
?>
</select><br>
<a href="menu.php"</a>Return To Main Menu<br>
<input type="submit" name="Submit" value="Select DVD">
</a>
</form>
It will be better you do it this way
<form name="FrmAmend" method="post" action="amenddvd2.php">
Select from the list below<br>
<select name="Film" t[enter link description here][1]itle="Select DVD">
<option value="" selected disabled>Select DVD</option>
<?php
$result = mysqli_query($con, "SELECT `DVD ID`, `Title`, `Certificate` FROM tbldvd;");
while ($row = mysqli_fetch_assoc($result)) {
?>
<option value=' <?php echo"$row['DVD ID'] $row['Title'] $row['Certificate']" ?> ' selected disabled>Select DVD</option>
<?php
}
?>
</select><br>
<a href="menu.php"</a>Return To Main Menu<br>
<input type="submit" name="Submit" value="Select DVD">
</a>
</form>
concat a space between the vars
echo "<option value='" . $row['DVD ID'] . $row['Title'] . $row['Certificate'] . "'>" . $row['DVD ID'] . ' ' . $row['Title'] . ' ' . $row['Certificate'] . "</option>";
Related
I am trying to retain the value selected in a drop down menu. Everything is working, but I don't know how to show and retain the selected value. How can I do this?
I've got this working using another way:
<?php if($_POST['selClass'] == $row1['class']) echo 'selected="selected"' ?>
but this leads to other problems, i.e. a blank option in my drop down menu.
<form action="" method="POST" name="form1" id="form1">
<select name="selClass" size="1" id="selClass" onchange="form1.submit()">
<option value="">Select a class</option>
<?php
echo "<option value='". "All records". "' . >" . "all records". "</option>";
while ($row1 = mysqli_fetch_array($rs5)) {
echo "<option value='".$row1["class"] ."'>" . $row1["class"]. "</option>";
}
?>
</select>
</form>
You can approach this as
<?php
$selectedOption = '';
if($_POST){
$selectedOption = $_POST['selClass'];
}
?>
<form action="" method="POST" name="form1" id="form1">
<select name="selClass" size="1" id="selClass" onchange="form1.submit()">
<option value="">Select a class</option>
<?php
echo "<option value='". "All records". "' . >" . "all records". "</option>";
while ($row1 = mysqli_fetch_array($rs5)) {
if($row1["class"] == $selectedOption)
echo "<option value='".$row1["class"] ."' selected='selected'>" . $row1["class"]. "</option>";
else
echo "<option value='".$row1["class"] ."'>" . $row1["class"]. "</option>";
}
?>
</select>
</form>
There is two option you can choose whichever you feel ease.
<?php
echo "<option value='". "All records". "' . >" . "all records". "</option>";
while ($row1 = mysqli_fetch_array($rs5)) {
if($_POST['selClass'] == $row1['class']){
echo "<option value='".$row1["class"] ."' selected='selected'>" . $row1["class"]. "</option>";
}else{
echo "<option value='".$row1["class"] ."'>" . $row1["class"]. "</option>";
}
}
?>
OR
<?php
$selectedClass = $_POST['selClass'];
while ($row1 = mysqli_fetch_array($rs5)) { ?>
<option value="<?php echo $row1['çlass']?>" <?php if(selectedClass == $row1['class']) { echo "selected='selected'"; }?> ><?php echo $row1['class']?></option>
<?php } ?>
I am creating a daycare student registration system. I have a form which submits data into my daycare table. I have a column named Grade and I would like to retrieve all students based on the selected grade. Can anyone assist me in constructing the proper logic to do this? Thanks
Here is my HTML code
<form method="POST" action="display.php">
View Student Records
<select name="grades">
<option value="all">All</option>
<option value="3">3rd Grade</option>
<option value="4">4th Grade</option>
<option value="5">5th Grade</option>
<option value="6">6th Grade</option>
</select>
<input type="submit" value="View Students" name="view">
</form>
PHP code
this is my attempted logic if the user selects 3rd graders.
my grade field is also a text format rather than number
<?php
session_start();
require("dbconnect.php");
if(empty($_SESSION['user_name']))
{
echo "Please login: <a href='./index.php>Login</a>";
exit();
}
?>
<?php
$link=Connect();
if (isset($_POST['view'])){
$grade = ($_POST['grades']);
$select = "SELECT * daycare WHERE Grade = $grade";
$result = mysql_connect($select, $link) or die("Error: "mysql_error());
}
echo "<table>";
while($row = mysql_fetch_array($select){
echo "<tr><td>" . $row['fname'] . "</td><td>" . $row['lname'] . "</td></tr>" . "</td><td>" . $row['grade'] . "</td></tr>";
}
echo "</table>";
}
mysql_close();
?>
hellow maybe you can try this
file to connect to database:
<?php
function Connect()
{
if (!($link=mysql_connect("localhost","root","")))
{
echo "Error to connect to DataBase.";
exit();
}
if (!mysql_select_db("DataBase_Name",$link))
{
echo "Error to select DataBase.";
exit();
}
return $link;
}
?>
file to select grades and show
<form method="post" action="display.php">
View Student Records
<select name="grades">
<option name="all" value="all">All</option>
<option name="third" value="third">3rd Grade</option>
<option name="fourth" value="fourth">4th Grade</option>
<option name="fifth" value="fifth">5th Grade</option>
<option name="sixth" value="sixth">6th Grade</option>
</select>
<input type="submit" value="View" name="view">
</form>
file to select and return the table grades:
<?php
session_start();
require("dbconnect.php");
if(empty($_SESSION['user_name']))
{
echo "session not started please login: <a href='./login.php'>Login</a>";
exit();
}
?>
<?php
$link=Connect();
if (isset($POST['view'])){
$query3 = "SELECT * FROM daycare WHERE Grade = "3"" ;
$result3=mysql_query($query3,$link) or die("Error: ".mysql_error());
}
echo "<table>";
while($row = mysql_fetch_array($result3){
echo "<tr><td>" . $row['fname'] . "</td><td>" . $row['lname'] . "</td></tr>" . "</td><td>" . $row['grade'] . "</td></tr>";
}
echo "</table>";
mysql_close($link);
?>
and you should verify if exist values (all - third - fourth....) with a if
and show the table grade from your selection.
I am struggling to produce a SQL result. I am trying to display my results in a table from one of the select options.
Any help?
HTML:
<form action="" method="post" name="parkname">
<select id="combobox" name="parkname" class="park-choice">
<option hidden value="C">C</option>
<option class="hidden" value="E">E</option>
<option class="hidden" value="W">W</option>
</select>
<span style="display:inline-block; width: 200px;"></span>
Capacity:
<select id="foo" style="display:inline-block; width: 80px;" id="combobox">
<input type="submit" value="submit">
</select>
</form>
PHP code:
<?php
$selectOption = $_POST['parkname'];
$query = "SELECT * FROM `ROOMS` WHERE `Park` = '$selectOption%';";
$result = mysql_query($query);
echo $result;
if ($result == FALSE) die ("could not execute statement $query<br />");
echo "<table>";
while($row = mysql_fetch_array($result)){
echo "<tr><td>" . $row['roomCode'] . "</td><td>" . $row['Park'] . "</td><td>" . $row['Capacity'] . "</td><td>" . $row['Style'] . "</td><td>" . $row['dataProjector'] . "</td><td>" . $row['Whiteboard'] . "</td><td>" . $row['OHP'] . "</td><td>" . $row['wheelchairAccess'] . "</td><td>" . $row['lectureCapture'] . "</td></tr>";
}
echo "</table>";
mysql_close();
?>
First, you need to clear your query from % sign.
$query = "SELECT * FROM `ROOMS` WHERE `Park` = '$selectOption';";
Or if you want to find all matches, you can use LIKE operator:
$query = "SELECT * FROM `ROOMS` WHERE `Park` LIKE '%$selectOption%';";
Second, for displaying html combobox with Park names (in your case), use code like:
<select name="park">
<option value="Park1">Display name</option>
<option value="Park2">Display name</option>
<option value="Park3">Display name</option>
</select>
Park1,Park2,Park3 - Values that would be sent to your php code inside $_REQUEST['park'] variable.
Display name - Just visually display name for options in select
<form action='main.php' method='POST'>
<select name="Category" class='listbox'>
<?php $cat = mysql_query("select cName from category");
while($drop = mysql_fetch_array($cat))
{
echo '<option value="' . $drop['Category'] . '">' . $drop['cName'] . '</option>';
}
?>
<input type='text' name='search' class='namebox'>
<input type='submit' name='submit' value='Search' class='submitbox'></select>
</select>
i am trying to use this form to create a search engine from my database but just cant get the value from the drop down menu.
$submit = $_POST['submit'];
if($submit)
{
$search = $_POST['search'];
$catval = $_POST['Category'];
echo $catval ;
$searchval = mysql_query("select * from item where iname like '%$search%'and cId in (select cId from category where cName = '$catval')");
while($info = mysql_fetch_array($searchval))
{
echo "Item Name: " . $info['iName'];
}
}
so when i try to search using this method i get no results.
You have placed the selects closing tag wrong :) and I assume you remembered to close your form aswell?
<form action='main.php' method='POST'>
<select name="Category" class='listbox'>
<?php $cat = mysql_query("select cName, Category from category");
while($drop = mysql_fetch_array($cat))
{
echo '<option value="' . $drop['Category'] . '">' . $drop['cName'] .'</option>';
}
?>
</select>
<input type='text' name='search' class='namebox'>
<input type='submit' name='submit' value='Search' class='submitbox'>
</form>
<form action='main.php' method='POST'>
<select name="Category" class='listbox'>
<?php $cat = mysql_query("select cName from category");
while($drop = mysql_fetch_array($cat))
{
echo '<option value="' . $drop['Category'] . '">' . $drop['cName'] .
'</option>';
}
?>
</select>
<input type='text' name='search' class='namebox'>
<input type='submit' name='submit' value='Search' class='submitbox'>
</form>
That should do the trick. Your </select> was in the wrong place.
In the meantime, you might want to look into PDO and bound values instead of using mysql() as it's depreciated (I.E. don't use it anymore) and insecure.
I have been trying to make this webpage work for a while but keep getting problems. In this webpage, I have a series of selection boxes (some are independent and some are depended on another) to make selections and then apply filter to make a query. It is still in test-mode and working fine for single selections. But I have still not managed to make it work for multiple selections in same selection boxes. For example; When I select Europe and North America in Region Box and apply the filter it gives no result when I'd expect it to give me the results of the companies which are in Europe OR North America. You can find the test webpage here: http://gorevler.awardspace.biz/realdeal04.html
I have been trying to use "implode" and IN operator in .PHP file but don't know where I am doing wrong at. I'd appreciate it if you could you please show me the right way of doing it. You can find the coding below:
PHP
<?php
error_reporting(E_ALL); ini_set('display_errors', 1); mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
$DB_HOST = "*****"; $DB_USER = "*****"; $DB_PASS = "*****"; $DB_NAME = "*******";
$con = new mysqli($DB_HOST, $DB_USER, $DB_PASS, $DB_NAME); if($con->connect_errno > 0) { die('Connection failed [' . $con->connect_error . ']'); }
$bolge= "'" . implode("', '", $_POST['filtre_region']) . "'" ;
$bolge1= mysqli_real_escape_string($con,$bolge);
$ulke= "'" . implode("', '", $_POST['filtre_country']) . "'";
$ulke1= mysqli_real_escape_string($con,$ulke);
$sektor= "'" . implode("', '", $_POST['filtre_sector']) . "'";
$sektor1= mysqli_real_escape_string($con,$sektor);
$altsektor= "'" . implode("', '", $_POST['filtre_subsector']) . "'";
$altsektor1= mysqli_real_escape_string($con,$altsektor);;
$urun= "'" . implode("', '", $_POST['filtre_product']) . "'";
$urun1= mysqli_real_escape_string($con,$urun);
$sql = mysqli_query("SELECT * FROM gorevler WHERE region IN ('$bolge1') AND country IN ('$ulke1') AND sector IN ('$sektor1') AND sub_sector IN ('$altsektor1') AND product IN ('$urun1')");
echo "<table border='0'>
<tr>
<th>No</th>
<th>Company</th>
<th>Region</th>
<th>Country</th>
<th>Sector</th>
<th>Sub Sector</th>
<th>Product</th>
<th>Website</th>
</tr>";
while ($row = mysqli_fetch_array($sql)){
echo "<td>" . ''.$row['no'] . "</td>";
echo "<td>" . ''.$row['company'] . "</td>";
echo "<td>" . ''.$row['region'] . "</td>";
echo "<td>" . ''.$row['country'] . "</td>";
echo "<td>" . ''.$row['sector'] . "</td>";
echo "<td>" . ''.$row['sub_sector'] . "</td>";
echo "<td>" . ''.$row['product'] . "</td>";
echo "<td>" . ''.$row['website'] . "</td>";
echo "</tr>";
}
echo "</table>";
?>
HTML
<form id="filtersForm" action="search_company.php" method="post" target="_blank">
<fieldset id="filtersPane">
<div class="part03_line01" id="part03_line01">
<div class="filter_bolge" id="filtre_bolge"><p>Region:</p>
<select id="filter_region" name="filtre_region[]" class="select_bolge" title="Select a region" multiple="multiple" size="5">
</select>
</div>
<div class="filter_ulke" id="filtre_ulke"><p>Country:</p>
<select id="filter_country" name="filtre_country[]" class="select_ulke" title="Select a country" multiple="multiple" size="5">
</select>
</div>
<div class="filter_sektor" id="filtre_sektor"><p>Sector:</p>
<select id="filter_sector" name="filtre_sector[]" class="select_sektor" title="Select a sector" multiple="multiple" size="5">
</select>
</div>
<div class="filter_altsektor" id="filtre_altsektor"><p>Sub Sector:</p>
<select id="filter_subsector" name="filtre_subsector[]" disabled="disabled" class="select_altsektor" title="Select a sub-sector" multiple="multiple" size="5">
<option value="" data-filter-type="" selected="selected">
-- Make a Choice --</option>
</select>
</div>
<div class="filter_urun" id="filtre_urun"><p>Product:</p>
<select id="filter_product" name="filtre_product[]" disabled="disabled" class="select_urun" title="Select a product" multiple="multiple" size="5">
<option value="" data-filter-type="" selected="selected">
-- Make a Choice --</option>
</select>
</div>
</div>
<div class="part03_line03" id="part03_line03">
<div class="aramadugmesi" id="aramadugmesi"> <button type="submit" id="applyFilterButton">Apply Filters</button>
</div>
</div>
</fieldset>
</form>
JAVASCRIPT
<script>
$(document).ready(function() {
$('#filter_region')
.load('/textdata/region.txt');
$('#filter_country')
.load('/textdata/country.txt');
$('#filter_sector')
.load('/textdata/sector.txt');
$('#filter_sector').change(function() {
$('#filter_subsector').load("textdata/subsector/" + $(this).val() + ".txt",
function(){
$(this).attr('disabled',false);
}
);
});
$('#filter_subsector').change(function(){
$('#filter_product').load(
"textdata/subsector/product/" + $(this).val() + ".txt",
function(){
$(this).attr('disabled',false);
}
);
});
});
</script>
This Php coding is not working for me. It is not giving any results when I click Apply Filter. For example when I select Europe and North America in the selection box and click apply, I want all the companies which are in Europe OR North America to be fetched from database and listed. But it fetches no result. I guess it is a problem with php coding but I don't know whats wrong
You need to get single quotes inside your parentheses like this:
$bolge1 = "'" . implode("', '", $_POST['filtre_region']) . "'";
mysql needs to see something like this:
IN ('value1','value2','value3')
Your explode was just producing this :
IN (value1, value2, value3)
The code above will insert the opening and closing apostrophes and make sure there are also apostrophes between each value.