我正在使用Chosen插件创建一个select
,如果找不到搜索到的option
,则可以动态添加一个新的select
。所说的select
从mySQL表(第1列)中获取数据,并将其作为option
(inc/topicselect.inc.php
文件)插入到option
中。
要在select
内添加新的chosen.jquery.js
,请在下面的select
内使用JavaScript代码(案例13),该代码已与Enter键挂钩。现在,它可以完美工作,但只能将其临时插入option
中,这意味着刷新后,一切都消失了。
我要实现的目标是获取新添加的<select data-placeholder="Wybierz tematy:" class="topic-dropdown" name="topic" action="inc/topicselect.inc.php" class="chosen-select" multiple>
<?php require 'inc/topicselect.inc.php' ?>
</select>
并使用PHP(最后一个代码段)将其插入到表中,以便以后在使用时向所有用户永久显示(工作)是从早期获取的。
关于如何将JavaScript与PHP插入桥接的任何想法?
case 13:
evt.preventDefault();
if (this.results_showing) {
if (!this.is_multiple || this.result_highlight) {
return this.result_select(evt);
}
$(".topic-dropdown").append('<option>' + $(evt.target).val() + '</option>');
$(".topic-dropdown").trigger('chosen:updated');
this.result_highlight = this.search_results.find('li.active-result').lastreturn;
this.result_select(evt);
}
break;
<?php if(isset($_POST["?"])) {
require "connect.inc.php";
$topic=$_POST["topicname"];
if(empty($topic)) {
header("Location: ../index.php#dodajpost?puste");
exit();
}
else {
$sql="SELECT name FROM topics WHERE name=?";
$stmt=mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../index.php#dodajpost?error=sqlerror");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "s", $_POST["topicname"]);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
$resultcheck=mysqli_stmt_num_rows();
if($resultcheck > 0) {
header("Location: ../index.php#dodajpost?jużjest");
exit();
}
else {
$sql="INSERT INTO topics (name) VALUES (?)";
$stmt=mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)) {
header("Location: ../index.php#dodajpost?błądzapisu");
exit();
}
else {
mysqli_stmt_bind_param($stmt, "s", $_POST["topicname"]);
mysqli_stmt_execute($stmt);
header("Location: ../index.php#dodajpost");
exit();
}
}
}
}
mysqli_stmt_close($stmt);
mysqli_close($conn);
}
else {
header("Location: ../index.php#dodajpost?errorstart");
exit();
}
?>
var Income = (from u in db.OrderDetails
join p in db.Product on u.ProductId equals p.ProductId
join o in db.Orders on u.OrderId equals o.OrderId
where o.Paid == true
group u by u.Product.Description into g
select new
{
KindOfProduct = g.Key,
AmountSold = g.Count(),
TotalPrice = g.Sum(x => x.Product.Price)
}).ToList();
if (Income != null)
{
var orderCart = new BindingSource();
orderCart.DataSource = Income;
dgvShoppingCart.DataSource = orderCart;
this.dgvShoppingCart.Sort(this.dgvShoppingCart.Columns ["AmountSold"], ListSortDirection.Ascending);
for (int i = 0; i < dgvShoppingCart.Rows.Count; i++)
{
sumBar += Convert.ToDecimal(dgvShoppingCart.Rows[i].Cells["TotalPrice"].Value);
}
lblTotalSale.Text = sumBar.ToString();
}