用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2709|回复: 2
收起左侧

[HELP] CI随机取出记录

[复制链接]
发表于 2012-2-9 11:11:39 | 显示全部楼层 |阅读模式
我这里有普通的PHP和MYSQL代码,想转成CI Model的。

$db_con=mysql_connect('localhost', "root", "123456789101111111111111111111");
mysql_select_db( "sasoucing",$db_con);
$sql = "SELECT * FROM cms_products ORDER BY rand() LIMIT 5;";
$result=mysql_query($sql);




// Printing results in HTML
echo "<table>\n";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
    echo "\t<tr>\n";
    foreach ($line as $col_value) {
        echo "\t\t<td>$col_value</td>\n";
    }
    echo "\t</tr>\n";
}
echo "</table>\n";

// Free resultset
mysql_free_result($result);

// Closing connection
mysql_close($db_con);

发表于 2012-2-9 11:17:59 | 显示全部楼层
 楼主| 发表于 2012-2-9 12:18:46 | 显示全部楼层
$sql = "SELECT * FROM cms_products ORDER BY rand() LIMIT 5;";
$query=$this->db->query($sql);

本版积分规则