1

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

1
  • wrap 'apple' in single quotes in you sql where clause Commented Mar 14, 2015 at 8:02

1 Answer 1

1

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 ");
}
Sign up to request clarification or add additional context in comments.

8 Comments

mate i try this i changed apple to 'apple' but when i run my app stop worked... any other solution you know for this....
use this: return $this->db->select("SELECT * FROM users WHERE selection = 'apple' ORDER BY points DESC ");
Yup this time it worked :) but i can't able to see records in front end page need changes here to <td><strong><?php echo $value['selection']?></strong></td> something wrong in view section
Why not you helped me with query correction i will vote for sure, the truth is didn't found any button for vote here because i am new here can you navigate me through,
i am not sure... but try this....replace "foreach($this->offerUser as $key => $value) {" --with-- "while($value=mysql_fetch_assoc($this->offerUser)) {"
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.