php - 如何从mysql数组文本中选择并比较

标签 php mysql arrays text pdo

我使用来自 php 表单的 PDO 连接在 mysql 中收集用户选择的“文本”作为数组,假设有 3 个带有名称的复选框 1- 苹果 2- 香蕉 3-樱桃

In DB stored values are as per shown apple,banana,cherry

What i want : I want to display "Apple" users in certain "/offer.php" page while i am using SELECT query and it's not working i am using pure php mvc framwork.

In Controller i done this

public function offer(){    
$this->view->title = User Selection;
$this->view->offerUser = $this->model->offerUser();
$this->view->render('dashboard/offer');
}

In Model I done this

public function offerUser()
{
return $this->db->select('SELECT * FROM users WHERE selection = apple ORDER BY points DESC ');
}

In View i done this

<?php
foreach($this->offerUser as $key => $value) {?>
<tbody>
<tr>
<td></td>
<td><strong><?php echo $value['selection']?></strong></td>
</tr>

The issue is i am not able to select "Text" from stored array with model and even not able to display selection in "View" user end page.

此代码格式在选择或比较单个数字时工作正常,但在文本数组时失败。

请帮我解决这个问题,我真的很感激我是文本数组获取方面的新手。

希望有人能尽快回答我的问题....

问候, 詹姆斯

最佳答案

查询无效:在 apple 周围使用单引号

public function offerUser()
{
 return $this->db->select("SELECT * FROM users WHERE selection = 'apple' ORDER    BY points DESC ");
}

关于php - 如何从mysql数组文本中选择并比较,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29046767/

相关文章:

php - 获取数据并检查一次查询中是否有 "Next Page"?

php - 如何从数据库获取两组结果 - 拥有某个项目的用户以及拥有该项目的用户的 friend

php - 从另一个具有最新条目的表中选择值

java - 我如何才能从任何类访问这个数组?

.net - 为什么 .NET 中的多维数组比普通数组慢?

php - Javascript crc32 函数和 PHP crc32 与 UTF8 不匹配

php - 优化 codeigniter 查询、Join 或 Where

php - (notice) child pid XXXX exit signal Segmentation fault (11), possible coredump in/etc/apache2

MYSQL 将两张表整合到一张表中,不漏掉任何一行

java - 我将哪种类型的数组发送给构造函数?