50\" this query yields 120 results... how to print those results on a page in order of rating 开发者_StackOverflow社区with" />
开发者

How do I take a mysql query and print the results on a cakephp page

开发者 https://www.devze.com 2023-02-18 03:05 出处:网络
With links to each user. For example. \"SELECT * FROM users WHERE rating > 50\" this query yields 120 results... how to print those results on a page in order of rating 开发者_StackOverflow社区with

With links to each user.

For example. "SELECT * FROM users WHERE rating > 50" this query yields 120 results... how to print those results on a page in order of rating 开发者_StackOverflow社区with links to each profile..

a leaderboard if you will


A good place to start would be to review the docs at http://book.cakephp.org/ but in short it will follow Cake's MVC principles. You'll need a model to interact with the database and pass this data back to a controller. The controller will then pass that information to the relevant view script and which point you can layout the recordset as you wish.


First, you should read up on CakePHP like @simnom has suggested. Once you do, your query and view code should look something like this:

Users Controller:

$users = $this->User->find('all', array('order'=> array('User.rating' => 'desc'), 'conditions'=>array('User.rating >' => '50')));
$this->set('users', $users); 

View Code:

<?php
foreach ($users as $user):
   echo $this->Html->link("View User", array('controller' => 'users', 'action' => 'view', $user['id']));
endforeach;
?>
0

精彩评论

暂无评论...
验证码 换一张
取 消