James
James

Reputation: 11

How to select from mysql array text and compare

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

Upvotes: 1

Views: 311

Answers (1)

Faisal Hameed
Faisal Hameed

Reputation: 104

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 ");
}

Upvotes: 1

Related Questions