I have bootstrap chosen-select multiple select option. It is wokring fine but when i go to insert multiple selections into database it doesnt insert all selected options it inserts only the biggest value from the selected options.
Select Box
<select name="type" data-placeholder="Choose a Card Type..." class="chosen-select" style="text-align: left;" tabindex="2" multiple>
<?php
$q_all_categories = mysql_query("SELECT * from sort_kcc");
while ($all_categories = mysql_fetch_array($q_all_categories)) {
$category_id = $all_categories['id'];
$categories_name = $all_categories['ename'];
$categories_aname = $all_categories['aname'];
$q_selected_cat = mysql_query("
SELECT * FROM rel_sort_kcc WHERE sort_id=".$category_id."
AND sr_id=".$_GET['id']."
");
$selected = "";
while ($category = mysql_fetch_array($q_selected_cat)) {
$selected_category = $category['sort_id'];
if($category_id == $selected_category){$selected = "selected";}
}
print "<option class='ur' ".$selected." value='".$category_id."'>".$categories_name."</option>";
$selected = "";
}
?>
</select>
Insert Query
$categoriesCT = $_POST['type'];
for($i=0; $i < count($categoriesCT); $i++) {
mysql_query("
INSERT INTO
rel_sort_kcc
(sr_id, sort_id)
VALUES
('".$_POST['idName']."', '".$categoriesCT[$i]."')
");
}
Related
I want to write an IF statement for a dynamically generated dropdown menu, but I keep getting errors or it doesn't just work, what I am trying to do is compare two variables to see if they match from a data in the database
$loma = "Asokoro";
$row['locales'] is from locality table in the database
$row['locales'] = "Asokoro";
$row['locales'] = "Dutse";
$row['locales'] = "Mari";
$row['locales'] = "Cook";
That means if $loma which is Asokoro matches $row['locales'] = "Asokoro"; select it as the option menu
<select name="checkout_area_name" id="checkout_area_name" required>
$query = "SELECT * FROM `locality` WHERE state_name = '$hi_state'";
$sql = mysqli_query($con, $query) or die(mysqli_error($con, $query));
$r = ' <option value="">Please Choose Locality</option>';
?>
<?php
while ( $row = mysqli_fetch_assoc($sql))
{
?>
<?php $r = $r . '<option value="'.$loma.'" if ("'.$loma.' == '.$row["locales"].'") selected="selected" >'.$row['locales'].'</option>'; ?>
<?php
}
echo $r;
?>
</select>
I am trying to select the options menu that has $loma and $row['locales'] matching but I keep getting errors or when I console.log, it does not produce the result i want.
You are outputting php script as html markup, try changing your code to:
<select name="checkout_area_name" id="checkout_area_name" required>
$query = "SELECT * FROM `locality` WHERE state_name = '$hi_state'"; $sql = mysqli_query($con, $query) or die(mysqli_error($con, $query)); $r = '
<option value="">Please Choose Locality</option>'; ?>
<?php
while ( $row = mysqli_fetch_assoc($sql))
{
$r = $r . '<option value="'.$loma.'" '.(($loma==$row["locales"])?'selected':'').'>'.$row['locales'].'</option>';
}
echo $r;
?>
</select>
I have an order form where the product is selected from a database with the method "select" and "option". I show screenshot and code
Code:
<div class="form-group">
<select class="form-control" name="productName[]" id="productName<?php echo $x; ?>" onchange="getProductData(<?php echo $x; ?>)" >
<option value="">-- Selecciona --</option>
<?php
$productSql = "SELECT * FROM product WHERE active = 1 AND status = 1 AND
quantity != 0";
$productData = $connect->query($productSql);
while($row = $productData->fetch_array()) {
$selected = "";
if($row['product_id'] == $orderItemData['product_id']) {
$selected = "selected";
} else {
$selected = "";
}
echo "<option value='".$row['product_id']."'
id='changeProduct".$row['product_id']."' ".$selected."
>".$row['product_name']."</option>";
} // /while
?>
</select>
</div>
I would like to transform this way of selecting a product (droping-down list using "select") for an order form in a field that can be input the first letters of the name of the product or reference and I can see in the drop-down list those references that match instead of all references in table. I know that "input" and "post" should be used and in the query to the database something like:
// Conexión a la base de datos y seleccion de registros
$con=mysql_connect("localhost","xxxxx_xxxx","xxxxxxx");
$sql = "SELECT * FROM product WHERE referencia, product_name, position_store
like ‘%$buscar%’ ORDER BY id DESC";
mysql_select_db("xxxxxxx_stock", $con);
$result = mysql_query($sql, $con);
The idea is to do what I show in the screenshot:
Once the matches appear, you can select the one that interests you. I'm not sure how to structure the changes to convert the initial code into what I'm looking for.
I appreciate any help.
I have a select box which shows job roles.
Upon select I would like another select box to auto populate the department (stored in the same row as job role in the MySQL DB)
<select class="full-width"name="manager" data-placeholder="Manager" data-init-plugin="select2">
<?
$result=mysql_query("SELECT * FROM hr_job_roles")or die('Could not connect:' . mysql_error());
for ($i = 1; $i <= mysql_num_rows($result); $i++)
{
$row = mysql_fetch_array($result);
$title=$row['title'];
echo" <option value='$title'>$title </option>";
}
if ($i % 4 == 0) {
echo ''; // it's time no move to next row
}
?>
</select>
I have a drop down that is being populated from a static select. Then when a choice is made in the first drop down a query runs and the second drop down is populated from the database depending on selection in first select box. Here is the code. I'm having a problem displaying the second drop down with the data.
$selectvalue = mysqli_real_escape_string($mysqli, $_GET['selectvalue']);
$result = mysqli_query($mysqli, "SELECT DISTINCT '$selectvalue' FROM accounts ");
echo '<option value="">Please select...</option>';
while($row = mysqli_fetch_array($result))
{
echo '<option value="'.$row['$selectvalue'].'">' . $row['$selectvalue'] . "</option>";
//echo $row['drink_type'] ."<br/>";
}
mysqli_free_result($result);
mysqli_close($connection);
?>
<?php
$selectvalue = mysqli_real_escape_string($mysqli, $_GET['selectvalue']);
$result = mysqli_query($mysqli, "SELECT DISTINCT * FROM accounts WHERE col_name = '".$selectvalue."' ");
echo '
<select name="some_name">
<option value="">Please select...</option>';
while($row = mysqli_fetch_array($result)) {
echo '<option value="'.$row['col_name'].'">'.$row['col_name']."</option>";
}
mysqli_free_result($result);
mysqli_close($connection);
?>
i need help for my php script with bootstrap selectpicker integration
i have php script for show selectpicker multiple value
<select id="skill" name="skill" class="selectpicker" multiple data-size="5" data-selected-text-format="count">
<?php
$skills = mysql_query("SELECT skill_id, skill_name FROM skill",$conn);
while($r_skills = mysql_fetch_assoc($skills)){
echo '<option value="'.$r_skills['skill_id'].'">'.$r_skills['skill_name'].'</option>
';
}
?>
</select>
and on my other table i have user and skill_id, for skill_id content : 1, 2, 3
i had explode it into each value like this :
$q = ("SELECT nik, skill_id FROM dosen WHERE nik = '".$nik."'",$conn);
while($row_dosen = mysql_fetch_assoc($q)){
$pieces = explode(",", $row_dosen['skill_id']);
for($i = 0; $i < count($pieces) ; $i++){
$pp = mysql_query("SELECT skill_id, skill_name FROM skill WHERE skill_id = '".$pieces[$i]."'",$conn);
while($p = mysql_fetch_assoc($pp)){
$var_each = $p['skill_id'];
}
}
}
The question is : how i can set default selected value for my multiple selectpicker option to make them selected as my user data on table ?
Thank you.
The help will be appreciated :)
How about something like:
<select id="skill" name="skill" class="selectpicker" multiple data-size="5" data-selected-text-format="count">
<?php
$skills = mysql_query("SELECT skill_id, skill_name FROM skill",$conn);
while($r_skills = mysql_fetch_assoc($skills)){
echo '<option value="'.$r_skills['skill_id'].'"';
if ($r_skills['skill_id'] == '1337 codingz')
echo ' selected';
echo '>'.$r_skills['skill_name'].'</option>';
}
?>
</select>