如何从MySQL阵列文字选择和比较 [英] How to select from mysql array text and compare

查看:59
本文介绍了如何从MySQL阵列文字选择和比较的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是用户选择文本作为使用从PHP形式PDO阵列连接mysql中有让假设3复选框以名字收集
1-苹果
2 - 香蕉
3樱桃


  

在DB存储的值按所示
  苹果,香蕉,樱桃


  
  

我想:我要显示在某些/offer.php苹果用户页面
  而我使用SELECT查询,它不工作我使用纯PHP MVC framwork。


  
  

在控制器我做到了这一点。


 公共职能报价(){
$这个 - >取景>标题=用户选择;
$这个 - >取景> offerUser = $这个 - >&建模GT; offerUser();
$这个 - >取景>渲染(仪表盘/报价');
}


  

在型号我做到了这一点。


 公共职能offerUser()
{
返回$这个 - > DB-GT&;选择(SELECT * FROM用户WHERE选择=苹果ORDER BY DESC点');
}


  

在查看我做到了这一点。


 < PHP
的foreach($这个 - > offerUser为$关键=> $值){>
<&TBODY GT;
&所述; TR>
< TD>< / TD>
< TD><强>< PHP的echo $值['选择']>< / STRONG>< / TD>
< / TR>


  

问题是我不能够从与模型存储阵列,甚至不能在查看最终用户页面中显示选项选择文本。


这code画幅的是工作的罚款单的数字数字选择或比较,但文字阵列失败。

请帮我出这个我真的AP preciate这个我新的文本阵列读取。

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

问候,
詹姆斯


解决方案

查询不工作:用单引号围绕着苹果

 公共职能offerUser()
{
 返回$这个 - > DB-GT&;选择(SELECT * FROM用户WHERE选择='苹果'ORDER BY点DESC);
}

I am collecting user selected "text" as array in mysql using PDO connection from php form there are let suppose 3 check boxes with names 1- Apple 2- Banana 3- Cherry

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.

This code format was working fine with single numeric digit selection or compare but failed with text array.

Please help me out with this i really appreciate this i am new with text array fetching.

Hope someone answer my question soon....

Regards, james

解决方案

query is not working : use single quotation around apple

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

这篇关于如何从MySQL阵列文字选择和比较的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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