我想我不知道怎么问正确的问题,所以最后几个小时没有结果...... :-(
这是我的工作:
我有公寓所有者的数据库和列出它们的页面。一切正常,看起来很好
现在我想:
选择场或下拉框,可选择某些公寓类型
让我们说只显示2-4人的公寓。
在appartement中,db是一个包含for_max_people字段的表
表格如下:
--------------------------------------------------------------------------<br>
id |名字|一年|主页| for_max_people |
1 |红色| 2017年| www.page1.html | 2-4 |
2 |蓝色| 2016 | www.page2.html | 1-2 |
3 |灰色| 2014 | www.page3.html | 2-4 |
-------------------------------------------------- ------------------------
所以标准视图将是所有公寓 - (~300)但我希望有一个选项可以选择某个参数。
<form class="form-horizontal">
<select id="selectbasic" name="selectbasic" class="form-control">
<option value="2-4">App. 2-4 People</option>
<option value="4-6">App. 3-6 People</option>
</select>
</form>
所以, 我的问题不在于 - 如何填充数据库中的选择字段... 而是如何进行查询,选择将改变表格网格的视图与显示的公寓......
希望这是可以理解的......
问题是什么? 我可以(!!!)google它,但我总是得到一个解决方案来填充选择/下拉字段!
要搜索的表达/单词? 当然,小提琴会很完美......
马丁
答案 0 :(得分:0)
您可以使用select的<select id="selectbasic" name="selectbasic" class="form-control" onchange="updateTable();">
事件并调用一个根据所选选项更改值的函数。
updateTable
在data.php?filter=2-4
函数中,您从数据库请求新数据,然后将它们放入表中。在请求新数据时,您应该将过滤器作为参数传递,例如: WHERE
。
对于SQL查询:您可以使用for_max_people
条件,只选择列PDO
的值等于您输入的值的结果。
注意:请务必使用准备好的语句并验证您的用户输入,否则您不知道恶意用户可能会向您发送什么内容。这是使用ArrayList<SettingsSceneCardItem> cardItems = new ArrayList<>();
private SettingsAdapterListener listener;
private OnSelectCallback onSelectCallback;
public SettingsSceneCardAdapter(SettingsAdapterListener listener) {
this.listener = listener;
}
public void setOnSelectCallback(OnSelectCallback callback) {
this.onSelectCallback = callback;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.layout_scene_settings_card_item, parent, false);
return new ViewHolder(view);
}
@Override
public void onBindViewHolder(final ViewHolder holder, final int position) {
// Settings Scene Card Item cardItem
final SettingsSceneCardItem cardItem = cardItems.get(position);
// Card Item View
holder.cardItemView.setBackgroundColor(Color.parseColor("#131B22"));
// Card Item Text Description
holder.cardItemDescription.setText(cardItem.getDescription());
holder.cardItemDescription.setTextColorColor.parseColor("#ffffff"));
holder.cardItemDescription.setTextSize(12);
// Card Item Main Image Icon
holder.cardItemMainImageIcon.setImageResource(cardItem.getMainIcon());
holder.cardItemMainImageIcon.getLayoutParams().width = 100;
holder.cardItemMainImageIcon.getLayoutParams().height = 100;
// Focused Item View with shadow behinds the card item view
holder.focusedItemView.setVisibility(View.GONE);
// Set Card Item Focus Behaviour
holder.cardItemView.setFocusable(true);
holder.cardItemView.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
if (hasFocus) {
if (onSelectCallback != null) {
onSelectCallback.onSelect(position);
}
holder.cardItemView.setBackgroundColor(Color.RED);
// Set Card Item Text Description Behaviour
holder.cardItemDescription.setTextColor(Color.parseColor("#ffffff"));
holder.cardItemDescription.setTextSize(18);
// Set Card Item Main Image Icon Behaviour
holder.cardItemMainImageIcon.getLayoutParams().width = 120;
holder.cardItemMainImageIcon.getLayoutParams().height = 120;
} else {
// Reset Card Item View Behaviour
holder.cardItemView.setBackgroundColor(Color.parseColor("#131B22"));
// Reset Card Item Text Description Behaviour
holder.cardItemDescription.setTextColor(Color.parseColor("#ffffff"));
holder.cardItemDescription.setTextSize(12);
// Reset Card Item Main Image Icon Behaviour
holder.cardItemMainImageIcon.getLayoutParams().width = 100;
holder.cardItemMainImageIcon.getLayoutParams().height = 100;
}
}
});
// TODO Add image listener
holder.cardItemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
System.out.println("###################### CARD ITEM CLICKED POSITION " + position);
listener.onItemClick(position);
}
});
}
@Override
public int getItemCount() {
return cardItems.size();
}
/**
* Recycler View Holder
*/
public class ViewHolder extends RecyclerView.ViewHolder {
// Relative layout for focused card view item with shadow
private RelativeLayout focusedItemView;
// Relative layout for card item view
private RelativeLayout cardItemView;
//Image view main card item image icon
private ImageView cardItemMainImageIcon;
// Text view description
private TextView cardItemDescription;
public ViewHolder(View itemView) {
super(itemView);
focusedItemView = (RelativeLayout) itemView.findViewById(R.id.settings_scene_card_item_view_focused);
cardItemView = (RelativeLayout) itemView.findViewById(R.id.settings_scene_card_item_view);
cardItemMainImageIcon = (ImageView) itemView.findViewById(R.id.settings_scene_card_main_image_icon);
cardItemDescription = (TextView) itemView.findViewById(R.id.settings_scene_card_item_text_description);
}
}
public interface SettingsAdapterListener {
void onItemClick(int position);
void onSelected(int position);
}
public interface OnSelectCallback {
void onSelect(int index);
}
public void refreshCardItems(ArrayList<SettingsSceneCardItem> cardItems) {
this.cardItems = cardItems;
notifyDataSetChanged();
}
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.RecyclerView
android:id="@+id/settings_scene_card_item_list_recycler"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_centerInParent="true" />
进行此操作的好方法。