Welcome Guest, Not a member yet? Register   Sign In
Convert this to CI
#1

[eluser]MMCCQQ[/eluser]
hi


i dont have any idea how to write this
Quote:$cantidad = "4";



//query
$sql = "SELECT topic_id, forum_id, topic_title, topic_time FROM phpbb_topics ORDER BY topic_time DESC LIMIT $cantidad";
$query = mysql_query($sql,$link);

$topic_number = 1;

while($result = mysql_fetch_array($query))
{

$titulo = substr(stripslashes($result['topic_title']),0,50);
$cat = mysql_query("SELECT * FROM phpbb_forums WHERE forum_id = '$result[forum_id]'");
$result2 = mysql_fetch_array($cat);

to CI. i want put this code to a Models

how can i do this?
#2

[eluser]Josh Kendall[/eluser]
Hi MMCCQQ, I think this is what you want.

Code:
/* You're Variables */
$cantidad        = 4;
$topic_number    = 1;

/* First Database Query */
$this->db->select('topic_id, forum_id, topic_title, topic_time');
$this->db->orderby('topic_time', 'desc');
$this->db->limit($cantidad);
$this->db->from('phpbb_topics');
$query = $this->db->get();

/* First Database Result */
$result = $query->result_array(); // = mysql_fetch_array();

/* Dealing with the While Loop */
$count = 0;
while($count < count($result)){

    /* Second Database Query */
    $titulo    = substr(stripslashes($result[$count]['topic_title']),0,50);
    $this->db->where('forum_id', $result[$count]['forum_id']);
    $this->db->from('phpbb_forums');
    $query2    = $this->db->get();

    //Second Database Result
    $result2 = $query2->result_array(); // = mysql_fetch_array();

    $count++;

}

Hope this helps.
#3

[eluser]MMCCQQ[/eluser]
how can i output the topic? sorry my english is no very goood Big Grin

i can do this

return $result2;
#4

[eluser]Josh Kendall[/eluser]
Do you want to output only one topic (ie whatever topic is set as $topic_number) or do you want to output every topic?
#5

[eluser]MMCCQQ[/eluser]
i want output 5 topic.
#6

[eluser]MMCCQQ[/eluser]
...




Theme © iAndrew 2016 - Forum software by © MyBB