PHP-按MySQL字段值过滤 [英] PHP - Filtering by MySQL field value

查看:111
本文介绍了PHP-按MySQL字段值过滤的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,其中有些行包含3个字段(类别,标题,图像).首先,我创建了一个foreach循环,该循环返回了一些html,其中包含来自每一行的信息.但是,现在我实际上想创建一个方案,可以按类别过滤"我的循环.

I've got a table with some rows that contain 3 fields (category, title, image). At first I created a foreach loop that returned some html with the information from each of the rows. However, now I actually want to create a scenario where I can "filter" my loop by category.

我的意思是说我想创建一个函数,该函数将只为类别字段具有特定值的行生成html.我希望能够将此功能应用于类别的所有不同值.

What I mean to say is that I want to create a function that will only generate the html for rows that have a particular value for their category field. I want to be able to apply this function to all the different values for category.

任何帮助将不胜感激.

推荐答案

MySql查询解决方案:
在查询中使用Where语句,并保持PHP不变.
例如

MySql query solution:
Use a Where Statement in your query, and keep your PHP the same.
e.g.

Select * From table Where `category`="Filter Value";

让我知道这是否对您有用,或者您是否只能使用PHP来过滤类别.

Let me know if that works for you, or if you're constrained to only using PHP to filter the category..

这篇关于PHP-按MySQL字段值过滤的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆